'use client'; import Breadcrumbs from '@/components/layout/Breadcrumbs'; import Button from '@/components/ui/Button'; import Card from '@/components/ui/Card'; import { ArrowLeft, Calendar, Trophy, Users, Zap } from 'lucide-react'; export interface ResultEntry { position: number; driverId: string; driverName: string; driverAvatar: string; country: string; car: string; laps: number; time: string; fastestLap: string; points: number; incidents: number; isCurrentUser: boolean; } export interface PenaltyEntry { driverId: string; driverName: string; type: 'time_penalty' | 'grid_penalty' | 'points_deduction' | 'disqualification' | 'warning' | 'license_points'; value: number; reason: string; notes?: string; } export interface RaceResultsTemplateProps { raceTrack?: string; raceScheduledAt?: string; totalDrivers?: number; leagueName?: string; raceSOF?: number | null; results: ResultEntry[]; penalties: PenaltyEntry[]; pointsSystem: Record; fastestLapTime: number; currentDriverId: string; isAdmin: boolean; isLoading: boolean; error?: Error | null; // Actions onBack: () => void; onImportResults: (results: any[]) => void; onPenaltyClick: (driver: { id: string; name: string }) => void; // UI State importing: boolean; importSuccess: boolean; importError: string | null; showImportForm: boolean; setShowImportForm: (show: boolean) => void; } export function RaceResultsTemplate({ raceTrack, raceScheduledAt, totalDrivers, leagueName, raceSOF, results, penalties, pointsSystem, fastestLapTime, currentDriverId, isAdmin, isLoading, error, onBack, onImportResults, onPenaltyClick, importing, importSuccess, importError, showImportForm, setShowImportForm, }: RaceResultsTemplateProps) { const formatDate = (date: string) => { return new Date(date).toLocaleDateString('en-US', { weekday: 'long', month: 'long', day: 'numeric', year: 'numeric', }); }; const formatTime = (ms: number) => { const minutes = Math.floor(ms / 60000); const seconds = Math.floor((ms % 60000) / 1000); const milliseconds = Math.floor((ms % 1000) / 10); return `${minutes}:${seconds.toString().padStart(2, '0')}.${milliseconds.toString().padStart(2, '0')}`; }; const getCountryFlag = (countryCode: string): string => { const codePoints = countryCode .toUpperCase() .split('') .map(char => 127397 + char.charCodeAt(0)); return String.fromCodePoint(...codePoints); }; const breadcrumbItems = [ { label: 'Races', href: '/races' }, ...(leagueName ? [{ label: leagueName, href: `/leagues/${leagueName}` }] : []), ...(raceTrack ? [{ label: raceTrack, href: `/races/${raceTrack}` }] : []), { label: 'Results' }, ]; if (isLoading) { return (
Loading results...
); } if (error && !raceTrack) { return (
{error?.message || 'Race not found'}
); } const hasResults = results.length > 0; return (
{/* Header */}

Race Results

{raceTrack} • {raceScheduledAt ? formatDate(raceScheduledAt) : ''}

{/* Stats */}

Drivers

{totalDrivers ?? 0}

League

{leagueName ?? '—'}

SOF

{raceSOF ?? '—'}

Fastest Lap

{fastestLapTime ? formatTime(fastestLapTime) : '—'}

{importSuccess && (
Success! Results imported and standings updated.
)} {importError && (
Error: {importError}
)} {hasResults ? (
{/* Results Table */}
{results.map((result) => { const isCurrentUser = result.driverId === currentDriverId; const countryFlag = getCountryFlag(result.country); const points = pointsSystem[result.position.toString()] ?? 0; return (
{/* Position */}
{result.position}
{/* Avatar */}
{result.driverName}
{countryFlag}
{/* Driver Info */}

{result.driverName}

{isCurrentUser && ( You )}
{result.car} Laps: {result.laps} Incidents: {result.incidents}
{/* Times */}

{result.time}

FL: {result.fastestLap}

{/* Points */}
PTS {points}
); })}
{/* Penalties Section */} {penalties.length > 0 && (

Penalties

{penalties.map((penalty, index) => (
!
{penalty.driverName} {penalty.type.replace('_', ' ')}

{penalty.reason}

{penalty.notes && (

{penalty.notes}

)}
{penalty.type === 'time_penalty' && `+${penalty.value}s`} {penalty.type === 'grid_penalty' && `+${penalty.value} grid`} {penalty.type === 'points_deduction' && `-${penalty.value} pts`} {penalty.type === 'disqualification' && 'DSQ'} {penalty.type === 'warning' && 'Warning'} {penalty.type === 'license_points' && `${penalty.value} LP`}
))}
)}
) : ( <>

Import Results

No results imported. Upload CSV to test the standings system.

{importing ? (
Importing results and updating standings...
) : (

This is a placeholder for the import form. In the actual implementation, this would render the ImportResultsForm component.

)} )}
); }