"use client" import { useState, useEffect } from "react" import { useAuth } from "@/context/auth-context" import { useRouter } from "next/router" import { toast } from "react-hot-toast" import type { DashboardStats, ActivityData } from "@/lib/types" import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card" import { Loader2, Award, BookOpen, Code, CheckCircle2, TrendingUp } from "lucide-react" import api from "@/lib/api" export function DashboardStatsOverview() { const { user, firebaseUser, isLoadingAuth, authMethod, token } = useAuth() // Check token for access const router = useRouter() const [stats, setStats] = useState(null) const [activity, setActivity] = useState([]) const [isLoadingData, setIsLoadingData] = useState(true) const [error, setError] = useState(null) useEffect(() => { if (!isLoadingAuth && !user && !firebaseUser) { // Allow either MetaMask or Firebase user toast.error("Please login to view your dashboard.") router.push("/") return } const fetchDashboardData = async () => { setIsLoadingData(true) setError(null) try { // --- ORIGINAL API CALLS (UNCOMMENT WHEN BACKEND IS READY) --- const statsResponse = await api.get("/api/dashboard/stats") setStats(statsResponse.data) const activityResponse = await api.get("/api/dashboard/activity") setActivity(activityResponse.data) } catch (err: any) { console.error("Failed to fetch dashboard data:", err) setError(err.response?.data?.message || "Failed to load dashboard data.") toast.error(err.response?.data?.message || "Failed to load dashboard data.") } finally { setIsLoadingData(false) // Handled by setTimeout } } if (user || firebaseUser) { // Only fetch if either user type is logged in fetchDashboardData() } }, [user, firebaseUser, isLoadingAuth, router, token]) if (isLoadingAuth || isLoadingData) { return (
Loading dashboard...
) } if (error) { return (

{error}

) } if (!stats) { return (

No dashboard data available.

Start learning to see your progress!

) } return (
{authMethod === "firebase" && !token && (

Limited Access

You are logged in with email. Full functionality, including personalized stats and activity tracking, requires connecting your MetaMask wallet.

)}

Your Dashboard

Total XP
{stats.total_xp}

Accumulated experience points

Courses Completed
{stats.courses_completed}

Courses you've finished

Problems Solved
{stats.coding_problems_solved}

Coding challenges mastered

Quiz Accuracy
{stats.quiz_accuracy.toFixed(1)}%

Overall quiz performance

Coding Streak
{stats.coding_streak} days

Consecutive days coding

Activity Heatmap (Coming Soon)

Interactive activity heatmap visualization will appear here.

Strengths/Weaknesses & Leaderboard (Coming Soon)

Radar chart for strengths/weaknesses will appear here.

Global leaderboard will appear here.

) }