import { LOCALES, getLocale, initializeLocale, setLocale, t, translateDocument } from './i18n.mjs'; import { mountAccountControl } from '../features/account/ui/account-control.mjs'; const storageKey = 'algofish.theme'; function storedTheme() { try { const value = localStorage.getItem(storageKey); return value === 'light' || value === 'dark' ? value : null; } catch { return null; } } function preferredTheme() { return storedTheme() ?? 'light'; } function applyTheme(theme, persist = false) { document.documentElement.dataset.theme = theme; document.querySelector('meta[name="theme-color"]')?.setAttribute('content', theme === 'light' ? '#edf7fb' : '#061521'); for (const button of document.querySelectorAll('[data-theme-toggle]')) { const nextKey = theme === 'light' ? 'Dark' : 'Light'; button.textContent = t(`theme.${nextKey.toLowerCase()}`); button.setAttribute('aria-label', t(`theme.enable${nextKey}`)); } if (persist) { try { localStorage.setItem(storageKey, theme); } catch { /* stockage facultatif */ } } window.dispatchEvent(new CustomEvent('algofish:themechange', { detail: { theme } })); } const page = document.body.dataset.page; for (const nav of document.querySelectorAll('.site-nav')) { for (const item of [{id:'meteo',fr:'Météo',en:'Weather'},{id:'records',fr:'Mes records',en:'My records'},{id:'spots',fr:'Mes spots',en:'My spots'},{id:'sorties',fr:'Mes sorties',en:'My outings'}]) { if(nav.querySelector('[data-nav="'+item.id+'"]'))continue; const link=document.createElement('a');link.href=new URL('../'+item.id+'/',import.meta.url).href;link.dataset.nav=item.id; const label=()=>{link.textContent=getLocale()==='en'?item.en:item.fr;};label(); window.addEventListener('algofish:localechange',label);nav.append(link); } } document.querySelector(`[data-nav="${page}"]`)?.setAttribute('aria-current', 'page'); for (const select of document.querySelectorAll('[data-language-select]')) { select.innerHTML = Object.entries(LOCALES).map(([code, locale]) => ``).join(''); select.addEventListener('change', () => setLocale(select.value)); } initializeLocale(); translateDocument(); applyTheme(preferredTheme()); mountAccountControl(); for (const button of document.querySelectorAll('[data-theme-toggle]')) { button.addEventListener('click', () => { applyTheme(document.documentElement.dataset.theme === 'light' ? 'dark' : 'light', true); }); } window.addEventListener('algofish:localechange', () => applyTheme(document.documentElement.dataset.theme ?? preferredTheme())); export { applyTheme, getLocale, setLocale }; const photoFooter=document.createElement('footer');photoFooter.className='site-photo-footer'; const photoCredit=document.createElement('a');photoCredit.href=new URL('../credits-photos/',import.meta.url).href; const creditLabel=()=>{photoCredit.textContent=getLocale()==='en'?'Photography credits':'Crédits photographiques';};creditLabel(); window.addEventListener('algofish:localechange',creditLabel);photoFooter.append(photoCredit);document.body.append(photoFooter);