class CustomSidebar extends HTMLElement { constructor() { super(); this.activePage = this.getAttribute('active-page') || 'dashboard'; this.isMobileMenuOpen = false; } connectedCallback() { this.attachShadow({ mode: 'open' }); this.render(); this.addEventListeners(); } static get observedAttributes() { return ['active-page']; } attributeChangedCallback(name, oldValue, newValue) { if (name === 'active-page' && oldValue !== newValue) { this.activePage = newValue; this.render(); } } render() { this.shadowRoot.innerHTML = ` `; setTimeout(() => { feather.replace(); }, 100); } addEventListeners() { setTimeout(() => { // Close sidebar when clicking on overlay (mobile) const overlay = this.shadowRoot.getElementById('sidebar-overlay'); if (overlay) { overlay.addEventListener('click', () => { this.closeMobileMenu(); }); } // Add click handlers for view buttons const viewButtons = this.shadowRoot.querySelectorAll('button'); viewButtons.forEach(button => { button.addEventListener('click', () => { if (button.textContent === 'List') { window.location.href = 'tasks.html?view=list'; } else if (button.textContent === 'Board') { window.location.href = 'board.html'; } else if (button.textContent === 'Calendar') { window.location.href = 'calendar.html'; } else if (button.textContent === 'Timeline') { window.location.href = 'timeline.html'; } }); }); }, 100); } toggleMobileMenu() { this.isMobileMenuOpen = !this.isMobileMenuOpen; const sidebar = this.shadowRoot.getElementById('sidebar'); const overlay = this.shadowRoot.getElementById('sidebar-overlay'); if (sidebar) { sidebar.classList.toggle('mobile-open', this.isMobileMenuOpen); } if (overlay) { overlay.classList.toggle('active', this.isMobileMenuOpen); } // Prevent body scroll when menu is open document.body.style.overflow = this.isMobileMenuOpen ? 'hidden' : 'auto'; } closeMobileMenu() { this.isMobileMenuOpen = false; const sidebar = this.shadowRoot.getElementById('sidebar'); const overlay = this.shadowRoot.getElementById('sidebar-overlay'); if (sidebar) { sidebar.classList.remove('mobile-open'); } if (overlay) { overlay.classList.remove('active'); } document.body.style.overflow = 'auto'; } } customElements.define('custom-sidebar', CustomSidebar);