// Top navigation behaviors: logout + theme toggle (persisted to // localStorage immediately and to the profile when logged in). import { api, toast } from '/static/js/api.js'; const logoutBtn = document.getElementById('nav-logout'); if (logoutBtn) { logoutBtn.addEventListener('click', async () => { try { await api('POST', '/api/v1/auth/logout', {}); } catch (e) { /* session may already be gone */ } window.location.href = '/login'; }); } const themeBtn = document.getElementById('nav-theme'); if (themeBtn) { themeBtn.addEventListener('click', async () => { const el = document.documentElement; const next = el.dataset.theme === 'dark' ? 'light' : 'dark'; el.dataset.theme = next; try { localStorage.setItem('theme', next); } catch (e) { /* ignore */ } if (document.body.dataset.loggedIn === '1') { try { await api('PATCH', '/api/v1/profile', { settings: { theme: next } }); } catch (e) { toast('Could not save theme preference: ' + e.message, 'err'); } } }); }