"use client"; import { fetchWithAuth } from "@/lib/apiClient"; import { useEffect, useState } from "react" import { MistakeHeatmap } from "@/components/AI/MistakeHeatmap" import { StudyPlanCard } from "@/components/AI/StudyPlanCard" import { ReadinessGauge } from "@/components/AI/ReadinessGauge" import { CollegePredictorCard } from "@/components/AI/CollegePredictorCard" import { ExamStrategyCard } from "@/components/AI/ExamStrategyCard" import { StudyTimeOptimizationCard } from "@/components/AI/StudyTimeOptimizationCard" import { TutorChat } from "@/components/AI/TutorChat" import { ReferralCard } from "@/components/AI/ReferralCard" import { ProgressShare } from "@/components/AI/ProgressShare" import { DailyChallengeBanner } from "@/components/AI/DailyChallengeBanner" import { WeeklyProgressReport } from "@/components/AI/WeeklyProgressReport" import { Card, CardContent } from "@/components/ui/card" import { Button } from "@/components/ui/button" import { BrainCircuit, RefreshCw, CheckCircle2, Flame, Trophy, Target, Zap, BookOpen, Bot, FileText } from "lucide-react" import { useActiveUser, isDemoUser } from "@/hooks/useActiveUser" import Link from "next/link" // Days until NEET 2026 (May 3, 2026) function getDaysToExam(exam: string) { const targets: Record = { "NEET": new Date("2026-05-03"), "JEE_Main": new Date("2026-01-22"), "JEE_Advanced": new Date("2026-05-24"), } const t = targets[exam] || targets["NEET"] const diff = Math.ceil((t.getTime() - Date.now()) / 86400000) return diff > 0 ? diff : 0 } export default function AICoachDashboard() { const [stats, setStats] = useState(null) const { userId, user, hasAccessTo, loading: userLoading } = useActiveUser(); const isDemo = isDemoUser(userId); useEffect(() => { if (!userLoading && userId) { fetchWithAuth(`/api/users/${userId}/stats`) .then(res => res.ok ? res.json() : null) .then(data => setStats(data)) .catch(() => setStats(null)) } }, [userId, userLoading]) if (userLoading) { return (
Loading AI Coach...
) } if (!hasAccessTo("ai-mistake-tracking")) { return (

AI Coach Workspace

Mistake tracking, Spaced Repetition (SM-2), AI Tutor Chats, and Readiness scores are premium features reserved for AI Coach subscribers.

) } const daysLeft = getDaysToExam(user?.target_exam || "NEET") const questionsSolved = isDemo ? "1,247" : (stats?.total_questions_attempted ?? 0).toLocaleString() const overallAccuracy = isDemo ? "74%" : `${stats?.overall_accuracy ?? 0}%` const mistakesMastered = isDemo ? 38 : 0 const aiSessions = isDemo ? 124 : 0 const currentStreakDays = `${user?.streak_count || (isDemo ? 12 : 1)} d` return (
{/* ── METRICS BAR ── */}
{user?.streak_count || 1}-Day Streak
{daysLeft} days to {user?.target_exam?.replace("_", " ") || "Exam"}
AI Coach
{/* ── DAILY CHALLENGE BANNER ── */} {/* ── QUICK STATS ── */}
{[ { label: "Questions Solved", value: questionsSolved, color: "text-[var(--cyan-ai)]", bg: "bg-[var(--cyan-ai-10)]", border: "border-[var(--cyan-ai-20)]", icon: }, { label: "Overall Accuracy", value: overallAccuracy, color: "text-amber-500", bg: "bg-amber-500/5", border: "border-amber-500/20", icon: }, { label: "Current Streak", value: currentStreakDays, color: "text-yellow-400", bg: "bg-yellow-400/5", border: "border-yellow-400/20", icon: }, { label: "Mistakes Mastered", value: mistakesMastered, color: "text-green-400", bg: "bg-green-400/5", border: "border-green-400/20", icon: }, { label: "AI Sessions", value: aiSessions, color: "text-purple-400", bg: "bg-purple-400/5", border: "border-purple-400/20", icon: }, ].map((stat) => (
{stat.icon}
{stat.value}
{stat.label}
))}
{/* ── PREDICTIVE INTELLIGENCE ROW ── */}
Predictive Intelligence & Strategy
Full Analytics →
{/* ── HEATMAP / STUDY PLAN / WEEKLY REPORT ── */}
Study Plan
Full Schedule →
Mastery Map
Mastery Map Vault →
Weekly Progress Overview
View Details →
{/* ── TUTOR CHAT ── */}

24/7 AI Tutor Chat Assistant

Full Desk Mode →
{/* ── GROWTH HUB ── */}
) }