"use client" import { useState, useEffect } from "react" import { Card, CardContent } from "@/components/ui/card" import { Button } from "@/components/ui/button" import { Trophy, TrendingUp, AlertTriangle, Sparkles, Building2, Target, Sliders, CheckCircle2, ChevronRight, UserCheck } from "lucide-react" import { useActiveUser, isDemoUser } from "@/hooks/useActiveUser" export default function RankPredictorPage() { const { user } = useActiveUser() const isDemo = isDemoUser(user?.id) const [exam, setExam] = useState<"NEET" | "JEE">("NEET") const [physics, setPhysics] = useState(0) const [chemistry, setChemistry] = useState(0) const [bioOrMath, setBioOrMath] = useState(0) const [saved, setSaved] = useState(false) const [initialized, setInitialized] = useState(false) useEffect(() => { if (!user || initialized) return const isNeet = user.target_exam ? user.target_exam.includes("NEET") : true setExam(isNeet ? "NEET" : "JEE") if (isDemo) { if (isNeet) { setPhysics(140) setChemistry(150) setBioOrMath(320) } else { setPhysics(65) setChemistry(70) setBioOrMath(75) } } else { setPhysics(0) setChemistry(0) setBioOrMath(0) } setInitialized(true) }, [user, isDemo, initialized]) const maxTotal = exam === "NEET" ? 720 : 300 const maxPhysics = exam === "NEET" ? 180 : 100 const maxChem = exam === "NEET" ? 180 : 100 const maxThird = exam === "NEET" ? 360 : 100 const totalScore = physics + chemistry + bioOrMath // Calculate predicted rank based on total score percentage const calculateRank = (score: number, max: number) => { const pct = score / max if (pct >= 0.95) return Math.max(12, Math.round((1 - pct) * 2000)) if (pct >= 0.90) return Math.round(1500 + (0.95 - pct) * 50000) if (pct >= 0.80) return Math.round(4000 + (0.90 - pct) * 80000) if (pct >= 0.70) return Math.round(12000 + (0.80 - pct) * 120000) if (pct >= 0.60) return Math.round(25000 + (0.70 - pct) * 200000) return Math.round(60000 + (0.60 - pct) * 400000) } const predictedRank = calculateRank(totalScore, maxTotal) const colleges = exam === "NEET" ? [ { name: "AIIMS New Delhi", category: "Top Tier Medical", minScore: 690, color: "text-[#00F0FF]", border: "border-[#00F0FF]/30", bg: "bg-[#00F0FF]/10" }, { name: "MAMC New Delhi", category: "Central GMC", minScore: 665, color: "text-amber-400", border: "border-amber-400/30", bg: "bg-amber-400/10" }, { name: "KGMU Lucknow / VMMCH", category: "Premier State GMC", minScore: 635, color: "text-emerald-400", border: "border-emerald-400/30", bg: "bg-emerald-400/10" }, { name: "Top State Govt Medical College", category: "State Quota", minScore: 590, color: "text-purple-400", border: "border-purple-400/30", bg: "bg-purple-400/10" }, ] : [ { name: "IIT Bombay / IIT Delhi (CS)", category: "Top 5 IITs", minScore: 260, color: "text-[#00F0FF]", border: "border-[#00F0FF]/30", bg: "bg-[#00F0FF]/10" }, { name: "IIT Madras / Kharagpur", category: "Core Engineering", minScore: 220, color: "text-amber-400", border: "border-amber-400/30", bg: "bg-amber-400/10" }, { name: "NIT Trichy / Surathkal", category: "Top NITs", minScore: 180, color: "text-emerald-400", border: "border-emerald-400/30", bg: "bg-emerald-400/10" }, { name: "Top State Engineering Colleges", category: "State Govt", minScore: 140, color: "text-purple-400", border: "border-purple-400/30", bg: "bg-purple-400/10" }, ] return (
{/* Header */}
AI Neural Prediction Engine

AI Rank & College Predictor

Simulate your subject marks to dynamically calculate your All India Rank (AIR) and college admission chances.

{user && (
Profile Connected: {user.name.replace(/\s*\([^)]*\)\s*$/, '').trim()} ({user.target_exam?.replace("_", " ")})
)} {/* Exam Switcher */}
{/* Main Grid */}
{/* Left Interactive Simulator */}

Mark Simulator

Drag Sliders to Adjust
{/* Physics Slider */}
Physics Score {physics} / {maxPhysics}
setPhysics(Number(e.target.value))} className="w-full h-2.5 bg-secondary rounded-lg appearance-none cursor-pointer accent-[#00F0FF]" />
{/* Chemistry Slider */}
Chemistry Score {chemistry} / {maxChem}
setChemistry(Number(e.target.value))} className="w-full h-2.5 bg-secondary rounded-lg appearance-none cursor-pointer accent-amber-400" />
{/* Bio / Math Slider */}
{exam === "NEET" ? "Biology Score (Botany + Zoology)" : "Mathematics Score"} {bioOrMath} / {maxThird}
setBioOrMath(Number(e.target.value))} className="w-full h-2.5 bg-secondary rounded-lg appearance-none cursor-pointer accent-emerald-400" />
Simulated Total Score {totalScore} / {maxTotal}
{/* AI Strategy Insights based on Score */}

Strongest Domain

{totalScore === 0 ? "Baseline Calibrating: Solve your first DPP or CBT to benchmark your subject strengths." : `Your Biology/Math score (${bioOrMath}) provides solid rank leverage. Keep maintaining your revision momentum.`}

High-Yield Growth Zone

{totalScore === 0 ? "Zero Baseline: Adjust the sliders above or take practice tests to see rank impact in real time." : "Increasing Physics by just 25 marks will boost your rank by approximately ~4,800 positions."}

{/* Right Output Dashboard */}
{/* AIR Display Card */}
Estimated All India Rank
{totalScore === 0 ? "AIR --" : `AIR ~${predictedRank.toLocaleString()}`}
{totalScore === 0 ? "Calibrating ยท Adjust Sliders" : "High Accuracy Confidence"}
{/* College Admission Probability Table */}

College Admission Chances

{totalScore === 0 ? (

No Marks Simulated

Drag the subject sliders on the left or complete mock tests to view college probability predictions.

) : (
{colleges.map((c) => { const isLikely = totalScore >= c.minScore const chancePct = Math.min(99, Math.max(10, Math.round((totalScore / c.minScore) * 85))) return (
{c.name} {isLikely ? `${chancePct}% Likely` : "Reach Target"}
{c.category} Cutoff Score: {c.minScore}+
) })}
)}
) }