'use client' import { useState, useEffect } from 'react' import { SettingsNav, SettingsSection, SettingSelect } from '@/components/settings' import { updateAISettings, getAISettings } from '@/app/actions/ai-settings' import { updateUserSettings, getUserSettings } from '@/app/actions/user-settings' import { useLanguage } from '@/lib/i18n' export default function AppearanceSettingsPage() { const { t } = useLanguage() const [theme, setTheme] = useState('auto') const [fontSize, setFontSize] = useState('medium') // Load settings on mount useEffect(() => { async function loadSettings() { try { const [aiSettings, userSettings] = await Promise.all([ getAISettings(), getUserSettings() ]) if (aiSettings.fontSize) setFontSize(aiSettings.fontSize) if (userSettings.theme) setTheme(userSettings.theme) } catch (error) { console.error('Error loading settings:', error) } } loadSettings() }, []) const handleThemeChange = async (value: string) => { setTheme(value) localStorage.setItem('theme-preference', value) // Instant visual update const root = document.documentElement root.removeAttribute('data-theme') root.classList.remove('dark') if (value === 'auto') { if (window.matchMedia('(prefers-color-scheme: dark)').matches) root.classList.add('dark') } else if (value === 'dark') { root.classList.add('dark') } else { root.setAttribute('data-theme', value) if (['midnight'].includes(value)) root.classList.add('dark') } await updateUserSettings({ theme: value as 'light' | 'dark' | 'auto' }) } const handleFontSizeChange = async (value: string) => { setFontSize(value) // Instant visual update const fontSizeMap: Record = { 'small': '14px', 'medium': '16px', 'large': '18px', 'extra-large': '20px' } const root = document.documentElement root.style.setProperty('--user-font-size', fontSizeMap[value] || '16px') await updateAISettings({ fontSize: value as any }) } return (

{t('appearance.title')}

{t('appearance.description')}

🎨} description={t('settings.themeLight') + ' / ' + t('settings.themeDark')} > 📝} description={t('profile.fontSizeDescription')} >
) }