'use client'; import React from 'react'; import { Breadcrumbs } from '@/ui/Breadcrumbs'; import { Button } from '@/ui/Button'; import { Card } from '@/ui/Card'; import { Box } from '@/ui/Box'; import { Stack } from '@/ui/Stack'; import { Text } from '@/ui/Text'; import { Heading } from '@/ui/Heading'; import { Container } from '@/ui/Container'; import { Grid } from '@/ui/Grid'; import { Icon } from '@/ui/Icon'; import { Surface } from '@/ui/Surface'; import { ArrowLeft, Trophy, Zap, type LucideIcon } from 'lucide-react'; import type { RaceResultsViewData } from '@/lib/view-data/races/RaceResultsViewData'; import { RaceResultRow } from '@/ui/RaceResultRow'; import { RacePenaltyRow } from '@/ui/RacePenaltyRowWrapper'; export interface RaceResultsTemplateProps { viewData: RaceResultsViewData; isAdmin: boolean; isLoading: boolean; error?: Error | null; // Actions onBack: () => void; onImportResults: (results: unknown[]) => 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({ viewData, isLoading, error, onBack, onImportResults, importing, importSuccess, importError, }: 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 breadcrumbItems = [ { label: 'Races', href: '/races' }, ...(viewData.leagueName ? [{ label: viewData.leagueName, href: `/leagues/${viewData.leagueName}` }] : []), ...(viewData.raceTrack ? [{ label: viewData.raceTrack, href: `/races/${viewData.raceTrack}` }] : []), { label: 'Results' }, ]; if (isLoading) { return ( Loading results... ); } if (error && !viewData.raceTrack) { return ( {error?.message || 'Race not found'} ); } const hasResults = viewData.results.length > 0; return ( {/* Header */} Race Results {viewData.raceTrack} • {viewData.raceScheduledAt ? formatDate(viewData.raceScheduledAt) : ''} {/* Stats */} {importSuccess && ( Success! Results imported and standings updated. )} {importError && ( Error: {importError} )} {hasResults ? ( {/* Results Table */} {viewData.results.map((result) => ( ))} {/* Penalties Section */} {viewData.penalties.length > 0 && ( Penalties {viewData.penalties.map((penalty, index) => ( ))} )} ) : ( 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. )} )} ); } function StatItem({ label, value, icon, color = 'text-white' }: { label: string, value: string | number, icon?: LucideIcon, color?: string }) { return ( {label} {icon && } {value} ); }