'use client'; import React, { useState } from 'react'; import { useRouter } from 'next/navigation'; import Button from '@/components/ui/Button'; import { useServices } from '@/lib/services/ServiceProvider'; import { AlertTriangle, Clock, Flag, Zap } from 'lucide-react'; interface DriverOption { id: string; name: string; } interface QuickPenaltyModalProps { raceId?: string; drivers: DriverOption[]; onClose: () => 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 default function QuickPenaltyModal({ raceId, drivers, onClose, 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 [loading, setLoading] = useState(false); const [error, setError] = useState(null); const router = useRouter(); const { penaltyService } = useServices(); const handleSubmit = async (e: React.FormEvent) => { e.preventDefault(); if (!selectedRaceId || !selectedDriver || !infractionType || !severity) return; setLoading(true); setError(null); try { const command: any = { raceId: selectedRaceId, driverId: selectedDriver, adminId, infractionType: infractionType as any, severity: severity as any, }; if (notes.trim()) { command.notes = notes.trim(); } await penaltyService.applyPenalty(command); // Refresh the page to show updated results router.refresh(); onClose(); } catch (err) { setError(err instanceof Error ? err.message : 'Failed to apply penalty'); } finally { setLoading(false); } }; return (

Quick Penalty

{/* Race Selection */} {races && !raceId && (
)} {/* Driver Selection */}
{preSelectedDriver ? (
{preSelectedDriver.name}
) : ( )}
{/* Infraction Type */}
{INFRACTION_TYPES.map(({ value, label, icon: Icon }) => ( ))}
{/* Severity */}
{SEVERITY_LEVELS.map(({ value, label, description }) => ( ))}
{/* Notes */}