'use client'; import { Result } from '../../domain/entities/Result'; import { Driver } from '../../domain/entities/Driver'; interface ResultsTableProps { results: Result[]; drivers: Driver[]; pointsSystem: Record; fastestLapTime?: number; } export default function ResultsTable({ results, drivers, pointsSystem, fastestLapTime }: ResultsTableProps) { const getDriverName = (driverId: string): string => { const driver = drivers.find(d => d.id === driverId); return driver?.name || 'Unknown Driver'; }; const formatLapTime = (seconds: number): string => { const minutes = Math.floor(seconds / 60); const secs = (seconds % 60).toFixed(3); return `${minutes}:${secs.padStart(6, '0')}`; }; const getPoints = (position: number): number => { return pointsSystem[position] || 0; }; const getPositionChangeColor = (change: number): string => { if (change > 0) return 'text-performance-green'; if (change < 0) return 'text-warning-amber'; return 'text-gray-500'; }; const getPositionChangeText = (change: number): string => { if (change > 0) return `+${change}`; if (change < 0) return `${change}`; return '0'; }; if (results.length === 0) { return (
No results available
); } return (
{results.map((result) => { const positionChange = result.getPositionChange(); const isFastestLap = fastestLapTime && result.fastestLap === fastestLapTime; return ( ); })}
Pos Driver Fastest Lap Incidents Points +/-
{result.position} {getDriverName(result.driverId)} {formatLapTime(result.fastestLap)} 0 ? 'text-warning-amber' : 'text-white'}> {result.incidents}× {getPoints(result.position)} {getPositionChangeText(positionChange)}
); }