"use client" import { useEffect, useState } from "react" import { Button } from "@/components/ui/button" import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card" import { Trophy, Calendar, User, ArrowLeft } from "lucide-react" import Link from "next/link" import { BadgeList } from "@/components/profile/badge-list" import { getApiUrl } from "@/lib/api-config" import { Tabs, TabsContent, TabsList, TabsTrigger } from "@/components/ui/tabs" import { UserAttendanceList } from "@/components/profile/user-attendance-list" import { UserReviewsList } from "@/components/profile/user-reviews-list" import { UserGroupsList } from "@/components/profile/user-groups-list" import { Avatar, AvatarFallback, AvatarImage } from "@/components/ui/avatar" import { notFound } from "next/navigation" interface UserProfile { id: number email: string username: string | null bio: string | null created_at: string } interface UserBadge { id: number badge: { id: number name: string description: string icon: string slug: string } awarded_at: string } export default function PublicProfilePage({ params }: { params: Promise<{ slug: string }> }) { const [id, setId] = useState(null) const [user, setUser] = useState(null) const [badges, setBadges] = useState([]) const [loading, setLoading] = useState(true) const [error, setError] = useState(false) const [stats, setStats] = useState({ attendance_count: 0, review_count: 0, group_count: 0 }) useEffect(() => { params.then(p => setId(p.slug)) }, [params]) useEffect(() => { if (!id) return const fetchData = async () => { try { // Public fetch - no auth header needed strictly, but maybe good practice if protected const token = localStorage.getItem("token") const headers: Record = token ? { Authorization: `Bearer ${token}` } : {} const userRes = await fetch(`${getApiUrl()}/users/${id}`, { headers }) if (!userRes.ok) throw new Error("User not found") const userData = await userRes.json() setUser(userData) // Fetch Stats const statsRes = await fetch(`${getApiUrl()}/users/${id}/stats`, { headers }) if (statsRes.ok) setStats(await statsRes.json()) // Fetch Badges // Check if badges endpoint exists for specific user, otherwise /badges/me is for me. // Assuming we default to empty badges for public profile if no specific endpoint // Actually, let's skip badges for now or try specific endpoint if it existed. // Assuming no public badges endpoint yet. setBadges([]) } catch (e) { console.error(e) setError(true) } finally { setLoading(false) } } fetchData() }, [id]) if (loading) return
Loading profile...
if (error || !user) return
User not found
const displayName = user.username || user.email.split('@')[0] return (

{displayName}

Member since {new Date(user.created_at).toLocaleDateString()}

{user.bio && (

{user.bio}

)}
{stats.attendance_count} Shows
{stats.review_count} Reviews
{stats.group_count} Groups
Attendance Reviews Communities
) }