"use client"; import { useMemo } 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, TimeFormat, FirstDayOfWeek } from '@/stores/settings-store'; import { formatDate } from '@/lib/utils'; import { SettingsSection, SettingItem, Select, RadioGroup } from './settings-section'; export function LanguageSettings() { const t = useTranslations('settings.language_region'); const tDays = useTranslations('calendar.days'); const { dateFormat, timeFormat, firstDayOfWeek, updateSetting } = useSettingsStore(); // Subscribe to locale changes so the preview re-renders on language switch // (formatDate reads it via getState() and would otherwise stay stale). const locale = useLocaleStore((s) => s.locale); const preview = useMemo(() => { // Build sample timestamps for each bucket so users see what their pick // will look like in practice. Use offsets relative to "now" so the // bucketing is stable even though the wall-clock keeps moving. void locale; void dateFormat; void timeFormat; const now = new Date(); const today = new Date(now); today.setHours(15, 31, 0, 0); const thisWeek = new Date(now); thisWeek.setDate(now.getDate() - 2); thisWeek.setHours(15, 31, 0, 0); const older = new Date(now); older.setMonth(now.getMonth() - 2); older.setHours(15, 31, 0, 0); return { today: formatDate(today), thisWeek: formatDate(thisWeek), older: formatDate(older), }; }, [locale, dateFormat, timeFormat]); return (
updateSetting('firstDayOfWeek', parseInt(value) as FirstDayOfWeek)} options={[ { value: '1', label: tDays('monday') }, { value: '0', label: tDays('sunday') }, ]} /> ); }