import { useEffect, useState } from 'react'; import { Radio } from 'lucide-react'; import { Button } from '@/components/ui/button'; import { Input } from '@/components/ui/input'; import { Label } from '@/components/ui/label'; import { cn } from '@/lib/utils'; import { useI18n, FlagGB, FlagFR, type Lang } from '@/lib/i18n'; import { GetActiveProfile, SaveProfile, DownloadAllReferenceLists } from '../../wailsjs/go/main/App'; import type { profile as profileModels } from '../../wailsjs/go/models'; type Profile = Omit; // FirstRunModal collects the mandatory station identity on the very first launch // (no callsign configured yet). It writes straight into the active profile, so // OpsLog has a valid station before any QSO is logged. Not dismissable. export function FirstRunModal({ onDone }: { onDone: () => void }) { const { t, lang, setLang } = useI18n(); const [p, setP] = useState(null); const [saving, setSaving] = useState(false); const [err, setErr] = useState(''); const [refsState, setRefsState] = useState<'idle' | 'loading' | 'done'>('idle'); const [refsMsg, setRefsMsg] = useState(''); async function downloadRefs() { setRefsState('loading'); try { const summary = await DownloadAllReferenceLists(); setRefsMsg(summary); setRefsState('done'); } catch (e: any) { setRefsMsg(String(e?.message ?? e)); setRefsState('idle'); } } useEffect(() => { GetActiveProfile().then((x) => setP(x as Profile)).catch(() => setP({} as Profile)); }, []); const set = (patch: Partial) => setP((s: Profile | null) => ({ ...(s as Profile), ...patch })); const callsign = (p?.callsign ?? '').trim().toUpperCase(); const grid = (p?.my_grid ?? '').trim().toUpperCase(); const operator = (p?.operator ?? '').trim().toUpperCase(); const canSave = callsign.length >= 3 && grid.length >= 4; async function save() { if (!p || !canSave) return; setSaving(true); setErr(''); try { await SaveProfile({ ...p, callsign, my_grid: grid, operator: operator || callsign, owner_callsign: (p.owner_callsign ?? '').trim().toUpperCase() || callsign, op_name: (p.op_name ?? '').trim(), } as any); onDone(); } catch (e: any) { setErr(String(e?.message ?? e)); } finally { setSaving(false); } } return (
{/* Language chooser — lives here (and not only in the localStorage-backed first-launch flag gate) so a fresh setup always offers EN/FR, like the station identity below. */}
{([['en', FlagGB, 'English'], ['fr', FlagFR, 'Français']] as [Lang, typeof FlagGB, string][]).map(([code, Flag, label]) => ( ))}

{t('frm.welcome')}

{t('frm.intro')}

set({ callsign: e.target.value })} /> set({ my_grid: e.target.value })} /> set({ operator: e.target.value })} /> set({ owner_callsign: e.target.value })} /> set({ op_name: e.target.value })} />
{/* Optional: grab the award reference lists now (also in Tools later). */}
{t('frm.awardRefs')}
{t('frm.awardRefsHint')}
{refsMsg &&
{refsMsg}
}
{err &&
{err}
}
{!canSave && {t('frm.required')}}
); }