import { html, css } from '@lion/core';
import { renderLitAsNode } from '@lion/helpers';
import { LionOption } from '@lion/listbox';
import { LionCombobox } from '../../src/LionCombobox.js';
class WaOption extends LionOption {
static get properties() {
return {
title: String,
text: String,
time: String,
image: String,
isUserText: { attribute: 'is-user-text', reflect: true, type: Boolean },
isUserTextRead: { attribute: 'is-user-text-read', reflect: true, type: Boolean },
};
}
static get styles() {
return [
super.styles,
css`
:host {
--background-default: white;
--background-default-active: gray;
--secondary: #777;
--secondary-lighter: #aaa;
--chatlist-icon: #aaa;
background-color: var(--background-default);
cursor: pointer;
color: rgb(74, 74, 74);
padding: 0;
transition: max-height 0.4s ease, opacity 0.3s ease;
max-height: 500px;
}
:host([checked]) {
background-color: #eee;
}
:host(:hover) {
background-color: #f6f6f6;
}
.wa-option {
position: relative;
display: flex;
flex-direction: row;
height: 72px;
pointer-events: all;
}
.wa-option__image {
display: flex;
flex: none;
align-items: center;
margin-top: -1px;
padding: 0 15px 0 13px;
}
.wa-option__image-inner {
position: relative;
overflow: hidden;
background-color: var(--avatar-background);
border-radius: 50%;
height: 49px;
width: 49px;
}
.wa-option__image-inner img,
.wa-option__image-inner svg {
width: 100%;
height: 100%;
}
.wa-option__image-inner-inner {
position: absolute;
top: 0;
z-index: 1;
display: flex;
align-items: center;
justify-content: center;
width: 100%;
height: 100%;
}
.wa-option__content {
display: flex;
flex-basis: auto;
flex-direction: column;
flex-grow: 1;
justify-content: center;
min-width: 0;
border-bottom: 1px solid #eee;
padding-right: 15px;
}
.wa-option__content-row1 {
display: flex;
align-items: center;
line-height: normal;
text-align: left;
}
.wa-option__content-row1-title {
display: flex;
flex-grow: 1;
overflow: hidden;
color: var(--primary-strong);
font-weight: 400;
font-size: 17px;
line-height: 21px;
}
.wa-option__content-row1-time {
line-height: 14px;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
margin-left: 6px;
margin-top: 3px;
flex: none;
max-width: 100%;
color: var(--secondary-lighter);
font-size: 12px;
line-height: 20px;
}
.wa-option__content-row2 {
display: flex;
align-items: center;
min-height: 20px;
color: var(--secondary);
font-size: 13px;
line-height: 20px;
margin-top: 2px;
/* color: var(--secondary-stronger); */
}
.wa-option__content-row2-text {
flex-grow: 1;
overflow: hidden;
font-weight: 400;
font-size: 14px;
line-height: 20px;
white-space: nowrap;
text-overflow: ellipsis;
}
.wa-option__content-row2-text-inner {
display: flex;
align-items: flex-start;
}
.wa-option__content-row2-text-inner-icon {
display: none;
flex: none;
color: var(--chatlist-icon);
vertical-align: top;
margin-right: 2px;
}
:host([is-user-text]) .wa-option__content-row2-text-inner-icon {
display: inline-block;
}
:host([is-user-text-read]) .wa-option__content-row2-text-inner-icon {
color: lightblue;
}
.wa-selected {
color: #009688;
}
`,
];
}
render() {
return html`

${this.image
? ''
: html`
`}
`;
}
/**
* @configure LionCombobox
* @param {string} matchingString
*/
onFilterMatch(matchingString) {
this.__originalTitle = this.title;
this.__originalText = this.text;
const newTitle = this.__originalTitle.replace(
new RegExp(`(${matchingString})`, 'i'),
`$1`,
);
const newText = this.__originalText.replace(
new RegExp(`(${matchingString})`, 'i'),
`$1`,
);
const helperNode = document.createElement('div');
// For Safari, we need to add a label to the element
helperNode.innerHTML = `${newTitle}`;
[this.title] = helperNode.children;
helperNode.innerHTML = `${newText}`;
[this.text] = helperNode.children;
// Show animation
this.style.cssText = `
max-height: 500px;
opacity: 1;
`;
}
/**
* @configure LionCombobox
* @param {string} [curValue]
* @param {string} [prevValue]
*/
// eslint-disable-next-line no-unused-vars
onFilterUnmatch() {
if (this.__originalTitle) {
this.title = this.__originalTitle;
}
if (this.__originalText) {
this.text = this.__originalText;
}
this.style.cssText = `
max-height: 0;
opacity: 0;
`;
}
}
customElements.define('wa-option', WaOption);
class WaCombobox extends LionCombobox {
static get styles() {
return [
super.styles,
css`
:host {
font-family: SF Pro Text, SF Pro Icons, system, -apple-system, system-ui,
BlinkMacSystemFont, Helvetica Neue, Helvetica, Lucida Grande, Kohinoor Devanagari,
sans-serif;
}
.input-group__container {
display: flex;
border-bottom: none;
}
* > ::slotted([role='listbox']) {
max-height: none;
}
* > ::slotted([slot='input']) {
font-size: 14px;
}
.input-group {
padding: 15px;
background: #f6f6f6;
}
.input-group__prefix {
margin-right: 20px;
color: #999;
display: flex;
}
.input-group__container {
border-radius: 18px;
background: white;
padding: 7px;
padding-left: 16px;
}
/** Undo Popper */
#overlay-content-node-wrapper {
position: static !important;
width: auto !important;
transform: none !important;
/* height: 300px;
overflow: scroll; */
}
`,
];
}
get slots() {
return {
...super.slots,
prefix: () =>
renderLitAsNode(
html``,
),
};
}
constructor() {
super();
/** @configure OverlayMixin */
this.opened = true;
/** @configure LionCombobox */
this.showAllOnEmpty = true;
/** @configure LionCombobox */
this.rotateKeyboardNavigation = false;
/** @configure LionCombobox */
this.autocomplete = 'list';
}
/**
* @override LionCombobox - also match option.text
* @param {LionOption} option
* @param {string} textboxValue current ._inputNode value
*/
matchCondition(option, textboxValue) {
let idx = -1;
if (typeof option.choiceValue === 'string' && typeof textboxValue === 'string') {
idx = option.choiceValue.toLowerCase().indexOf(textboxValue.toLowerCase());
// enhance LionCombobox: also match option.text
const text = option.__originalText || option.text;
if (idx === -1 && typeof text === 'string') {
idx = text.toLowerCase().indexOf(textboxValue.toLowerCase());
}
}
if (this.matchMode === 'all') {
return idx > -1; // matches part of word
}
return idx === 0; // matches beginning of value
}
/**
* @override LionCombobox - always sync textbox when selected value changes
*/
// eslint-disable-next-line no-unused-vars
_syncToTextboxCondition() {
return true;
}
}
customElements.define('wa-combobox', WaCombobox);