import { useState, useEffect } from 'react' import { setLocale, getLocale, type Locale } from '@/lib/i18n' import { t } from '@/lib/i18n' import { localeStorage } from '@/lib/localeStorage' 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 = async (): Promise => { try { // Migrate from localStorage if needed await localeStorage.migrateFromLocalStorage() // Load from IndexedDB const savedLocale = await localeStorage.getLocale() if (savedLocale) { setLocale(savedLocale) setCurrentLocale(savedLocale) } } catch (e) { console.error('Error loading locale:', e) } finally { setLoading(false) } } void loadLocale() }, []) const handleLocaleChange = async (locale: Locale): Promise => { setLocale(locale) setCurrentLocale(locale) try { await localeStorage.saveLocale(locale) } catch (e) { console.error('Error saving locale:', e) } // Force page reload to update all translations window.location.reload() } const onLocaleClick = (locale: Locale): void => { void handleLocaleChange(locale) } if (loading) { return (
{t('settings.language.loading')}
) } return (

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

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

) }