// Dual-mode track config modal // Browse mode (no onSelect): read-only info table // Picker mode (onSelect provided): clickable rows for selection App.TrackConfigModal = function TrackConfigModal({ track, configs: configsProp, onSelect, onClose }) { const [configs, setConfigs] = React.useState(configsProp || null); const [loading, setLoading] = React.useState(!configsProp); React.useEffect(() => { if (!configsProp && track) { setLoading(true); App.API.get('track-configs?track_id=' + track.id).then(data => { setConfigs(data); setLoading(false); }); } }, [track, configsProp]); if (!track) return null; const pickerMode = typeof onSelect === 'function'; const handleRowClick = (cfg) => { if (pickerMode) { onSelect({ id: cfg.id, trackId: cfg.track_id, trackName: track.name, configName: cfg.config_name, }); onClose(); } }; return (
{pickerMode ? 'Select a configuration' : 'Track Configurations'}
{loading &&No configurations found.
)} {!loading && configs && configs.length > 0 && (| Configuration | Type | Length (mi) | Turns | Night | Free |
|---|---|---|---|---|---|
| {cfg.config_name || 'Base'} | {cfg.track_type_name || '-'} | {cfg.length_miles ? Number(cfg.length_miles).toFixed(2) : '-'} | {cfg.turns || '-'} | {cfg.has_night == 1 ? 'Yes' : 'No'} | {cfg.is_free == 1 ? 'Yes' : 'No'} |