class AliasesBottomSheet extends HTMLElement {
constructor() {
super();
this.attachShadow({mode: 'open'});
this.shadowRoot.innerHTML = `
`;
this.aliasesBottomSheet = this.shadowRoot.getElementById('aliasesSheet');
this.overlay = this.shadowRoot.querySelector('.overlay');
this.closeAliasesBtn = this.shadowRoot.getElementById('closeAliases');
this.closeAliasesBtn.onclick = () => this.hide();
this.overlay.onclick = () => this.hide();
}
show(aliases, brandKey) {
const commonAliasesList = this.shadowRoot.getElementById('commonAliasesList');
const brandAliasesList = this.shadowRoot.getElementById('brandAliasesList');
commonAliasesList.innerHTML = '';
brandAliasesList.innerHTML = '';
const pattern = /alias|='[^']*'/g;
aliases.aliases.common_aliases.forEach(alias => {
const li = document.createElement('li');
li.textContent = alias[0].replace(pattern, '').trim();
commonAliasesList.appendChild(li);
});
const brandAliases = aliases.aliases.brand_aliases[brandKey] || [];
brandAliases.forEach(alias => {
const li = document.createElement('li');
li.textContent = alias[0].replace(pattern, '').trim();
brandAliasesList.appendChild(li);
});
this.aliasesBottomSheet.style.display = 'block';
this.overlay.style.display = 'block';
setTimeout(() => this.aliasesBottomSheet.classList.add('show'), 10);
}
hide() {
this.aliasesBottomSheet.classList.remove('show');
setTimeout(() => {
this.aliasesBottomSheet.style.display = 'none';
this.overlay.style.display = 'none';
}, 300); // Match with the CSS transition duration
}
}
customElements.define('aliases-bottom-sheet', AliasesBottomSheet);