'use client'; import { User, Users2, Info } from 'lucide-react'; import Input from '@/components/ui/Input'; import SegmentedControl from '@/components/ui/SegmentedControl'; import type { LeagueConfigFormModel } from '@gridpilot/racing/application'; interface LeagueStructureSectionProps { form: LeagueConfigFormModel; onChange?: (form: LeagueConfigFormModel) => void; readOnly?: boolean; } export function LeagueStructureSection({ form, onChange, readOnly, }: LeagueStructureSectionProps) { const disabled = readOnly || !onChange; const structure = form.structure; const updateStructure = ( patch: Partial, ) => { if (!onChange) return; const nextStructure = { ...structure, ...patch, }; let nextForm: LeagueConfigFormModel = { ...form, structure: nextStructure, }; if (nextStructure.mode === 'fixedTeams') { const maxTeams = typeof nextStructure.maxTeams === 'number' && nextStructure.maxTeams > 0 ? nextStructure.maxTeams : 1; const driversPerTeam = typeof nextStructure.driversPerTeam === 'number' && nextStructure.driversPerTeam > 0 ? nextStructure.driversPerTeam : 1; const maxDrivers = maxTeams * driversPerTeam; nextForm = { ...nextForm, structure: { ...nextStructure, maxTeams, driversPerTeam, maxDrivers, }, }; } if (nextStructure.mode === 'solo') { nextForm = { ...nextForm, structure: { ...nextStructure, maxTeams: undefined, driversPerTeam: undefined, }, }; } onChange(nextForm); }; const handleModeChange = (mode: 'solo' | 'fixedTeams') => { if (mode === structure.mode) return; if (mode === 'solo') { updateStructure({ mode: 'solo', maxDrivers: structure.maxDrivers || 24, maxTeams: undefined, driversPerTeam: undefined, }); } else { const maxTeams = structure.maxTeams ?? 12; const driversPerTeam = structure.driversPerTeam ?? 2; updateStructure({ mode: 'fixedTeams', maxTeams, driversPerTeam, maxDrivers: maxTeams * driversPerTeam, }); } }; const handleMaxDriversChange = (value: string) => { const parsed = parseInt(value, 10); updateStructure({ maxDrivers: Number.isNaN(parsed) ? 0 : parsed, }); }; const handleMaxTeamsChange = (value: string) => { const parsed = parseInt(value, 10); const maxTeams = Number.isNaN(parsed) ? 0 : parsed; const driversPerTeam = structure.driversPerTeam ?? 2; updateStructure({ maxTeams, driversPerTeam, maxDrivers: maxTeams > 0 && driversPerTeam > 0 ? maxTeams * driversPerTeam : structure.maxDrivers, }); }; const handleDriversPerTeamChange = (value: string) => { const parsed = parseInt(value, 10); const driversPerTeam = Number.isNaN(parsed) ? 0 : parsed; const maxTeams = structure.maxTeams ?? 12; updateStructure({ driversPerTeam, maxTeams, maxDrivers: maxTeams > 0 && driversPerTeam > 0 ? maxTeams * driversPerTeam : structure.maxDrivers, }); }; return (
{/* League structure selection */}
handleModeChange(mode as 'solo' | 'fixedTeams') } />
{/* Solo mode capacity */} {structure.mode === 'solo' && (

Driver capacity

Set the maximum number of drivers who can join your league

handleMaxDriversChange(e.target.value)} disabled={disabled} min={1} max={64} className="w-32" />

Typical club leagues use 20–30 drivers

)} {/* Teams mode capacity */} {structure.mode === 'fixedTeams' && (

Team structure

Configure the team composition and maximum grid size

Quick setup: Choose a common configuration

handleMaxTeamsChange(e.target.value)} disabled={disabled} min={1} max={32} className="w-32" />

Total competing teams

handleDriversPerTeamChange(e.target.value)} disabled={disabled} min={1} max={6} className="w-32" />

Common: 2–3 drivers

drivers

Auto-calculated from teams × drivers

)}
); }