'use client';
import React from 'react';
import Breadcrumbs from '@/components/layout/Breadcrumbs';
import { Button } from '@/ui/Button';
import { Box } from '@/ui/Box';
import { Stack } from '@/ui/Stack';
import { Text } from '@/ui/Text';
import { Container } from '@/ui/Container';
import { Icon } from '@/ui/Icon';
import { Grid } from '@/ui/Grid';
import { GridItem } from '@/ui/GridItem';
import { Skeleton } from '@/ui/Skeleton';
import { InfoBox } from '@/ui/InfoBox';
import { RaceJoinButton } from '@/components/races/RaceJoinButton';
import { RaceHero } from '@/components/races/RaceHero';
import { RaceUserResult } from '@/components/races/RaceUserResult';
import { RaceEntryList } from '@/components/races/RaceEntryList';
import { RaceDetailCard } from '@/components/races/RaceDetailCard';
import { LeagueSummaryCard } from '@/components/leagues/LeagueSummaryCard';
import {
AlertTriangle,
ArrowLeft,
CheckCircle2,
Clock,
PlayCircle,
Trophy,
XCircle,
Scale,
} from 'lucide-react';
import { Surface } from '@/ui/Surface';
import { Card } from '@/ui/Card';
export interface RaceDetailEntryViewModel {
id: string;
name: string;
avatarUrl: string;
country: string;
rating?: number | null;
isCurrentUser: boolean;
}
export interface RaceDetailUserResultViewModel {
position: number;
startPosition: number;
positionChange: number;
incidents: number;
isClean: boolean;
isPodium: boolean;
ratingChange?: number;
}
export interface RaceDetailLeague {
id: string;
name: string;
description?: string;
settings: {
maxDrivers: number;
qualifyingFormat: string;
};
}
export interface RaceDetailRace {
id: string;
track: string;
car: string;
scheduledAt: string;
status: 'scheduled' | 'running' | 'completed' | 'cancelled';
sessionType: string;
}
export interface RaceDetailRegistration {
isUserRegistered: boolean;
canRegister: boolean;
}
export interface RaceDetailViewData {
race: RaceDetailRace;
league?: RaceDetailLeague;
entryList: RaceDetailEntryViewModel[];
registration: RaceDetailRegistration;
userResult?: RaceDetailUserResultViewModel;
canReopenRace: boolean;
}
export interface RaceDetailTemplateProps {
viewData?: RaceDetailViewData;
isLoading: boolean;
error?: Error | null;
// Actions
onBack: () => void;
onRegister: () => void;
onWithdraw: () => void;
onCancel: () => void;
onReopen: () => void;
onEndRace: () => void;
onFileProtest: () => void;
onResultsClick: () => void;
onStewardingClick: () => void;
onLeagueClick: (leagueId: string) => void;
onDriverClick: (driverId: string) => void;
// User state
currentDriverId?: string;
isOwnerOrAdmin?: boolean;
// UI State
animatedRatingChange: number;
// Loading states
mutationLoading?: {
register?: boolean;
withdraw?: boolean;
cancel?: boolean;
reopen?: boolean;
complete?: boolean;
};
}
export function RaceDetailTemplate({
viewData,
isLoading,
error,
onBack,
onRegister,
onWithdraw,
onCancel,
onReopen,
onEndRace,
onFileProtest,
onResultsClick,
onStewardingClick,
onDriverClick,
isOwnerOrAdmin = false,
animatedRatingChange,
mutationLoading = {},
}: RaceDetailTemplateProps) {
if (isLoading) {
return (
);
}
if (error || !viewData || !viewData.race) {
return (
{error instanceof Error ? error.message : error || 'Race not found'}
The race you're looking for doesn't exist or has been removed.
);
}
const { race, league, entryList, userResult } = viewData;
const statusConfig = {
scheduled: {
icon: Clock,
variant: 'primary' as const,
label: 'Scheduled',
description: 'This race is scheduled and waiting to start',
},
running: {
icon: PlayCircle,
variant: 'success' as const,
label: 'LIVE NOW',
description: 'This race is currently in progress',
},
completed: {
icon: CheckCircle2,
variant: 'default' as const,
label: 'Completed',
description: 'This race has finished',
},
cancelled: {
icon: XCircle,
variant: 'warning' as const,
label: 'Cancelled',
description: 'This race has been cancelled',
},
};
const config = statusConfig[race.status] || statusConfig.scheduled;
const breadcrumbItems = [
{ label: 'Races', href: '/races' },
...(league ? [{ label: league.name, href: `/leagues/${league.id}` }] : []),
{ label: race.track },
];
return (
{/* Navigation Row */}
}
>
Back
{/* User Result */}
{userResult && (
)}
{/* Hero Header */}
{league && }
{/* Actions Card */}
Actions
{race.status === 'completed' && (
<>
}>
View Results
{userResult && (
}>
File Protest
)}
}>
Stewarding
>
)}
{/* Status Info */}
);
}