'use client'; import { useState, useEffect } from 'react'; import { motion } from 'framer-motion'; import { BarChart3, TrendingUp, Eye, Heart, Zap, Users, Clock, Globe, Activity, Target, Award } from 'lucide-react'; interface AnalyticsData { overview: { totalProjects: number; publishedProjects: number; featuredProjects: number; totalViews: number; totalLikes: number; totalShares: number; avgLighthouse: number; }; projects: Array<{ id: number; title: string; category: string; difficulty: string; views: number; likes: number; shares: number; lighthouse: number; published: boolean; featured: boolean; createdAt: string; updatedAt: string; }>; categories: Record; difficulties: Record; performance: { avgLighthouse: number; totalViews: number; totalLikes: number; totalShares: number; }; } interface PerformanceData { pageViews: { total: number; last24h: number; last7d: number; last30d: number; }; interactions: { total: number; last24h: number; last7d: number; last30d: number; }; topPages: Record; topInteractions: Record; } export function AnalyticsDashboard() { const [analyticsData, setAnalyticsData] = useState(null); const [performanceData, setPerformanceData] = useState(null); const [loading, setLoading] = useState(true); const [error, setError] = useState(null); useEffect(() => { fetchAnalyticsData(); }, []); const fetchAnalyticsData = async () => { try { setLoading(true); // Get basic auth from environment or use default const auth = btoa('admin:change_this_password_123'); const [analyticsRes, performanceRes] = await Promise.all([ fetch('/api/analytics/dashboard', { headers: { 'Authorization': `Basic ${auth}` } }), fetch('/api/analytics/performance', { headers: { 'Authorization': `Basic ${auth}` } }) ]); if (!analyticsRes.ok || !performanceRes.ok) { throw new Error('Failed to fetch analytics data'); } const [analytics, performance] = await Promise.all([ analyticsRes.json(), performanceRes.json() ]); setAnalyticsData(analytics); setPerformanceData(performance); } catch (err) { setError(err instanceof Error ? err.message : 'Unknown error'); } finally { setLoading(false); } }; if (loading) { return (
{[...Array(4)].map((_, i) => (
))}
); } if (error) { return (

Error loading analytics: {error}

); } if (!analyticsData || !performanceData) return null; const StatCard = ({ title, value, icon: Icon, color, trend }: { title: string; value: number | string; icon: React.ComponentType<{ className?: string }>; color: string; trend?: string; }) => (

{title}

{value}

{trend && (

{trend}

)}
); const getDifficultyColor = (difficulty: string) => { switch (difficulty) { case 'Beginner': return 'bg-green-500'; case 'Intermediate': return 'bg-yellow-500'; case 'Advanced': return 'bg-orange-500'; case 'Expert': return 'bg-red-500'; default: return 'bg-gray-500'; } }; return (
{/* Header */}

Analytics Dashboard

Übersicht über deine Portfolio-Performance

{/* Overview Stats */}
{/* Performance Stats */}
{/* Projects Performance */}

Top Performing Projects

{analyticsData.projects .sort((a, b) => b.views - a.views) .slice(0, 5) .map((project, index) => (
{index + 1}

{project.title}

{project.difficulty} {project.category}

{project.views}

Views

{project.likes}

Likes

{project.lighthouse}

Lighthouse

))}
{/* Categories & Difficulties */}

Projects by Category

{Object.entries(analyticsData.categories) .sort(([,a], [,b]) => b - a) .map(([category, count]) => (
{category}
{count}
))}

Projects by Difficulty

{Object.entries(analyticsData.difficulties) .sort(([,a], [,b]) => b - a) .map(([difficulty, count]) => (
{difficulty}
{count}
))}
); } export default AnalyticsDashboard;