"use client" import { useEffect, useState } from "react" import { Card, CardContent } from "@/components/ui/card" import { TrendingUp, Flame, RefreshCw } from "lucide-react" import Link from "next/link" import { useActiveUser } from "@/hooks/useActiveUser" export function ReadinessGauge() { const [data, setData] = useState(null) const [loading, setLoading] = useState(true) const { userId, loading: userLoading } = useActiveUser(); useEffect(() => { if (userLoading || !userId) return; async function fetchReadiness() { try { const res = await fetch(`/api/ai-coach/readiness/${userId}`) if (!res.ok) throw new Error("Failed to fetch") const json = await res.json() setData(json) } catch (err) { console.warn("Using mock fallback data for Readiness Gauge.") setData({ score: 72, breakdown: { accuracy: 30, speed: 15, consistency: 8, recovery: 5, coverage: 14 } }) } finally { setLoading(false) } } fetchReadiness() }, [userId, userLoading]) if (loading) { return ( ) } const score = data?.score || 0 const breakdown = data?.breakdown || {} const circumference = 2 * Math.PI * 45 // r=45 const strokeDashoffset = circumference - (score / 100) * circumference const getColor = (s: number) => { if (s >= 75) return "text-green-500" if (s >= 50) return "text-yellow-500" return "text-red-500" } return (
{/* Background glow decoration */}
Updated daily • Today +5 this week
{/* Circular Score */}
{score} SCORE
{/* Quick metric grid beside ring */}
88% ↑
Accuracy
45s ↓
Speed/Q
High ↑
Consistency
64% ↑
Syllabus
{/* Subject Bars */}
{[ { name: "Physics", val: 68, color: "#00F0FF" }, { name: "Chemistry", val: 74, color: "#F59E0B" }, { name: "Biology", val: 82, color: "#10B981" }, ].map(sub => (
{sub.name}
{sub.val}%
))}
{/* National Avg */}
National Avg 58 / 100 You: +{score - 58} above avg
Your speed has dropped slightly. Focus on time-bound practice today.
) }