document.addEventListener('DOMContentLoaded', function() { // Initialize charts on dashboard page if (document.querySelector('#lineChart')) { initCharts(); } // File upload dropzone functionality if (document.getElementById('dropzone')) { setupFileUpload(); } // Mobile menu toggle const mobileMenuBtn = document.querySelector('.mobile-menu-btn'); if (mobileMenuBtn) { mobileMenuBtn.addEventListener('click', toggleMobileMenu); } }); function initCharts() { // Line Chart const lineCtx = document.getElementById('lineChart').getContext('2d'); const lineChart = new Chart(lineCtx, { type: 'line', data: { labels: ['Q1', 'Q2', 'Q3', 'Q4'], datasets: [{ label: 'Revenue', data: [12000, 19000, 15000, 22000], backgroundColor: 'rgba(46, 125, 50, 0.2)', borderColor: 'rgba(46, 125, 50, 1)', borderWidth: 2, tension: 0.3, fill: true }] }, options: { responsive: true, maintainAspectRatio: false, plugins: { legend: { display: false } }, scales: { y: { beginAtZero: true, grid: { color: 'rgba(0, 0, 0, 0.05)' } }, x: { grid: { display: false } } } } }); // Bar Chart const barCtx = document.getElementById('barChart').getContext('2d'); const barChart = new Chart(barCtx, { type: 'bar', data: { labels: ['North', 'South', 'East', 'West'], datasets: [{ label: 'Sales', data: [12000, 19000, 8000, 15000], backgroundColor: [ 'rgba(76, 175, 80, 0.7)', 'rgba(139, 195, 74, 0.7)', 'rgba(205, 220, 57, 0.7)', 'rgba(255, 235, 59, 0.7)' ], borderColor: [ 'rgba(76, 175, 80, 1)', 'rgba(139, 195, 74, 1)', 'rgba(205, 220, 57, 1)', 'rgba(255, 235, 59, 1)' ], borderWidth: 1 }] }, options: { responsive: true, maintainAspectRatio: false, plugins: { legend: { display: false } }, scales: { y: { beginAtZero: true, grid: { color: 'rgba(0, 0, 0, 0.05)' } }, x: { grid: { display: false } } } } }); // Pie Chart const pieCtx = document.getElementById('pieChart').getContext('2d'); const pieChart = new Chart(pieCtx, { type: 'pie', data: { labels: ['Product A', 'Product B', 'Product C', 'Product D'], datasets: [{ data: [30000, 25000, 18000, 15000], backgroundColor: [ 'rgba(46, 125, 50, 0.7)', 'rgba(76, 175, 80, 0.7)', 'rgba(139, 195, 74, 0.7)', 'rgba(205, 220, 57, 0.7)' ], borderColor: 'rgba(255, 255, 255, 0.8)', borderWidth: 2 }] }, options: { responsive: true, maintainAspectRatio: false, plugins: { legend: { position: 'bottom' } } } }); } function setupFileUpload() { const dropzone = document.getElementById('dropzone'); const fileInput = document.getElementById('fileInput'); // Handle click on dropzone dropzone.addEventListener('click', () => { fileInput.click(); }); // Handle file selection fileInput.addEventListener('change', (e) => { if (e.target.files.length) { handleFiles(e.target.files); } }); // Handle drag and drop ['dragenter', 'dragover', 'dragleave', 'drop'].forEach(eventName => { dropzone.addEventListener(eventName, preventDefaults, false); }); function preventDefaults(e) { e.preventDefault(); e.stopPropagation(); } ['dragenter', 'dragover'].forEach(eventName => { dropzone.addEventListener(eventName, highlight, false); }); ['dragleave', 'drop'].forEach(eventName => { dropzone.addEventListener(eventName, unhighlight, false); }); function highlight() { dropzone.classList.add('highlight'); } function unhighlight() { dropzone.classList.remove('highlight'); } // Handle dropped files dropzone.addEventListener('drop', (e) => { const dt = e.dataTransfer; const files = dt.files; handleFiles(files); }); function handleFiles(files) { const file = files[0]; if (file) { // In a real app, you would process the file here alert(`File "${file.name}" ready for processing!`); // Show the data preview section document.querySelector('.data-preview').style.display = 'block'; } } } function toggleMobileMenu() { const navLinks = document.querySelector('.nav-links'); const authButtons = document.querySelector('.auth-buttons'); navLinks.style.display = navLinks.style.display === 'flex' ? 'none' : 'flex'; authButtons.style.display = authButtons.style.display === 'flex' ? 'none' : 'flex'; }