// Handle mobile menu toggle document.addEventListener('DOMContentLoaded', function() { const mobileMenuButton = document.querySelector('.user-menu button'); if (mobileMenuButton) { mobileMenuButton.addEventListener('click', function() { const navLinks = document.querySelector('.nav-links'); navLinks.classList.toggle('hidden'); }); } // Handle user dropdown const userAvatar = document.querySelector('.user-avatar'); if (userAvatar) { userAvatar.addEventListener('click', function() { const dropdown = this.nextElementSibling; dropdown.classList.toggle('hidden'); }); } // Close dropdowns when clicking outside document.addEventListener('click', function(event) { if (!event.target.closest('.user-menu')) { const dropdowns = document.querySelectorAll('.user-menu .dropdown-menu'); dropdowns.forEach(dropdown => { if (!dropdown.classList.contains('hidden')) { dropdown.classList.add('hidden'); } }); } }); // Initialize tooltips document.addEventListener('DOMContentLoaded', function() { // Initialize any tooltips if needed const tooltipTriggerList = [].slice.call(document.querySelectorAll('[data-bs-toggle="tooltip"]')); tooltipTriggerList.map(function (tooltipTriggerEl) { return new bootstrap.Tooltip(tooltipTriggerEl); }); // Handle modal toggles const modalTriggers = document.querySelectorAll('[data-modal-toggle]'); modalTriggers.forEach(trigger => { trigger.addEventListener('click', function() { const modalId = this.getAttribute('data-modal-toggle'); const modal = document.getElementById(modalId); modal.classList.toggle('hidden'); }); }); // Close modals when clicking outside const modals = document.querySelectorAll('.modal'); modals.forEach(modal => { modal.addEventListener('click', function(e) { if (e.target === this) { this.classList.add('hidden'); } }); }); // Close modals with close button const closeButtons = document.querySelectorAll('[data-modal-hide]'); closeButtons.forEach(button => { button.addEventListener('click', function() { const modalId = this.getAttribute('data-modal-hide'); const modal = document.getElementById(modalId); modal.classList.add('hidden'); }); }); // Tab functionality const tabButtons = document.querySelectorAll('[data-tab-toggle]'); tabButtons.forEach(button => { button.addEventListener('click', function() { const tabId = this.getAttribute('data-tab-toggle'); const tabContent = document.getElementById(tabId); // Hide all tab contents document.querySelectorAll('.tab-content').forEach(content => { content.classList.add('hidden'); }); // Deactivate all tab buttons document.querySelectorAll('[data-tab-toggle]').forEach(btn => { btn.classList.remove('bg-blue-100', 'text-blue-700'); btn.classList.add('text-gray-600', 'hover:text-gray-800'); }); // Show selected tab content tabContent.classList.remove('hidden'); // Activate current tab button this.classList.remove('text-gray-600', 'hover:text-gray-800'); this.classList.add('bg-blue-100', 'text-blue-700'); }); }); // Accordion functionality const accordionButtons = document.querySelectorAll('[data-accordion-toggle]'); accordionButtons.forEach(button => { button.addEventListener('click', function() { const accordionId = this.getAttribute('data-accordion-toggle'); const accordionContent = document.getElementById(accordionId); const icon = this.querySelector('i'); // Toggle content accordionContent.classList.toggle('hidden'); // Toggle icon if (accordionContent.classList.contains('hidden')) { icon.setAttribute('data-feather', 'plus'); } else { icon.setAttribute('data-feather', 'minus'); } feather.replace(); }); }); }); // Format numbers with commas function formatNumber(num) { return num.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ","); } // Calculate percentage difference function calculatePercentageDifference(actual, expected) { if (expected === 0) return 0; return ((actual - expected) / expected) * 100; } // Validate POD entries function validatePODEntry(entry) { const { format5, format11, format15, format45 } = entry; const totalKg = (format5 * 5) + (format11 * 11) + (format15 * 15) + (format45 * 45); return { totalKg, isValid: totalKg > 0 }; } // View toggle functionality function toggleView(viewType) { const cardView = document.querySelector('.grid'); const tableView = document.querySelector('.hidden > div'); if (viewType === 'table') { cardView.classList.add('hidden'); tableView.classList.remove('hidden'); } else if (viewType === 'card') { cardView.classList.remove('hidden'); tableView.classList.add('hidden'); } } // Initialize view toggle buttons document.querySelectorAll('[data-view-toggle]').forEach(button => { button.addEventListener('click', function() { const viewType = this.getAttribute('data-view-toggle'); toggleView(viewType); // Update active state document.querySelectorAll('[data-view-toggle]').forEach(btn => { btn.classList.remove('active'); }); this.classList.add('active'); }); }); // Map functions function openMapWithTruck(vehicleId) { // In a real app, this would open a modal with live map tracking console.log(`Opening map for vehicle ${vehicleId}`); alert(`Opening live map tracking for vehicle ${vehicleId}`); } // Add click handlers for map buttons document.addEventListener('DOMContentLoaded', function() { const mapButtons = document.querySelectorAll('[data-feather="map"]'); mapButtons.forEach(button => { button.addEventListener('click', function() { const vehicleCell = this.closest('tr').querySelector('td:nth-child(8)'); const vehicleId = vehicleCell.textContent.trim(); if (vehicleId && vehicleId !== '-') { openMapWithTruck(vehicleId); } }); }); }); // Enhanced API functions with loading states async function fetchTransfers(filters = {}) { // Show loading state document.getElementById('transfers-container').innerHTML = `
Try adjusting your search or filter criteria.