Files
falah-mobile/src/app/page.tsx
T

178 lines
7.7 KiB
TypeScript
Raw Normal View History

"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,
} from "lucide-react";
import { DAILY_VERSE, generateAIResponse } from "@/lib/ai";
export default function HomePage() {
const { user, token, loading } = useAuth();
const router = useRouter();
const [streak, setStreak] = useState(0);
const [verse, setVerse] = useState(DAILY_VERSE[Math.floor(Math.random() * DAILY_VERSE.length)]);
useEffect(() => {
if (!loading && !token) router.push("/login");
}, [loading, token, router]);
if (loading) return <LoadingScreen />;
if (!user) return null;
const isPremium = user.isPremium || user.isPro;
const isPro = user.isPro;
2026-06-15 08:54:27 +02:00
return (
<div className="min-h-dvh bg-[#0a0a0f] pb-24">
{/* Header */}
<div className="px-4 pt-6 pb-4">
<div className="flex items-center justify-between mb-1">
<div>
<h1 className="text-xl font-bold text-white">
Assalamualaikum, {user.name.split(" ")[0]} ☪️
</h1>
<p className="text-xs text-gray-500 mt-0.5">
{new Date().toLocaleDateString("en-MY", { weekday: "long", day: "numeric", month: "long", year: "numeric" })}
</p>
</div>
{/* Streak */}
{streak > 0 && (
<div className="flex items-center gap-1.5 bg-gradient-to-r from-orange-900/40 to-orange-800/20 border border-orange-700/30 rounded-xl px-3 py-2">
<Flame size={16} className="text-orange-400 flame" />
<span className="text-sm font-bold text-orange-300">{streak}</span>
<span className="text-[10px] text-orange-400/70">day</span>
</div>
)}
</div>
{/* Premium banner */}
{!isPremium && (
<Link href="/upgrade"
className="mt-3 flex items-center justify-between glass-gold rounded-2xl px-4 py-3 active:opacity-80 transition">
<div className="flex items-center gap-3">
<div className="w-8 h-8 rounded-full bg-[#D4AF37]/20 flex items-center justify-center">
<Sparkles size={16} className="text-[#D4AF37]" />
</div>
<div>
<p className="text-sm font-semibold text-[#D4AF37]">Go Premium</p>
<p className="text-[11px] text-gray-500">Unlock unlimited AI & more</p>
</div>
</div>
<ChevronRight size={16} className="text-[#D4AF37]" />
</Link>
)}
{/* Pro badge */}
{isPro && (
<div className="mt-3 flex items-center gap-2 bg-purple-900/20 border border-purple-500/30 rounded-2xl px-4 py-2.5">
<Crown size={16} className="text-purple-400" />
<span className="text-sm font-medium text-purple-300">Pro Member Unlimited Everything</span>
</div>
)}
</div>
{/* Daily Verse */}
<div className="mx-4 mb-5 bg-gradient-to-br from-emerald-900/20 to-[#111118] border border-emerald-800/30 rounded-2xl p-4">
<div className="flex items-center gap-2 mb-2">
<BookOpen size={14} className="text-emerald-400" />
<span className="text-xs font-medium text-emerald-400">Daily Verse</span>
</div>
<p className="text-lg text-center font-arabic text-emerald-100 mb-2" dir="rtl">
{verse.arabic}
</p>
<p className="text-sm text-gray-400 text-center italic">
&ldquo;{verse.translation}&rdquo;
</p>
<p className="text-[10px] text-gray-600 text-center mt-1"> {verse.reference}</p>
</div>
{/* Quick Actions */}
<div className="px-4 mb-5">
<h2 className="text-xs font-semibold text-gray-500 uppercase tracking-wider mb-3">Quick Actions</h2>
<div className="grid grid-cols-4 gap-3">
<QuickAction href="/nur" icon={Bot} label="Nur AI" color="bg-amber-900/30 text-amber-300" />
<QuickAction href="/souq" icon={ShoppingBag} label="Souq" color="bg-[#D4AF37]/15 text-[#D4AF37]" />
<QuickAction href="/halal-monitor" icon={MapPin} label="Halal" color="bg-emerald-900/30 text-emerald-300" />
<QuickAction href="/wallet" icon={Wallet} label="Wallet" color="bg-blue-900/30 text-blue-300" />
</div>
</div>
{/* Stats Row */}
<div className="mx-4 mb-5">
<div className="grid grid-cols-3 gap-3">
<StatCard label="FLH Balance" value={user.flhBalance.toLocaleString()} icon={Zap} color="text-[#D4AF37]" />
<StatCard label="AI Today" value={`${user.dailyMsgCount}/10`} icon={Bot} color="text-amber-400" />
<StatCard label="Tier" value={isPro ? "Pro" : isPremium ? "Premium" : "Free"} icon={Crown}
color={isPro ? "text-purple-400" : isPremium ? "text-[#D4AF37]" : "text-gray-500"} />
</div>
</div>
{/* Activity Feed */}
<div className="px-4">
<div className="flex items-center justify-between mb-3">
<h2 className="text-xs font-semibold text-gray-500 uppercase tracking-wider">Activity</h2>
<Link href="/forum" className="text-[11px] text-[#D4AF37]">View all</Link>
2026-06-15 08:54:27 +02:00
</div>
<div className="bg-[#111118] border border-gray-800/60 rounded-2xl p-5 text-center">
<MessageCircle size={24} className="mx-auto text-gray-700 mb-2" />
<p className="text-sm text-gray-500">No recent activity</p>
<p className="text-xs text-gray-700 mt-1">Start a conversation with Nur AI</p>
2026-06-15 08:54:27 +02:00
</div>
</div>
{/* Premium upsell at bottom for free users */}
{!isPremium && (
<div className="mx-4 mt-5 bg-gradient-to-r from-[#D4AF37]/10 to-purple-900/10 border border-[#D4AF37]/20 rounded-2xl p-4">
<div className="flex items-start gap-3">
<div className="w-10 h-10 rounded-2xl bg-[#D4AF37]/15 flex items-center justify-center shrink-0">
<Star size={20} className="text-[#D4AF37]" />
</div>
<div className="flex-1">
<h3 className="font-semibold text-white text-sm">Unlock Your Full Potential</h3>
<p className="text-xs text-gray-500 mt-1">Premium gives you unlimited AI, halal monitor, and marketplace access.</p>
<Link href="/upgrade"
className="inline-block mt-3 text-xs font-semibold text-[#D4AF37] border border-[#D4AF37]/40 rounded-full px-4 py-1.5 active:bg-[#D4AF37]/10 transition">
See Plans
</Link>
</div>
</div>
</div>
)}
</div>
);
}
function QuickAction({ href, icon: Icon, label, color }: { href: string; icon: any; label: string; color: string }) {
return (
<Link href={href} className="flex flex-col items-center gap-1.5 active:scale-95 transition">
<div className={`w-14 h-14 rounded-2xl flex items-center justify-center ${color} bg-opacity-20`}>
<Icon size={22} />
</div>
<span className="text-[10px] text-gray-500 font-medium">{label}</span>
</Link>
);
}
function StatCard({ label, value, icon: Icon, color }: { label: string; value: string; icon: any; color: string }) {
return (
<div className="bg-[#111118] border border-gray-800/60 rounded-2xl p-3 text-center">
<Icon size={14} className={`mx-auto mb-1 ${color}`} />
<p className="text-sm font-bold text-white">{value}</p>
<p className="text-[9px] text-gray-600 mt-0.5">{label}</p>
</div>
);
}
function LoadingScreen() {
return (
<div className="min-h-dvh bg-[#0a0a0f] flex items-center justify-center">
<div className="w-8 h-8 rounded-full border-2 border-[#D4AF37]/30 border-t-[#D4AF37] animate-spin" />
2026-06-15 08:54:27 +02:00
</div>
);
}