import { csrfToken } from '@/lib/utils'; import { type SharedData } from '@/types'; import { router, usePage } from '@inertiajs/react'; import { useState } from 'react'; type SaveStatus = 'idle' | 'saving' | 'success' | 'error'; type DistributionMode = 'even' | 'priority'; interface DistributionOption { value: DistributionMode; label: string; description: string; } const distributionOptions: DistributionOption[] = [ { value: 'even', label: 'EVEN SPLIT', description: 'Split evenly across buckets in each phase, respecting individual capacity', }, { value: 'priority', label: 'PRIORITY ORDER', description: 'Fill highest-priority bucket first, then next', }, ]; interface SettingsPanelProps { onOpenChange: (open: boolean) => void; } export default function SettingsPanel({ onOpenChange, }: SettingsPanelProps) { const { scenario } = usePage().props; const [saveStatus, setSaveStatus] = useState('idle'); if (!scenario) return null; const handleDistributionModeChange = async (value: DistributionMode) => { if (value === scenario.distribution_mode) return; setSaveStatus('saving'); try { const response = await fetch(`/scenarios/${scenario.id}`, { method: 'PATCH', headers: { 'Content-Type': 'application/json', 'X-CSRF-TOKEN': csrfToken(), }, body: JSON.stringify({ distribution_mode: value }), }); if (!response.ok) throw new Error('Failed to update'); setSaveStatus('success'); router.reload({ only: ['scenario', 'buckets'] }); setTimeout(() => setSaveStatus('idle'), 1500); } catch { setSaveStatus('error'); setTimeout(() => setSaveStatus('idle'), 1500); } }; return (

SETTINGS

DISTRIBUTION MODE {saveStatus === 'success' && ( SAVED )} {saveStatus === 'error' && ( FAILED )}
{distributionOptions.map((option) => ( ))}
); }