'use client'; import React, { useState, useEffect, useCallback } from 'react'; import { motion, AnimatePresence } from 'framer-motion'; import { Mail, Settings, TrendingUp, Plus, Shield, Users, Activity, Database, Home, LogOut, Menu, X } from 'lucide-react'; import Link from 'next/link'; import { EmailManager } from './EmailManager'; import { AnalyticsDashboard } from './AnalyticsDashboard'; import ImportExport from './ImportExport'; import { ProjectManager } from './ProjectManager'; interface Project { id: string; title: string; description: string; content?: string; category: string; difficulty?: string; tags?: string[]; featured: boolean; published: boolean; github?: string; live?: string; image?: string; createdAt: string; updatedAt: string; analytics?: { views: number; likes: number; shares: number; }; performance?: { lighthouse: number; }; } interface ModernAdminDashboardProps { isAuthenticated?: boolean; } const ModernAdminDashboard: React.FC = ({ isAuthenticated = true }) => { const [activeTab, setActiveTab] = useState<'overview' | 'projects' | 'emails' | 'analytics' | 'settings'>('overview'); const [projects, setProjects] = useState([]); // eslint-disable-next-line @typescript-eslint/no-unused-vars const [isLoading, setIsLoading] = useState(false); const [mobileMenuOpen, setMobileMenuOpen] = useState(false); const [analytics, setAnalytics] = useState | null>(null); const [emails, setEmails] = useState[]>([]); const [systemStats, setSystemStats] = useState | null>(null); const loadProjects = useCallback(async () => { if (!isAuthenticated) return; try { setIsLoading(true); const response = await fetch('/api/projects', { headers: { 'x-admin-request': 'true' } }); if (!response.ok) { console.warn('Failed to load projects:', response.status); setProjects([]); return; } const data = await response.json(); setProjects(data.projects || []); } catch { setProjects([]); } finally { setIsLoading(false); } }, [isAuthenticated]); const loadAnalytics = useCallback(async () => { if (!isAuthenticated) return; try { const response = await fetch('/api/analytics/dashboard', { headers: { 'x-admin-request': 'true' } }); if (response.ok) { const data = await response.json(); setAnalytics(data); } } catch (error) { console.error('Error loading analytics:', error); } }, [isAuthenticated]); const loadEmails = useCallback(async () => { if (!isAuthenticated) return; try { const response = await fetch('/api/contacts', { headers: { 'x-admin-request': 'true' } }); if (response.ok) { const data = await response.json(); setEmails(data.contacts || []); } } catch (error) { console.error('Error loading emails:', error); } }, [isAuthenticated]); const loadSystemStats = useCallback(async () => { if (!isAuthenticated) return; try { const response = await fetch('/api/health', { headers: { 'x-admin-request': 'true' } }); if (response.ok) { const data = await response.json(); setSystemStats(data); } } catch (error) { console.error('Error loading system stats:', error); } }, [isAuthenticated]); const loadAllData = useCallback(async () => { await Promise.all([ loadProjects(), loadAnalytics(), loadEmails(), loadSystemStats() ]); }, [loadProjects, loadAnalytics, loadEmails, loadSystemStats]); // Real stats from API data const stats = { totalProjects: projects.length, publishedProjects: projects.filter(p => p.published).length, totalViews: (analytics?.totalViews as number) || projects.reduce((sum, p) => sum + (p.analytics?.views || 0), 0), unreadEmails: emails.filter(e => !(e.read as boolean)).length, avgPerformance: (analytics?.avgPerformance as number) || (projects.length > 0 ? Math.round(projects.reduce((sum, p) => sum + (p.performance?.lighthouse || 90), 0) / projects.length) : 90), systemHealth: (systemStats?.status as string) || 'unknown', totalUsers: (analytics?.totalUsers as number) || 0, bounceRate: (analytics?.bounceRate as number) || 0, avgSessionDuration: (analytics?.avgSessionDuration as number) || 0 }; useEffect(() => { // Load all data if authenticated if (isAuthenticated) { loadAllData(); } }, [isAuthenticated, loadAllData]); const navigation = [ { id: 'overview', label: 'Dashboard', icon: Home, color: 'blue', description: 'Overview & Statistics' }, { id: 'projects', label: 'Projects', icon: Database, color: 'green', description: 'Manage Projects' }, { id: 'emails', label: 'Emails', icon: Mail, color: 'purple', description: 'Email Management' }, { id: 'analytics', label: 'Analytics', icon: Activity, color: 'orange', description: 'Site Analytics' }, { id: 'settings', label: 'Settings', icon: Settings, color: 'gray', description: 'System Settings' } ]; return (
{/* Animated Background - same as main site */}
{/* Admin Navbar - Horizontal Navigation */}
{/* Left side - Logo and Admin Panel */}
Portfolio
Admin Panel
{/* Center - Desktop Navigation */}
{navigation.map((item) => ( ))}
{/* Right side - User info and Logout */}
Welcome, Dennis
{/* Mobile menu button */}
{/* Mobile Navigation Menu */} {mobileMenuOpen && (
{navigation.map((item) => ( ))}
)}
{/* Main Content - Full Width Horizontal Layout */}
{/* Content */} {activeTab === 'overview' && (

Admin Dashboard

Manage your portfolio and monitor performance

{/* Stats Grid - Mobile: 2x3, Desktop: 6x1 horizontal */}
setActiveTab('projects')} >

Projects

{stats.totalProjects}

{stats.publishedProjects} published

setActiveTab('analytics')} >

Page Views

{stats.totalViews.toLocaleString()}

{stats.totalUsers} users

setActiveTab('emails')} >

Messages

{emails.length}

{stats.unreadEmails} unread

setActiveTab('analytics')} >

Performance

{stats.avgPerformance}

Lighthouse Score

setActiveTab('analytics')} >

Bounce Rate

{stats.bounceRate}%

Exit rate

setActiveTab('settings')} >

System

Online

All systems operational

{/* Recent Activity & Quick Actions - Mobile: vertical, Desktop: horizontal */}
{/* Recent Activity */}

Recent Activity

{/* Mobile: vertical stack, Desktop: horizontal columns */}

Projects

{projects.slice(0, 3).map((project) => (
setActiveTab('projects')}>

{project.title}

{project.published ? 'Published' : 'Draft'} • {project.analytics?.views || 0} views

{project.published ? 'Live' : 'Draft'} {project.featured && ( Featured )}
))}

Messages

{emails.slice(0, 3).map((email, index) => (
setActiveTab('emails')}>

From {email.name as string}

{(email.subject as string) || 'No subject'}

{!(email.read as boolean) && (
)}
))}
{/* Quick Actions */}

Quick Actions

)} {activeTab === 'projects' && (

Project Management

Manage your portfolio projects

)} {activeTab === 'emails' && ( )} {activeTab === 'analytics' && ( )} {activeTab === 'settings' && (

System Settings

Manage system configuration and preferences

Import / Export

Backup and restore your portfolio data

System Status

Database
Online
Redis Cache
Online
API Services
Online
)}
); }; export default ModernAdminDashboard;