'use client'; import { useState, useEffect } from 'react'; import Link from 'next/link'; import { useRouter, useParams } from 'next/navigation'; import { getDriverRepository } from '@/lib/di-container'; import DriverProfile from '@/components/drivers/DriverProfile'; import Button from '@/components/ui/Button'; import Card from '@/components/ui/Card'; import Breadcrumbs from '@/components/layout/Breadcrumbs'; import { EntityMappers } from '@gridpilot/racing/application/mappers/EntityMappers'; import type { DriverDTO } from '@gridpilot/racing/application/dto/DriverDTO'; export default function DriverDetailPage({ searchParams, }: { searchParams?: { [key: string]: string | string[] | undefined }; }) { const router = useRouter(); const params = useParams(); const driverId = params.id as string; const [driver, setDriver] = useState(null); const [loading, setLoading] = useState(true); const [error, setError] = useState(null); const from = typeof searchParams?.from === 'string' ? searchParams.from : undefined; const leagueId = typeof searchParams?.leagueId === 'string' ? searchParams.leagueId : undefined; const backLink = from === 'league' && leagueId ? `/leagues/${leagueId}` : null; useEffect(() => { loadDriver(); // eslint-disable-next-line react-hooks/exhaustive-deps }, [driverId]); const loadDriver = async () => { try { const driverRepo = getDriverRepository(); const driverEntity = await driverRepo.findById(driverId); if (!driverEntity) { setError('Driver not found'); setLoading(false); return; } const driverDto = EntityMappers.toDriverDTO(driverEntity); if (!driverDto) { setError('Driver not found'); setLoading(false); return; } setDriver(driverDto); } catch (err) { setError(err instanceof Error ? err.message : 'Failed to load driver'); } finally { setLoading(false); } }; if (loading) { return (
Loading driver profile...
); } if (error || !driver) { return (
{error || 'Driver not found'}
); } return (
{backLink && (
← Back to league
)} {/* Breadcrumb */} {/* Driver Profile Component */}
); }