// app/events/[id]/page.tsx // Event detail page with registration form import { query } from '@/lib/db'; import { Event, EventRegistration } from '@/types/racing'; import { notFound } from 'next/navigation'; import { TrophyIcon, MapPinIcon, UsersIcon, ClockIcon, CalendarIcon } from '@/components/ui/icons'; import EventRegistrationForm from '@/components/events/EventRegistrationForm'; async function getEvent(eventId: number): Promise { const sql = ` SELECT e.*, COUNT(er.registration_id) as registrations_count FROM events e LEFT JOIN event_registrations er ON e.event_id = er.event_id AND er.status = 'REGISTERED' WHERE e.event_id = $1 GROUP BY e.event_id `; const rows = await query(sql, [eventId]); return rows.length > 0 ? rows[0] as Event : null; } async function getEventRegistrations(eventId: number): Promise { const sql = ` SELECT er.*, u.driver_name FROM event_registrations er JOIN users u ON er.driver_guid = u.driver_guid WHERE er.event_id = $1 AND er.status = 'REGISTERED' ORDER BY er.registration_date ASC `; const rows = await query(sql, [eventId]); return rows as EventRegistration[]; } function formatDate(date: Date): string { return new Date(date).toLocaleDateString('en-US', { weekday: 'long', year: 'numeric', month: 'long', day: 'numeric', hour: '2-digit', minute: '2-digit' }); } export default async function EventDetailPage({ params, }: { params: Promise<{ id: string }>; }) { const { event_id } = await params; const eventId = parseInt(event_id, 10); const event: any = await getEvent(eventId); if (!event) { notFound(); } const registrations = await getEventRegistrations(eventId); const isOpen = event.event_status === 'OPEN'; const isFull = event.registrations_count >= event.max_participants; const deadlinePassed = event.registration_deadline && new Date(event.registration_deadline) < new Date(); const canRegister = isOpen && !isFull && !deadlinePassed; return ( <> {/* Hero */}
EVENT DETAILS

{event.event_name}

{event.event_description}

{/* Event Info Cards */}
} /> } /> } /> } />
{/* Main Content */}
{/* Left Column - Registration */}
{/* Registration Form */} {canRegister ? (

REGISTER FOR EVENT

) : (

REGISTRATION CLOSED

{isFull && 'This event is full.'} {deadlinePassed && !isFull && 'Registration deadline has passed.'} {event.event_status === 'CLOSED' && !isFull && !deadlinePassed && 'Registration is closed for this event.'}

)} {/* Event Rules */} {event.event_rules && (

EVENT RULES

{event.event_rules}
)}
{/* Right Column - Registered Participants */}

REGISTERED DRIVERS ({event.registrations_count})

{registrations.length === 0 ? (

No registrations yet

) : ( registrations.map((reg: any, index: number) => (
#{String(index + 1).padStart(2, '0')} {reg.driver_name}
Car: {reg.car_model}
{reg.car_skin &&
Skin: {reg.car_skin}
} {reg.team_name &&
Team: {reg.team_name}
}
)) )}
); } function InfoCard({ label, value, icon }: { label: string; value: string; icon: React.ReactNode; }) { return (
{label}
{icon}
{value}
); }