"use client" import { TrendingUp, TrendingDown, Brain, Zap, Target, Clock } from "lucide-react" import { Card, CardContent } from "@/components/ui/card" import { useState } from "react" import { useActiveUser, isDemoUser } from "@/hooks/useActiveUser" const DAYS = ["Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"] const DEMO_QUESTIONS = [42, 58, 35, 71, 65, 48, 60] const DEMO_ACCURACY = [82, 78, 91, 88, 85, 79, 93] const DEMO_HOURS = [2.5, 3.5, 2, 4.5, 4, 3, 3.8] const ZERO_DATA = [0, 0, 0, 0, 0, 0, 0] export function WeeklyProgressReport() { const { userId } = useActiveUser() const isDemo = isDemoUser(userId) const [metric, setMetric] = useState<"questions" | "accuracy" | "hours">("accuracy") const [hovered, setHovered] = useState(null) const QUESTIONS = isDemo ? DEMO_QUESTIONS : ZERO_DATA const ACCURACY = isDemo ? DEMO_ACCURACY : ZERO_DATA const HOURS = isDemo ? DEMO_HOURS : ZERO_DATA const DATA = metric === "questions" ? QUESTIONS : metric === "accuracy" ? ACCURACY : HOURS const maxVal = Math.max(1, ...DATA) const avgVal = Math.round((DATA.reduce((a, b) => a + b, 0) / DATA.length) * 10) / 10 const trend = isDemo ? DATA[DATA.length - 1] - DATA[0] : 0 const trendUp = trend >= 0 const UNIT = metric === "accuracy" ? "%" : metric === "hours" ? "h" : "" const avgAccuracy = isDemo ? Math.round(ACCURACY.reduce((a, b) => a + b, 0) / ACCURACY.length) : 0 return (
{/* Summary chips */}
{avgAccuracy}% avg accuracy
{trendUp ? : } {trendUp ? "+" : ""}{trend}{UNIT} vs Mon
{isDemo ? "7/7 days active" : "Day 1 Active"}
{/* Metric Toggle */}
{(["accuracy", "questions", "hours"] as const).map((m) => ( ))}
{/* Bar Chart with Y-axis */}
{/* Y-axis */}
{[100, 75, 50, 25, 0].map(v => ( {metric === "hours" ? (v / 100 * 5).toFixed(1) : `${v}${metric === "accuracy" ? "%" : ""}`} ))}
{/* Grid + Bars */}
{[25, 50, 75].map(pct => (
))}
{DAYS.map((day, i) => (
setHovered(i)} onMouseLeave={() => setHovered(null)} > {/* Tooltip */} {hovered === i && (
{day}
{DATA[i]}{UNIT}
)}
))}
{/* X labels */}
{DAYS.map((day) => (
{day}
))}
{/* Quick stats row */}
{[ { label: "Avg Accuracy", value: `${avgAccuracy}%`, icon: }, { label: "Questions / Day", value: isDemo ? `${Math.round(QUESTIONS.reduce((a, b) => a + b, 0) / 7)}` : "0", icon: }, { label: "Study Hrs / Day", value: isDemo ? `${(HOURS.reduce((a, b) => a + b, 0) / 7).toFixed(1)}h` : "0.0h", icon: }, ].map(stat => (
{stat.icon}
{stat.value}
{stat.label}
))}
{/* AI insight */}
{isDemo ? ( <> Sign errors in Thermodynamics — detected in your last 3 attempts (W = −PΔV misapplied). We've queued 3 targeted practice questions for tomorrow.{" "} Tip: You peak at 7–9 PM. Schedule the hardest topics then. ) : ( <> AI Progress Engine Calibrating — Complete your first CBT mock test or DPP to begin mapping subject retention, speed trends, and error velocity. )}
) }