'use client'; import React, { useState, useEffect } from 'react'; import { motion, AnimatePresence } from 'framer-motion'; import { Mail, Users, BarChart3, Database, Zap, Globe, Shield, Bell, Settings, FileText, TrendingUp, ArrowLeft, Plus, Edit, Trash2, Eye, Save, Upload, Bold, Italic, List, Link as LinkIcon, Image as ImageIcon, Code, Quote, ChevronDown, ChevronRight, Palette, Smile } from 'lucide-react'; import Link from 'next/link'; import ReactMarkdown from 'react-markdown'; import { EmailManager } from './EmailManager'; import { AnalyticsDashboard } from './AnalyticsDashboard'; import ImportExport from './ImportExport'; interface Project { id: number; title: string; description: string; content: string; tags: string[]; featured: boolean; category: string; date: string; github?: string; live?: string; published: boolean; imageUrl?: string; metaDescription?: string; keywords?: string; ogImage?: string; schema?: Record; difficulty: 'Beginner' | 'Intermediate' | 'Advanced' | 'Expert'; timeToComplete?: string; technologies: string[]; challenges: string[]; lessonsLearned: string[]; futureImprovements: string[]; demoVideo?: string; screenshots: string[]; colorScheme: string; accessibility: boolean; performance: { lighthouse: number; bundleSize: string; loadTime: string; }; analytics: { views: number; likes: number; shares: number; }; } const ModernAdminDashboard: React.FC = () => { const [activeTab, setActiveTab] = useState<'overview' | 'projects' | 'emails' | 'analytics' | 'settings'>('overview'); const [projects, setProjects] = useState([]); const [selectedProject, setSelectedProject] = useState(null); const [isLoading, setIsLoading] = useState(true); const [showProjectEditor, setShowProjectEditor] = useState(false); const [isPreview, setIsPreview] = useState(false); const [markdownContent, setMarkdownContent] = useState(''); const [formData, setFormData] = useState({ title: '', description: '', content: '', tags: '', category: '', featured: false, github: '', live: '', published: true, imageUrl: '', difficulty: 'Intermediate' as 'Beginner' | 'Intermediate' | 'Advanced' | 'Expert', timeToComplete: '', technologies: '', challenges: '', lessonsLearned: '', futureImprovements: '', demoVideo: '', screenshots: '', colorScheme: 'Dark', accessibility: true, performance: { lighthouse: 90, bundleSize: '50KB', loadTime: '1.5s' }, analytics: { views: 0, likes: 0, shares: 0 } }); // Mock stats for overview const stats = { totalProjects: projects.length, publishedProjects: projects.filter(p => p.published).length, totalViews: projects.reduce((sum, p) => sum + p.analytics.views, 0), unreadEmails: 3, // This would come from your email API avgPerformance: Math.round(projects.reduce((sum, p) => sum + p.performance.lighthouse, 0) / projects.length) || 90 }; useEffect(() => { loadProjects(); }, []); const loadProjects = async () => { try { setIsLoading(true); const response = await fetch('/api/projects'); const data = await response.json(); setProjects(data.projects || []); } catch (error) { console.error('Error loading projects:', error); } finally { setIsLoading(false); } }; const handleEdit = (project: Project) => { setSelectedProject(project); setFormData({ title: project.title, description: project.description, content: project.content, tags: project.tags.join(', '), category: project.category, featured: project.featured, github: project.github || '', live: project.live || '', published: project.published, imageUrl: project.imageUrl || '', difficulty: project.difficulty, timeToComplete: project.timeToComplete || '', technologies: project.technologies.join(', '), challenges: project.challenges.join(', '), lessonsLearned: project.lessonsLearned.join(', '), futureImprovements: project.futureImprovements.join(', '), demoVideo: project.demoVideo || '', screenshots: project.screenshots.join(', '), colorScheme: project.colorScheme, accessibility: project.accessibility, performance: project.performance, analytics: project.analytics }); setMarkdownContent(project.content); setShowProjectEditor(true); }; const handleSave = async () => { // Save logic here console.log('Saving project...'); await loadProjects(); setShowProjectEditor(false); setSelectedProject(null); }; const handleDelete = async (projectId: number) => { if (confirm('Are you sure you want to delete this project?')) { try { await fetch(`/api/projects/${projectId}`, { method: 'DELETE' }); await loadProjects(); } catch (error) { console.error('Error deleting project:', error); } } }; const resetForm = () => { setSelectedProject(null); setFormData({ title: '', description: '', content: '', tags: '', category: '', featured: false, github: '', live: '', published: true, imageUrl: '', difficulty: 'Intermediate' as 'Beginner' | 'Intermediate' | 'Advanced' | 'Expert', timeToComplete: '', technologies: '', challenges: '', lessonsLearned: '', futureImprovements: '', demoVideo: '', screenshots: '', colorScheme: 'Dark', accessibility: true, performance: { lighthouse: 90, bundleSize: '50KB', loadTime: '1.5s' }, analytics: { views: 0, likes: 0, shares: 0 } }); setMarkdownContent(''); setShowProjectEditor(false); }; const tabs = [ { id: 'overview', label: 'Overview', icon: BarChart3, color: 'blue' }, { id: 'projects', label: 'Projects', icon: FileText, color: 'green' }, { id: 'emails', label: 'Emails', icon: Mail, color: 'purple' }, { id: 'analytics', label: 'Analytics', icon: TrendingUp, color: 'orange' }, { id: 'settings', label: 'Settings', icon: Settings, color: 'gray' } ]; const categories = [ "Web Development", "Full-Stack", "Web Application", "Mobile App", "Desktop App", "API Development", "Database Design", "DevOps", "UI/UX Design", "Game Development", "Machine Learning", "Data Science", "Blockchain", "IoT", "Cybersecurity" ]; return (
{/* Header */}
Back to Portfolio

Admin Dashboard

Live
dk0.dev
{/* Sidebar */}
{/* Main Content */}
{activeTab === 'overview' && ( {/* Stats Grid */}

Total Projects

{stats.totalProjects}

Published

{stats.publishedProjects}

Total Views

{stats.totalViews.toLocaleString()}

Avg Performance

{stats.avgPerformance}

{/* Recent Projects */}

Recent Projects

{projects.slice(0, 3).map((project) => (
{project.title.charAt(0)}

{project.title}

{project.category}

{project.published ? 'Published' : 'Draft'}
))}
)} {activeTab === 'projects' && (

Projects

{isLoading ? (
) : (
{projects.map((project) => (
{project.title.charAt(0)}

{project.title}

{project.description}

{project.category} {project.published ? 'Published' : 'Draft'}
))}
)}
)} {activeTab === 'emails' && ( )} {activeTab === 'analytics' && ( )} {activeTab === 'settings' && (

Settings

Import/Export

)}
); }; export default ModernAdminDashboard;