'use client' import { useState } from 'react' import { updateAISettings } from '@/app/actions/ai-settings' import { updateUserSettings } from '@/app/actions/user-settings' import { useLanguage } from '@/lib/i18n' import { toast } from 'sonner' import { Palette, Type } from 'lucide-react' import { applyDocumentTheme, normalizeThemeId, type ThemeId } from '@/lib/apply-document-theme' interface AppearanceSettingsClientProps { initialFontSize: string initialTheme: string initialFontFamily?: string } export function AppearanceSettingsClient({ initialFontSize, initialTheme, initialFontFamily = 'inter', }: AppearanceSettingsClientProps) { const { t } = useLanguage() const [theme, setTheme] = useState(normalizeThemeId(initialTheme || 'light')) const [fontSize, setFontSize] = useState(initialFontSize || 'medium') const [fontFamily, setFontFamily] = useState(initialFontFamily) const handleThemeChange = async (value: string) => { const next = normalizeThemeId(value) setTheme(next) localStorage.setItem('theme-preference', next) applyDocumentTheme(next) await updateUserSettings({ theme: next }) toast.success(t('settings.settingsSaved') || 'Saved') } const handleFontSizeChange = async (value: string) => { setFontSize(value) const map: Record = { small: '14px', medium: '16px', large: '18px', 'extra-large': '20px' } document.documentElement.style.setProperty('--user-font-size', map[value] || '16px') await updateAISettings({ fontSize: value as any }) toast.success(t('settings.settingsSaved') || 'Saved') } const handleFontFamilyChange = async (value: string) => { const font = value === 'system' ? 'system' : value === 'playfair' ? 'playfair' : value === 'jetbrains' ? 'jetbrains' : 'inter' setFontFamily(font) localStorage.setItem('font-family', font) const root = document.documentElement root.classList.remove('font-system', 'font-playfair', 'font-jetbrains') if (font === 'system') root.classList.add('font-system') if (font === 'playfair') root.classList.add('font-playfair') if (font === 'jetbrains') root.classList.add('font-jetbrains') await updateAISettings({ fontFamily: font as 'inter' | 'playfair' | 'jetbrains' | 'system' }) toast.success(t('settings.settingsSaved') || 'Saved') } const SelectCard = ({ icon: Icon, title, description, value, options, onChange, optionGroups, }: { icon: React.ElementType title: string description: string value: string options?: { value: string; label: string }[] optionGroups?: { label: string; options: { value: string; label: string }[] }[] onChange: (v: string) => void }) => (

{title}

{description}

) const themeOptionGroups = [ { label: t('settings.themeBaseGroup'), options: [ { value: 'light', label: t('settings.themeLight') }, { value: 'dark', label: t('settings.themeDark') }, { value: 'auto', label: t('settings.themeSystem') }, ], }, { label: t('settings.themePalettesGroup'), options: [ { value: 'sepia', label: t('settings.themeSepia') }, { value: 'midnight', label: t('settings.themeMidnight') }, { value: 'rose', label: t('settings.themeRose') }, { value: 'green', label: t('settings.themeGreen') }, { value: 'lavender', label: t('settings.themeLavender') }, { value: 'sand', label: t('settings.themeSand') }, { value: 'ocean', label: t('settings.themeOcean') }, { value: 'sunset', label: t('settings.themeSunset') }, { value: 'blue', label: t('settings.themeBlue') }, ], }, ] return (
{/* Section label — architectural style */}

{t('appearance.description') || "Personnalisez l'interface"}

) }