// Sidebar Management class SidebarManager { constructor() { this.sidebar = document.getElementById('sidebar'); this.overlay = document.getElementById('sidebarOverlay'); this.init(); } init() { // Set active link this.setActiveLink(); // Load saved sections state this.loadSectionsState(); // Auto-open active section this.openActiveSection(); } setActiveLink() { const currentPath = window.location.pathname; const links = document.querySelectorAll('.sidebar-item, .sidebar-subitem'); links.forEach(link => { const href = link.getAttribute('href'); if (href && currentPath.includes(href)) { link.classList.add('active'); } }); } openActiveSection() { const activeLink = document.querySelector('.sidebar-subitem.active'); if (activeLink) { const section = activeLink.closest('.sidebar-section'); if (section) { const header = section.querySelector('.sidebar-section-header'); const content = section.querySelector('.sidebar-section-content'); const icon = header.querySelector('.fa-chevron-down'); content.style.maxHeight = content.scrollHeight + 'px'; icon.style.transform = 'rotate(180deg)'; } } } loadSectionsState() { const savedState = localStorage.getItem('sidebarSections'); if (savedState) { const openSections = JSON.parse(savedState); openSections.forEach(index => { const section = document.querySelectorAll('.sidebar-section')[index]; if (section) { const content = section.querySelector('.sidebar-section-content'); const icon = section.querySelector('.fa-chevron-down'); content.style.maxHeight = content.scrollHeight + 'px'; icon.style.transform = 'rotate(180deg)'; } }); } } saveSectionsState() { const openSections = []; document.querySelectorAll('.sidebar-section').forEach((section, index) => { const content = section.querySelector('.sidebar-section-content'); if (content.style.maxHeight) { openSections.push(index); } }); localStorage.setItem('sidebarSections', JSON.stringify(openSections)); } } // Toggle Section function toggleSection(button) { const content = button.nextElementSibling; const icon = button.querySelector('.fa-chevron-down'); const isOpen = content.style.maxHeight; if (isOpen) { content.style.maxHeight = null; icon.style.transform = 'rotate(0deg)'; } else { content.style.maxHeight = content.scrollHeight + 'px'; icon.style.transform = 'rotate(180deg)'; } // Save state if (window.sidebarManager) { window.sidebarManager.saveSectionsState(); } } // Mobile Functions function openSidebar() { document.getElementById('sidebar').classList.add('active'); document.getElementById('sidebarOverlay').classList.add('active'); document.body.style.overflow = 'hidden'; } function closeSidebar() { document.getElementById('sidebar').classList.remove('active'); document.getElementById('sidebarOverlay').classList.remove('active'); document.body.style.overflow = ''; } // Initialize on page load document.addEventListener('DOMContentLoaded', () => { window.sidebarManager = new SidebarManager(); // Close sidebar on window resize window.addEventListener('resize', () => { if (window.innerWidth > 1024) { closeSidebar(); } }); // Update badges (example) updateBadges(); }); // Update notification badges function updateBadges() { // This would typically fetch from an API // For now, we'll use placeholder values // Example: Update orders count const ordersCount = document.getElementById('ordersCount'); if (ordersCount) { // ordersCount.textContent = '5'; // Replace with actual count } const stockCount = document.getElementById('stockCount'); if (stockCount) { // stockCount.textContent = '3'; // Replace with actual count } } // Refresh badges every 30 seconds setInterval(updateBadges, 30000);