// Admin Panel Navigation Script document.addEventListener('DOMContentLoaded', function() { const menuLinks = document.querySelectorAll('.menu-link[data-section]'); const sections = document.querySelectorAll('.section'); console.log('Navigation initialized'); console.log('Found menu links:', menuLinks.length); console.log('Found sections:', sections.length); // Function to show a specific section function showSection(sectionId) { console.log('Showing section:', sectionId); // Hide all sections sections.forEach(section => { section.classList.remove('active'); }); // Remove active class from all links menuLinks.forEach(link => { link.classList.remove('active-link', 'bg-gradient-to-r', 'from-purple-600', 'to-purple-700', 'text-white', 'shadow-lg', 'bg-blue-50', 'text-blue-700', 'border-r-2', 'border-blue-700'); link.classList.add('text-gray-700'); }); // Show target section const targetSection = document.getElementById(sectionId); if (targetSection) { targetSection.classList.add('active'); console.log('Section displayed:', sectionId); } else { console.error('Section not found:', sectionId); } // Activate corresponding link const activeLink = document.querySelector(`.menu-link[data-section="${sectionId}"]`); if (activeLink) { activeLink.classList.remove('text-gray-700'); activeLink.classList.add('active-link', 'bg-gradient-to-r', 'from-purple-600', 'to-purple-700', 'text-white', 'shadow-lg'); console.log('Link activated:', sectionId); } } // Add click event to all menu links menuLinks.forEach(link => { link.addEventListener('click', function(e) { const sectionId = this.getAttribute('data-section'); if (!sectionId) { return; // Allow default behavior for external links } e.preventDefault(); console.log('Link clicked:', sectionId); showSection(sectionId); // Update URL hash history.pushState(null, '', `#${sectionId}`); }); }); // Handle initial load based on URL hash const hash = window.location.hash.substring(1) || 'dashboard'; console.log('Initial hash:', hash); showSection(hash); // Handle browser back/forward buttons window.addEventListener('popstate', function() { const hash = window.location.hash.substring(1) || 'dashboard'; showSection(hash); }); });