'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, LayoutGrid, Maximize2 } from 'lucide-react' import { applyDocumentTheme, normalizeThemeId, type ThemeId } from '@/lib/apply-document-theme' interface AppearanceSettingsClientProps { initialFontSize: string initialTheme: string initialNotesViewMode: 'masonry' | 'tabs' | 'list' initialCardSizeMode?: 'variable' | 'uniform' initialFontFamily?: string } export function AppearanceSettingsClient({ initialFontSize, initialTheme, initialNotesViewMode, initialCardSizeMode = 'variable', initialFontFamily = 'inter', }: AppearanceSettingsClientProps) { const { t } = useLanguage() const [theme, setTheme] = useState(normalizeThemeId(initialTheme || 'light')) const [fontSize, setFontSize] = useState(initialFontSize || 'medium') const [notesViewMode, setNotesViewMode] = useState<'masonry' | 'tabs' | 'list'>(initialNotesViewMode) const [cardSizeMode, setCardSizeMode] = useState<'variable' | 'uniform'>(initialCardSizeMode) 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 handleNotesViewChange = async (value: string) => { const mode = value === 'tabs' ? 'tabs' : value === 'list' ? 'list' : 'masonry' setNotesViewMode(mode) await updateAISettings({ notesViewMode: mode }) toast.success(t('settings.settingsSaved') || 'Saved') } const handleCardSizeModeChange = async (value: string) => { const mode = value === 'uniform' ? 'uniform' : 'variable' setCardSizeMode(mode) localStorage.setItem('card-size-mode', mode) await updateUserSettings({ cardSizeMode: mode }) toast.success(t('settings.settingsSaved') || 'Saved') } const handleFontFamilyChange = async (value: string) => { const font = value === 'system' ? 'system' : 'inter' setFontFamily(font) localStorage.setItem('font-family', font) const root = document.documentElement font === 'system' ? root.classList.add('font-system') : root.classList.remove('font-system') await updateAISettings({ fontFamily: font }) 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 (

{t('appearance.title')}

{t('appearance.description')}

) }