"use client" import { useEffect, useState } from "react" import { useRouter } from "next/navigation" import { useSession } from "@/lib/auth-client" import { ProfileHeader } from "@/components/profile/profile-header" import { StatsRow } from "@/components/profile/stats-row" import { ContributionList } from "@/components/profile/contribution-list" import { SavedGamesGrid } from "@/components/saved-games/saved-games-grid" import { Bookmark, Settings, Loader2 } from "lucide-react" import { motion } from "motion/react" import type { ContributionEntry } from "@/types/api" type Tab = "overview" | "saved" | "settings" export default function ProfilePage() { const router = useRouter() const { data: session, isPending: isSessionLoading } = useSession() const [activeTab, setActiveTab] = useState("overview") const [profile, setProfile] = useState<{ id: string name: string email: string image: string | null role: string | null createdAt: string contributions: number verifiedEntries: number reputation: number verified: boolean } | null>(null) const [contributions, setContributions] = useState([]) const [isLoading, setIsLoading] = useState(true) useEffect(() => { if (!isSessionLoading && !session) { router.push("/login") } }, [session, isSessionLoading, router]) useEffect(() => { if (!session) return async function fetchProfile() { try { const [profileRes, contribRes] = await Promise.all([ fetch("/api/user/me"), fetch("/api/user/profile/" + session!.user.id + "/contributions?limit=10"), ]) if (profileRes.ok) { setProfile(await profileRes.json()) } if (contribRes.ok) { const data = await contribRes.json() setContributions(data.data) } } catch (err) { console.error("Failed to fetch profile:", err) } finally { setIsLoading(false) } } fetchProfile() }, [session]) if (isSessionLoading || isLoading) { return (
) } if (!session || !profile) { return null } const tabs: { id: Tab; label: string; icon: typeof Bookmark }[] = [ { id: "overview", label: "Overview", icon: Settings }, { id: "saved", label: "Saved Games", icon: Bookmark }, { id: "settings", label: "Settings", icon: Settings }, ] return (
{/* Profile header section */}
{/* Stats section */}
{/* Tabs + content section */}
{/* Tabs */}
{tabs.map((tab) => ( ))}
{/* Tab Content */} {activeTab === "overview" && (

Recent Contributions

)} {activeTab === "saved" && } {activeTab === "settings" && (

Account settings will appear here

)}
) }