'use client'; import { usePenaltyMutation } from "@/hooks/league/usePenaltyMutation"; import { Button } from '@/ui/Button'; import { Heading } from '@/ui/Heading'; import { Icon } from '@/ui/Icon'; import { Stack } from '@/ui/Stack'; import { Select } from '@/ui/Select'; import { Text } from '@/ui/Text'; import { TextArea } from '@/ui/TextArea'; import { AlertTriangle, Clock, Flag, Zap } from 'lucide-react'; import { useState } from 'react'; interface DriverOption { id: string; name: string; } interface QuickPenaltyModalProps { raceId?: string; drivers: DriverOption[]; onClose: () => void; onRefresh?: () => void; preSelectedDriver?: DriverOption; adminId: string; races?: { id: string; track: string; scheduledAt: Date }[]; } const INFRACTION_TYPES = [ { value: 'track_limits', label: 'Track Limits', icon: Flag }, { value: 'unsafe_rejoin', label: 'Unsafe Rejoin', icon: AlertTriangle }, { value: 'aggressive_driving', label: 'Aggressive Driving', icon: Zap }, { value: 'false_start', label: 'False Start', icon: Clock }, { value: 'other', label: 'Other', icon: AlertTriangle }, ] as const; const SEVERITY_LEVELS = [ { value: 'warning', label: 'Warning', description: 'Official warning only' }, { value: 'minor', label: 'Minor', description: 'Light penalty' }, { value: 'major', label: 'Major', description: 'Significant penalty' }, { value: 'severe', label: 'Severe', description: 'Heavy penalty' }, ] as const; export function QuickPenaltyModal({ raceId, drivers, onClose, onRefresh, preSelectedDriver, adminId, races }: QuickPenaltyModalProps) { const [selectedRaceId, setSelectedRaceId] = useState(raceId || ''); const [selectedDriver, setSelectedDriver] = useState(preSelectedDriver?.id || ''); const [infractionType, setInfractionType] = useState(''); const [severity, setSeverity] = useState(''); const [notes, setNotes] = useState(''); const [error, setError] = useState(null); const penaltyMutation = usePenaltyMutation(); const handleSubmit = async (e: React.FormEvent) => { e.preventDefault(); if (!selectedRaceId || !selectedDriver || !infractionType || !severity) return; setError(null); try { const command = { raceId: selectedRaceId, driverId: selectedDriver, stewardId: adminId, type: infractionType, reason: severity, notes: notes.trim() || undefined, }; await penaltyMutation.mutateAsync(command); // Refresh the page to show updated results onRefresh?.(); onClose(); } catch (err) { setError(err instanceof Error ? err.message : 'Failed to apply penalty'); } }; return ( Quick Penalty {/* Race Selection */} {races && !raceId && ( Race setSelectedDriver(e.target.value)} required options={[ { value: '', label: 'Select driver...' }, ...drivers.map((driver) => ({ value: driver.id, label: driver.name, })), ]} /> )} {/* Infraction Type */} Infraction Type {INFRACTION_TYPES.map(({ value, label, icon: InfractionIcon }) => ( setInfractionType(value)} display="flex" alignItems="center" gap={2} p={3} rounded="lg" border transition borderColor={infractionType === value ? 'border-primary-blue' : 'border-charcoal-outline'} bg={infractionType === value ? 'bg-primary-blue/10' : 'bg-deep-graphite'} color={infractionType === value ? 'text-primary-blue' : 'text-gray-300'} hoverBorderColor={infractionType !== value ? 'border-gray-500' : undefined} > {label} ))} {/* Severity */} Severity {SEVERITY_LEVELS.map(({ value, label, description }) => ( setSeverity(value)} w="full" textAlign="left" p={3} rounded="lg" border transition borderColor={severity === value ? 'border-primary-blue' : 'border-charcoal-outline'} bg={severity === value ? 'bg-primary-blue/10' : 'bg-deep-graphite'} color={severity === value ? 'text-primary-blue' : 'text-gray-300'} hoverBorderColor={severity !== value ? 'border-gray-500' : undefined} > {label} {description} ))} {/* Notes */} Notes (Optional)