"use client"; import { useEffect, useMemo, useState } from 'react'; import { useTranslations } from 'next-intl'; import { LanguageSwitcher } from '@/components/ui/language-switcher'; import { useLocaleStore } from '@/stores/locale-store'; import { useSettingsStore } from '@/stores/settings-store'; import type { DateFormat, DateLocale, TimeFormat, FirstDayOfWeek } from '@/stores/settings-store'; import { formatDate } from '@/lib/utils'; import { getEffectiveLocale } from '@/i18n/detect-locale'; import { AUTO_TIME_ZONE, getBrowserTimeZone, getEffectiveTimeZone, listTimeZones } from '@/lib/timezone'; import { SettingsSection, SettingItem, Select, RadioGroup } from './settings-section'; export function LanguageSettings() { const t = useTranslations('settings.language_region'); const tDays = useTranslations('calendar.days'); const { dateFormat, dateLocale, timeFormat, firstDayOfWeek, timeZone, updateSetting } = useSettingsStore(); // Browser zone + zone list are read after mount: SSR has no browser, and a // server/client mismatch in the option list would trip hydration. const [browserTimeZone, setBrowserTimeZone] = useState('UTC'); const [timeZones, setTimeZones] = useState([]); useEffect(() => { setBrowserTimeZone(getBrowserTimeZone()); setTimeZones(listTimeZones()); }, []); const timeZoneOptions = useMemo(() => { const options = [{ value: AUTO_TIME_ZONE, label: t('time_zone.auto', { zone: browserTimeZone }) }]; // A zone synced from another browser (newer tz database) may be missing // from this runtime's list; keep it selectable rather than snapping the // updateSetting('dateFormat', value as DateFormat)} options={[ { value: 'smart', label: withExample(t('date_format.smart'), preview.dateFormat.smart) }, { value: 'relative', label: withExample(t('date_format.relative'), preview.dateFormat.relative) }, { value: 'full', label: withExample(t('date_format.full'), preview.dateFormat.full) }, ]} />
{t('date_format.preview_today')} {preview.today}
{t('date_format.preview_this_week')} {preview.thisWeek}
{t('date_format.preview_older')} {preview.older}
updateSetting('timeZone', value)} options={timeZoneOptions} className="max-w-[16rem]" /> {timeZonePreview && (
{t('time_zone.preview_now')} {timeZonePreview}
)}