/* ========================================================================== Siro Admin Web Portal - Interactive Application Engine ========================================================================== */ document.addEventListener('DOMContentLoaded', () => { // DOM Elements const authWrapper = document.getElementById('authWrapper'); const loginForm = document.getElementById('loginForm'); const navItems = document.querySelectorAll('.nav-item[data-view]'); const pageViews = document.querySelectorAll('.page-view'); const logoutBtn = document.getElementById('logoutBtn'); const sidebar = document.getElementById('sidebar'); const toggleSidebarBtn = document.getElementById('toggleSidebar'); // Sample State & Datasets let currentUser = JSON.parse(localStorage.getItem('siro_admin_user')) || null; const mockRides = [ { id: 'SR-9842', rider: 'Ahmad Al-Mansoor', driver: 'Khalid Hassan', pickup: 'Abdoun, Amman', dropoff: '7th Circle', fare: '$14.50', status: 'Completed', time: '10 mins ago' }, { id: 'SR-9843', rider: 'Sarah Mahmoud', driver: 'Omar Farooq', pickup: 'Jabal Amman', dropoff: 'Queen Alia Airport', fare: '$28.00', status: 'In Progress', time: 'Just now' }, { id: 'SR-9844', rider: 'Tariq Ziyad', driver: 'Youssef Ali', pickup: 'Sweifieh Mall', dropoff: 'University of Jordan', fare: '$9.20', status: 'Completed', time: '25 mins ago' }, { id: 'SR-9845', rider: 'Reem Kanaan', driver: 'Hassan Nabil', pickup: 'Mecca Street', dropoff: 'Tabarbour', fare: '$11.80', status: 'Cancelled', time: '40 mins ago' }, { id: 'SR-9846', rider: 'Fadi Jarrah', driver: 'Bilal Mustafa', pickup: 'Khalda', dropoff: 'Shmeisani', fare: '$16.00', status: 'In Progress', time: '5 mins ago' }, ]; const mockDrivers = [ { id: 'DRV-101', name: 'Khalid Hassan', phone: '+962 7 9123 4567', vehicle: 'Toyota Camry 2022', rating: '4.95', trips: 1420, status: 'Online', verified: true }, { id: 'DRV-102', name: 'Omar Farooq', phone: '+962 7 8876 5432', vehicle: 'Hyundai Elantra 2021', rating: '4.88', trips: 980, status: 'In Trip', verified: true }, { id: 'DRV-103', name: 'Youssef Ali', phone: '+962 7 7654 3210', vehicle: 'Kia Optima 2023', rating: '4.90', trips: 1150, status: 'Online', verified: true }, { id: 'DRV-104', name: 'Hassan Nabil', phone: '+962 7 9988 7766', vehicle: 'Nissan Sentra 2020', rating: '4.72', trips: 620, status: 'Offline', verified: false }, ]; const mockPassengers = [ { id: 'PSG-501', name: 'Ahmad Al-Mansoor', email: 'ahmad@example.com', trips: 45, rating: '4.9', joined: 'Jan 2025', status: 'Active' }, { id: 'PSG-502', name: 'Sarah Mahmoud', email: 'sarah.m@example.com', trips: 89, rating: '5.0', joined: 'Nov 2024', status: 'Active' }, { id: 'PSG-503', name: 'Reem Kanaan', email: 'reem.k@example.com', trips: 12, rating: '4.6', joined: 'Mar 2025', status: 'Suspended' }, ]; // Initialize App function initApp() { checkAuth(); setupNavigation(); renderRidesTable(); renderDriversTable(); renderPassengersTable(); initCharts(); setupEvents(); } // Auth Functions function checkAuth() { if (currentUser) { authWrapper.classList.add('hidden'); } else { authWrapper.classList.remove('hidden'); } } loginForm?.addEventListener('submit', (e) => { e.preventDefault(); const email = document.getElementById('loginEmail').value; currentUser = { name: 'Super Admin', email: email, role: 'Administrator', authMethod: 'Password' }; localStorage.setItem('siro_admin_user', JSON.stringify(currentUser)); authWrapper.classList.add('hidden'); showNotification('Welcome back, Super Admin!', 'success'); }); const fingerprintLoginBtn = document.getElementById('fingerprintLoginBtn'); fingerprintLoginBtn?.addEventListener('click', async () => { showNotification('Touch Fingerprint sensor on your device...', 'info'); // Check WebAuthn support if (window.PublicKeyCredential) { try { // Biometric WebAuthn prompt simulation / API call setTimeout(() => { currentUser = { name: 'Super Admin (Biometric)', email: 'admin@siromove.com', role: 'Administrator', authMethod: 'Fingerprint/TouchID' }; localStorage.setItem('siro_admin_user', JSON.stringify(currentUser)); authWrapper.classList.add('hidden'); showNotification('Fingerprint Verified! Access Granted.', 'success'); }, 1200); } catch (err) { showNotification('Fingerprint verification failed', 'danger'); } } else { currentUser = { name: 'Super Admin', email: 'admin@siromove.com', role: 'Administrator', authMethod: 'Biometric' }; localStorage.setItem('siro_admin_user', JSON.stringify(currentUser)); authWrapper.classList.add('hidden'); showNotification('Biometric Auth Verified!', 'success'); } }); logoutBtn?.addEventListener('click', () => { localStorage.removeItem('siro_admin_user'); currentUser = null; authWrapper.classList.remove('hidden'); }); // Sidebar & Navigation function setupNavigation() { navItems.forEach(item => { item.addEventListener('click', (e) => { e.preventDefault(); const targetView = item.getAttribute('data-view'); navItems.forEach(n => n.classList.remove('active')); item.classList.add('active'); pageViews.forEach(view => { if (view.id === targetView) { view.classList.add('active'); } else { view.classList.remove('active'); } }); // Close sidebar on mobile if (window.innerWidth <= 992) { sidebar.classList.remove('open'); } }); }); toggleSidebarBtn?.addEventListener('click', () => { sidebar.classList.toggle('open'); }); } // Render Data Tables function renderRidesTable() { const tbody = document.getElementById('ridesTableBody'); if (!tbody) return; tbody.innerHTML = mockRides.map(ride => `
Pickup: Abdoun Circle, Amman
Dropoff: Queen Alia International Airport
Fare Breakdown: Base Fare ($4.00) + Distance ($20.00) + Peak Surge ($4.00)
Payment Method: Credit Card (Visa **** 4921)