import React, { useMemo } from 'react'; import { AreaChart, Area, XAxis, YAxis, CartesianGrid, ResponsiveContainer } from 'recharts'; import type { DriverPrediction, Driver, RacePhase } from '../types'; interface PositionChangePanelProps { driver: Driver | null; prediction: DriverPrediction | null; racePhase: RacePhase; } export const PositionChangePanel: React.FC = ({ driver, prediction, racePhase }) => { const chartData = useMemo(() => { if (!prediction || !prediction.positionHistory || prediction.positionHistory.length === 0) { return []; } return prediction.positionHistory.map((pos, idx) => ({ lap: idx + 1, position: pos })); }, [prediction]); const renderBadge = () => { if (racePhase === 'finished') { return (
Finished
); } return (
Live
); }; const CustomDot = (props: any) => { const { cx, cy, payload, index } = props; const isFirst = index === 0; const isLast = index === chartData.length - 1; if (isFirst || isLast) { return ( P{payload.position} ); } return ; }; return (

Position Change

{driver && (
{driver.lastName}
)}
{racePhase !== 'pre-race' && renderBadge()}
{racePhase === 'pre-race' ? (
⏱ Chart will build when race starts
) : chartData.length === 0 ? (
Waiting for first lap...
) : ( } isAnimationActive={false} /> )}
); };