import { apiCall } from './auth.js'; import { updateDarkModeGradients } from './darkmode.js'; import { getCurrentLanguage } from './i18n.js'; async function loadDashboard() { const authResult = await apiCall('/api/check-auth'); if (!authResult.success || !authResult.data.authenticated) { alert(getCurrentLanguage() === 'az' ? 'Zəhmət olmasa əvvəlcə daxil olun' : 'Please sign in first to access the dashboard'); // Use global navigateTo function (defined in main.js) if (typeof window.navigateTo === 'function') { window.navigateTo('login', { preventDefault: () => {} }); } return; } const imagesResult = await apiCall('/api/my-images'); if (imagesResult.success && imagesResult.data.images) { updateDashboardWithImages(imagesResult.data.images); } } function updateDashboardWithImages(images) { const dashboardContainer = document.querySelector('#dashboard-page .space-y-6'); if (!dashboardContainer) return; const existingItems = dashboardContainer.querySelectorAll('.card-hover'); existingItems.forEach(item => item.remove()); images.forEach((img, index) => { if (index >= 3) return; const isHealthy = img.prediction && img.prediction.toLowerCase().includes('healthy'); const bgColor = isHealthy ? 'from-green-50 to-green-100' : 'from-red-50 to-orange-50'; const borderColor = isHealthy ? 'border-green-200' : 'border-red-200'; const statusBadge = isHealthy ? '✅ Healthy' : '⚠️ Disease Detected'; const itemHTML = `
Scanned on ${new Date(img.created_at || Date.now()).toLocaleString()}