class CustomSidebar extends HTMLElement { static get observedAttributes() { return ['contacts']; } attributeChangedCallback(name, oldValue, newValue) { if (name === 'contacts') { this.renderContacts(JSON.parse(newValue)); } } renderContacts(contacts) { const contactsContainer = this.shadowRoot.querySelector('.contacts-container'); if (contactsContainer) { contactsContainer.innerHTML = contacts.map(contact => `
${contact.name} ${contact.unread > 0 ? `
${contact.unread}
` : ''}

${contact.name}

${contact.time}

${contact.lastMessage}

`).join(''); } } connectedCallback() { this.attachShadow({ mode: 'open' }); this.shadowRoot.innerHTML = ` `; } } customElements.define('custom-sidebar', CustomSidebar);