"use client" import { fetchWithAuth } from "@/lib/apiClient"; import { useState, useEffect } from "react" import { Card, CardContent } from "@/components/ui/card" import { Flame, Gift, Star, Trophy, Target, ArrowRight, CheckCircle2 } from "lucide-react" import { useActiveUser, isDemoUser } from "@/hooks/useActiveUser" export default function StreaksPage() { const { user } = useActiveUser() const isDemo = isDemoUser(user?.id) const currentStreak = user?.streak_count ?? 1 const bestStreak = isDemo ? (user?.longest_streak ?? 45) : Math.max(currentStreak, user?.longest_streak ?? 1) const [streakPoints, setStreakPoints] = useState(0) useEffect(() => { if (!user?.id) return if (isDemo) { setStreakPoints(currentStreak * 50) return } async function loadStats() { try { const res = await fetchWithAuth(`/api/users/${user?.id}/stats`) if (res.ok) { const stats = await res.json() if (!stats.is_new_user) { setStreakPoints(currentStreak * 50) } else { setStreakPoints(0) } } } catch { setStreakPoints(0) } } loadStats() }, [user?.id, isDemo, currentStreak]) const rewards = [ { streak: 7, title: "Consistent Learner", reward: "1 Free Premium DPP", unlocked: currentStreak >= 7 }, { streak: 14, title: "Dedicated Scholar", reward: "AI Performance Analysis Report", unlocked: currentStreak >= 14 }, { streak: 30, title: "Exam Warrior", reward: "1 Full Length Mock Test", unlocked: currentStreak >= 30 }, { streak: 50, title: "PragatiVeer Champion", reward: "1-on-1 AI Tutor Session", unlocked: currentStreak >= 50 }, { streak: 100, title: "Unstoppable", reward: "Merch + 50% Off Next Renewal", unlocked: currentStreak >= 100 }, ]; return (

Your Learning Streak

Build daily habits to unlock premium rewards and boost your rank.

{currentStreak} Days

CURRENT STREAK

{streakPoints === 0 ? "Complete your first Daily Practice Problem (DPP) or CBT Exam today to start earning streak points." : "Complete a Daily Practice Problem (DPP) or CBT Exam every day to keep your streak alive."}

STREAK STATS

Personal Best

{bestStreak} Days

Total Streak Points Earned

{streakPoints.toLocaleString()}

{streakPoints === 0 && (

Take a test to activate consistency bonus points

)}

Pro Tip: Your streak directly multiplies your leaderboard score. A longer streak gives you a higher Consistency Bonus.

Streak Rewards

{rewards.map((reward, i) => (
{reward.streak}

{reward.title}

{reward.reward}

{reward.unlocked ? (
Unlocked
) : (
{reward.streak - currentStreak} days to go
)}
))}
) }