"use client"; import { useState, useEffect } from "react"; import { useAuth } from "@/lib/AuthContext"; import Link from "next/link"; import { useRouter } from "next/navigation"; import { Bot, ShoppingBag, MessageCircle, Wallet, Flame, Sparkles, Star, ChevronRight, BookOpen, MapPin, Crown, Zap, TrendingUp, Gift, Trophy, CircleDot, Compass, } from "lucide-react"; import { DAILY_VERSE, generateAIResponse } from "@/lib/ai"; import PremiumBadge from "@/components/PremiumBadge"; export default function HomePage() { const { user, token, loading, streak, xp, refreshStreak, refreshXp, refreshUser } = useAuth(); const router = useRouter(); const [verse] = useState(DAILY_VERSE[Math.floor(Math.random() * DAILY_VERSE.length)]); const [claiming, setClaiming] = useState(false); const [claimResult, setClaimResult] = useState(null); const [dhikrTodayCount, setDhikrTodayCount] = useState(0); useEffect(() => { if (!loading && !token) router.push("/auth"); }, [loading, token, router]); // Refresh streak/XP data every 60 seconds useEffect(() => { if (!token) return; const interval = setInterval(() => { refreshStreak(); refreshXp(); }, 60000); return () => clearInterval(interval); }, [token, refreshStreak, refreshXp]); // Fetch dhikr stats useEffect(() => { if (!token) return; fetch("/mobile/api/dhikr/stats", { headers: { Authorization: `Bearer ${token}` }, }) .then((r) => r.ok ? r.json() : null) .then((data) => { if (data?.dayStats?.totalCount != null) setDhikrTodayCount(data.dayStats.totalCount); }) .catch(() => {}); }, [token]); const handleClaimReward = async () => { if (!token || claiming) return; setClaiming(true); setClaimResult(null); try { const res = await fetch("/mobile/api/gamification/streak", { method: "POST", headers: { Authorization: `Bearer ${token}` }, }); if (res.ok) { const data = await res.json(); setClaimResult( `Claimed! +${data.reward} FLH, +${data.xpGain} XP${ data.newLevel ? ` โ€” Level Up! You're now level ${data.newLevel}! ๐ŸŽ‰` : "" }` ); refreshStreak(); refreshXp(); refreshUser(); // update FLH balance } else if (res.status === 409) { setClaimResult("Already claimed today!"); } else { const err = await res.json(); setClaimResult(err.error || "Failed to claim"); } } catch { setClaimResult("Network error โ€” try again"); } finally { setClaiming(false); setTimeout(() => setClaimResult(null), 5000); } }; if (loading) return ; if (!user) return null; const isPremium = user.isPremium || user.isPro; const isPro = user.isPro; const currentStreak = streak?.currentStreak ?? 0; const canClaim = streak?.canClaim ?? false; const todayReward = streak?.todayReward ?? 0; const level = xp?.level ?? 1; const currentXp = xp?.xp ?? 0; const xpToNext = xp?.xpToNext ?? 100; const xpPercent = xpToNext > 0 ? Math.min(Math.round((currentXp / xpToNext) * 100), 100) : 0; return (
{/* Header */}

Assalamualaikum, {user.name.split(" ")[0]} โ˜ช๏ธ {/* Level Badge */}
Lv.{level}
{user.isPro && } {user.isPremium && !user.isPro && }

{new Date().toLocaleDateString("en-MY", { weekday: "long", day: "numeric", month: "long", year: "numeric" })}

{/* Streak */}
0 ? "bg-gradient-to-r from-orange-900/40 to-orange-800/20 border border-orange-700/30" : "bg-gray-900/40 border border-gray-800/30" }`}> 0 ? "text-orange-400 flame" : "text-gray-600"} /> 0 ? "text-orange-300" : "text-gray-500"}`}> {currentStreak} day
{/* XP Progress Bar */}
XP Progress {currentXp} / {xpToNext} XP
{/* Premium banner */} {!isPremium && (

Go Premium

Unlock unlimited AI & more

)} {/* Pro badge */} {isPro && (
Pro Member โ€” Unlimited Everything
)} {/* FLH Earning Rate - shown for premium/pro */} {(isPremium || isPro) && (
2x Earning Active โ€” Earn double FLH on marketplace sales
)}
{/* Daily Verse */}
Daily Verse

{verse.arabic}

“{verse.translation}”

โ€” {verse.reference}

{/* Streak Reward Card */}

Daily Reward

{canClaim ? `Claim your streak reward โ€” +${todayReward} FLH` : "Reward claimed โ€” come back tomorrow!"}

{todayReward.toLocaleString()}

FLH reward

{/* Claim button */} {canClaim ? ( ) : (
โœ… Claimed
)} {/* Claim result toast */} {claimResult && (
{claimResult}
)} {/* XP hint */}

+{Math.min(10 + currentStreak * 2, 100)} XP also awarded on claim

{/* Quick Actions */}

Quick Actions

{/* Dhikr Today */}

Dhikr Today

Digital Tasbih Counter

{dhikrTodayCount.toLocaleString()}

counts

ุณูุจู’ุญูŽุงู†ูŽ ูฑู„ู„ูŽู‘ูฐู‡ู ยท ูฑู„ู’ุญูŽู…ู’ุฏู ู„ูู„ูŽู‘ูฐู‡ู ยท ูฑู„ู„ูŽู‘ูฐู‡ู ุฃูŽูƒู’ุจูŽุฑู
{/* Qibla Finder */}

Qibla Finder

Find direction to the Kaaba

{/* Stats Row */}
{/* Activity Feed */}

Activity

View all

No recent activity

Start a conversation with Nur AI

{/* Premium upsell at bottom for free users */} {!isPremium && (

Unlock Your Full Potential

Premium gives you unlimited AI, halal monitor, 2x FLH earning, and marketplace access.

See Plans
)}
); } function QuickAction({ href, icon: Icon, label, color }: { href: string; icon: any; label: string; color: string }) { return (
{label} ); } function StatCard({ label, value, icon: Icon, color }: { label: string; value: string; icon: any; color: string }) { return (

{value}

{label}

); } function LoadingScreen() { return (
); }