'use client'; import { useEffect, useState } from 'react'; import Link from 'next/link'; import { User, MapPin, Calendar, Heart, Gift, Settings, LogOut, ChevronRight } from 'lucide-react'; interface UserProfile { id: string; name: string; email: string; district: string; role: string; emailVerified: boolean; createdAt: string; _count: { reservations: number; donations: number }; } interface Reservation { id: string; date: string; status: string; animal: { name: string; species: string; photos: { url: string }[]; shelter: { name: string; district: string }; }; } export default function AccountPage() { const [user, setUser] = useState(null); const [reservations, setReservations] = useState([]); const [loading, setLoading] = useState(true); useEffect(() => { Promise.all([ fetch('/api/users/me').then(r => r.json()), fetch('/api/reservations').then(r => r.json()), ]) .then(([u, r]) => { setUser(u); setReservations(Array.isArray(r) ? r : []); }) .finally(() => setLoading(false)); }, []); const statusColor: Record = { PENDING: 'var(--amber)', CONFIRMED: 'var(--sage)', CANCELLED: 'var(--soil-faint)', COMPLETED: 'var(--sage)', }; const statusLabel: Record = { PENDING: 'Pendente', CONFIRMED: 'Confirmada', CANCELLED: 'Cancelada', COMPLETED: 'Concluída', }; if (loading) { return (
{[1,2,3].map(i => (
))}
); } if (!user) { return (

Precisas de estar autenticado para ver esta página.

Entrar
); } return (
{/* Header da conta */}

A tua conta

Olá, {user.name.split(' ')[0]}.

{/* Stats */}
{[ { icon: Heart, label: 'Reservas', value: user._count.reservations }, { icon: Gift, label: 'Doações', value: user._count.donations }, ].map(({ icon: Icon, label, value }) => (
{label}
{value}
))}
{/* Informação pessoal */}

Dados pessoais

{[ { icon: User, label: 'Nome', value: user.name }, { icon: Settings, label: 'Email', value: user.email }, { icon: MapPin, label: 'Distrito', value: user.district }, { icon: Calendar, label: 'Membro desde', value: new Date(user.createdAt).toLocaleDateString('pt-PT', { year: 'numeric', month: 'long' }) }, ].map(({ icon: Icon, label, value }) => (
{label}
{value}
))}
{/* Histórico de reservas */}

As tuas reservas

{reservations.length === 0 ? (
🐾

Ainda não tens reservas. Começa por explorar os animais disponíveis.

Explorar animais
) : (
{reservations.map((res) => (
{res.animal.photos[0] && ( {res.animal.name} )}
{res.animal.name}
{res.animal.shelter.name} · {new Date(res.date).toLocaleDateString('pt-PT', { day: 'numeric', month: 'long', year: 'numeric' })}
{statusLabel[res.status] ?? res.status}
))}
)}
{/* Logout */}
Terminar sessão
); }