/* Voyage Assistant — main app shell. Gère le routing, le theme, l'auth (useAuth) et l'AuthModal global. */ const ROUTES = ['home', 'results', 'booking', 'confirm', 'mes-billets', 'assistant']; const useTheme = () => { const [mode, setMode] = React.useState(() => { try { return localStorage.getItem('va.theme') || 'light'; } catch { return 'light'; } }); React.useEffect(() => { try { localStorage.setItem('va.theme', mode); } catch {} }, [mode]); const resolved = mode === 'system' ? (window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches ? 'dark' : 'light') : mode; return { mode, setMode, resolved }; }; const useRoute = () => { const [route, setRouteRaw] = React.useState(() => { try { return localStorage.getItem('va.route') || 'home'; } catch { return 'home'; } }); const [ctx, setCtx] = React.useState(() => { try { return JSON.parse(localStorage.getItem('va.ctx') || '{}'); } catch { return {}; } }); const go = React.useCallback((next, nextCtx) => { if (!ROUTES.includes(next)) next = 'home'; setRouteRaw(next); if (nextCtx) setCtx((c) => ({ ...c, ...nextCtx })); try { localStorage.setItem('va.route', next); if (nextCtx) localStorage.setItem('va.ctx', JSON.stringify({ ...ctx, ...nextCtx })); } catch {} requestAnimationFrame(() => { const sc = document.querySelector('.va-app__main'); if (sc) sc.scrollTo(0, 0); }); }, [ctx]); return { route, ctx, go }; }; const UserChip = ({ user, onLogout, onGo }) => { const [open, setOpen] = React.useState(false); const initials = ((user.prenom || '')[0] || '') + ((user.nom || '')[0] || ''); return (