"use client" import { useState, useEffect } from "react" import { Card, CardContent } from "@/components/ui/card" import { Button } from "@/components/ui/button" import { BrainCircuit, Clock, CheckCircle2, AlertTriangle, ArrowLeft, ArrowRight, ShieldAlert, Sparkles, Send } from "lucide-react" import Link from "next/link" import { useActiveUser } from "@/hooks/useActiveUser" import { useRouter } from "next/navigation" export default function AIComCBTDPPPage() { const { user, hasAccessTo, loading } = useActiveUser() const router = useRouter() const [activeQuestion, setActiveQuestion] = useState(0) const [selectedAnswers, setSelectedAnswers] = useState>({}) const [timeLeft, setTimeLeft] = useState(1800) // 30 minutes const [submitted, setSubmitted] = useState(false) // Mock AI CBT DPP questions const sampleQuestions = [ { id: 1, subject: "Physics", topic: "Rotational Dynamics & Torque", question: "A uniform disc of mass M and radius R rotates about an axis passing through its center and perpendicular to its plane. Its moment of inertia about a tangent parallel to its plane is:", options: ["(1/2) M R²", "(5/4) M R²", "(3/2) M R²", "(7/4) M R²"], correct: 1, explanation: "Using parallel axis theorem: I_tangent = I_cm + M R^2 = (1/4 M R^2) + M R^2 = 5/4 M R^2." }, { id: 2, subject: "Chemistry", topic: "Chemical Equilibrium & Kp/Kc", question: "For the reaction N2(g) + 3H2(g) ⇌ 2NH3(g), the value of Kp / Kc at temperature T Kelvin is given by:", options: ["(RT)⁻²", "(RT)⁻¹", "(RT)", "(RT)²"], correct: 0, explanation: "Δn_g = 2 - (1 + 3) = -2. Therefore, Kp = Kc (RT)^(-2), so Kp / Kc = (RT)^(-2)." }, { id: 3, subject: "Biology / Maths", topic: "Calculus / Cell Biology", question: "Which organelle is responsible for the synthesis of lipids and steroidal hormones in eukaryotic cells?", options: ["Rough Endoplasmic Reticulum", "Smooth Endoplasmic Reticulum", "Golgi Apparatus", "Lysosome"], correct: 1, explanation: "Smooth Endoplasmic Reticulum (SER) is the primary site for synthesis of lipids and steroid hormones." }, { id: 4, subject: "Physics", topic: "Electrostatics & Potential", question: "Two point charges +q and -q are placed at distance 2a. The electric potential at the midpoint of the line joining them is:", options: ["Zero", "q / (4πε₀a)", "2q / (4πε₀a)", "Infinity"], correct: 0, explanation: "V_total = V_+q + V_-q = (q / 4πε₀a) + (-q / 4πε₀a) = 0." }, { id: 5, subject: "Chemistry", topic: "Organic Mechanism & Nucleophiles", question: "Which of the following undergoes SN1 reaction at the fastest rate?", options: ["Methyl chloride", "Ethyl chloride", "Isopropyl chloride", "Tert-butyl chloride"], correct: 3, explanation: "SN1 rate depends on carbocation stability. Tert-butyl carbocation (3°) is the most stable." } ] useEffect(() => { if (submitted || timeLeft <= 0) return const timer = setInterval(() => { setTimeLeft(prev => Math.max(0, prev - 1)) }, 1000) return () => clearInterval(timer) }, [submitted, timeLeft]) const formatTime = (secs: number) => { const m = Math.floor(secs / 60) const s = secs % 60 return `${m.toString().padStart(2, '0')}:${s.toString().padStart(2, '0')}` } const handleOptionSelect = (qIdx: number, optIdx: number) => { if (submitted) return setSelectedAnswers(prev => ({ ...prev, [qIdx]: String.fromCharCode(65 + optIdx) })) } const calculateScore = () => { let score = 0 sampleQuestions.forEach((q, idx) => { const selected = selectedAnswers[idx] if (selected) { const selectedOptIdx = selected.charCodeAt(0) - 65 if (selectedOptIdx === q.correct) score += 4 else score -= 1 } }) return score } if (loading) { return
Loading AI Coach CBT Engine...
} return (
{/* Top Header */}
PrepPilot AI • {user?.target_exam?.replace("_", " ") || "JEE/NEET"}

Interactive Target DPP #14

{formatTime(timeLeft)}
{!submitted ? ( ) : ( )}
{submitted && (

CBT DPP Completed!

Your performance analysis has been evaluated by the AI Evaluator.

{calculateScore()} / 20

Total Marks

)} {/* Main CBT Grid */}
{/* Question Area */}
Question {activeQuestion + 1} of {sampleQuestions.length} {sampleQuestions[activeQuestion].topic}

{sampleQuestions[activeQuestion].question}

{sampleQuestions[activeQuestion].options.map((opt, optIdx) => { const letter = String.fromCharCode(65 + optIdx) const isSelected = selectedAnswers[activeQuestion] === letter const isCorrect = sampleQuestions[activeQuestion].correct === optIdx let btnStyle = "border-border bg-secondary/20 hover:border-primary/50 text-foreground" if (isSelected) { btnStyle = "border-[var(--cyan-ai)] bg-[var(--cyan-ai)]/15 text-[var(--cyan-ai)] font-bold shadow-[0_0_12px_rgba(12,96,96,0.15)]" } if (submitted) { if (isCorrect) btnStyle = "border-emerald-500 bg-emerald-500/20 text-emerald-400 font-bold" else if (isSelected && !isCorrect) btnStyle = "border-red-500 bg-red-500/20 text-red-400 font-bold" } return (
handleOptionSelect(activeQuestion, optIdx)} className={`flex items-center gap-4 p-4.5 rounded-2xl border cursor-pointer transition-all ${btnStyle}`} > {letter} {opt} {submitted && isCorrect && }
) })}
{submitted && (
AI Solution & Explanation:

{sampleQuestions[activeQuestion].explanation}

)}
{/* Navigation buttons */}
{/* Question Palette Sidebar */}

Question Palette

{sampleQuestions.map((q, idx) => { const isAns = !!selectedAnswers[idx] const isCurr = activeQuestion === idx return ( ) })}
Current Question
Answered
Unattempted
) }