import { useState, useEffect } from 'react' import { setLocale, getLocale, type Locale } from '@/lib/i18n' import { t } from '@/lib/i18n' const LOCALE_STORAGE_KEY = 'zapwall-locale' interface LocaleOptionProps { locale: Locale label: string currentLocale: Locale onClick: (locale: Locale) => void } function LocaleOption({ locale, label, currentLocale, onClick }: LocaleOptionProps): React.ReactElement { const isActive = currentLocale === locale return ( ) } export function LanguageSettingsManager(): React.ReactElement { const [currentLocale, setCurrentLocale] = useState(getLocale()) const [loading, setLoading] = useState(true) useEffect(() => { const loadLocale = (): void => { try { if (typeof window === 'undefined') { setLoading(false) return } const savedLocale = window.localStorage.getItem(LOCALE_STORAGE_KEY) as Locale | null if (savedLocale && (savedLocale === 'fr' || savedLocale === 'en')) { setLocale(savedLocale) setCurrentLocale(savedLocale) } } catch (e) { console.error('Error loading locale:', e) } finally { setLoading(false) } } loadLocale() }, []) const handleLocaleChange = (locale: Locale): void => { setLocale(locale) setCurrentLocale(locale) try { if (typeof window !== 'undefined') { window.localStorage.setItem(LOCALE_STORAGE_KEY, locale) } } catch (e) { console.error('Error saving locale:', e) } // Force page reload to update all translations window.location.reload() } if (loading) { return (
{t('settings.language.loading')}
) } return (

{t('settings.language.title')}

{t('settings.language.description')}

) }