/** * Admin Panel Core Logic - Routing and Global Functions */ /** * Custom Toast Notification */ function showToast(type, title, message) { const container = document.getElementById('toast-container'); if (!container) return; const toast = document.createElement('div'); toast.className = `toast-message ${type}`; let iconClass = 'fa-solid fa-circle-info'; if (type === 'success') iconClass = 'fa-solid fa-circle-check'; if (type === 'error') iconClass = 'fa-solid fa-circle-exclamation'; toast.innerHTML = `

${title}

${message}

`; container.appendChild(toast); // Remove toast after 5 seconds setTimeout(() => { toast.classList.add('fade-out'); setTimeout(() => toast.remove(), 400); // Wait for animation }, 5000); } document.addEventListener('DOMContentLoaded', () => { const urlParams = new URLSearchParams(window.location.search); const tab = urlParams.get('tab') || 'dashboard'; switchTab(tab); // Periodically check for open tickets and update stats setInterval(() => { if(typeof updateTicketBadges === 'function') updateTicketBadges(); if (document.getElementById('section-dashboard').classList.contains('active') && typeof loadDashboardStats === 'function') { loadDashboardStats(); } }, 30000); if(typeof updateTicketBadges === 'function') updateTicketBadges(); }); function switchTab(tabName) { const sections = document.querySelectorAll('.admin-section'); const tabBtns = document.querySelectorAll('.admin-tab-btn'); const sidebarLinks = document.querySelectorAll('.sidebar-menu .side-btn'); const breadcrumb = document.getElementById('breadcrumb-active'); sections.forEach(s => s.classList.remove('active')); tabBtns.forEach(b => b.classList.remove('active')); sidebarLinks.forEach(l => l.classList.remove('active')); const activeSection = document.getElementById(`section-${tabName}`); const activeTabBtn = document.getElementById(`tab-btn-${tabName}`); const activeSidebarLink = document.getElementById(`nav-${tabName}-link`); if (activeSection) activeSection.classList.add('active'); if (activeTabBtn) activeTabBtn.classList.add('active'); if (activeSidebarLink) activeSidebarLink.classList.add('active'); if (tabName === 'dashboard') { if (breadcrumb) breadcrumb.innerText = 'Overview'; if(typeof loadDashboardStats === 'function') loadDashboardStats(); } else if (tabName === 'payments') { if (breadcrumb) breadcrumb.innerText = 'Payment Queue'; if(typeof loadTransactions === 'function') loadTransactions(); } else if (tabName === 'wallet') { if (breadcrumb) breadcrumb.innerText = 'Wallet Management'; if(typeof loadUserWallets === 'function') loadUserWallets(); } else if (tabName === 'users') { if (breadcrumb) breadcrumb.innerText = 'User Directory'; if(typeof loadUserManagement === 'function') loadUserManagement(); } else if (tabName === 'downloads') { if (breadcrumb) breadcrumb.innerText = 'Download History'; if(typeof loadDownloadHistory === 'function') loadDownloadHistory(); } else { if (breadcrumb) breadcrumb.innerText = 'Complaints'; if(typeof loadTickets === 'function') loadTickets(); } // Update URL without reload const newUrl = window.location.pathname + '?tab=' + tabName; window.history.pushState({ path: newUrl }, '', newUrl); } window.switchTab = switchTab; window.showToast = showToast;