'use client' import { useState } from 'react' import { useLanguage } from '@/lib/i18n' import { updateAISettings } from '@/app/actions/ai-settings' import { toast } from 'sonner' import { useRouter } from 'next/navigation' import { Globe, Bell } from 'lucide-react' import { motion } from 'motion/react' interface GeneralSettingsClientProps { initialSettings: { preferredLanguage: string emailNotifications: boolean desktopNotifications: boolean autoSave: boolean } } export function GeneralSettingsClient({ initialSettings }: GeneralSettingsClientProps) { const { t, setLanguage: setContextLanguage } = useLanguage() const router = useRouter() const [language, setLanguage] = useState(initialSettings.preferredLanguage || 'auto') const [emailNotifications, setEmailNotifications] = useState(initialSettings.emailNotifications ?? false) const [desktopNotifications, setDesktopNotifications] = useState(initialSettings.desktopNotifications ?? false) const [autoSave, setAutoSave] = useState(initialSettings.autoSave ?? true) const handleLanguageChange = async (value: string) => { setLanguage(value) await updateAISettings({ preferredLanguage: value as any }) if (value === 'auto') { localStorage.removeItem('user-language') document.cookie = 'user-language=;path=/;max-age=0' toast.success(t('settings.languageAuto')) } else { localStorage.setItem('user-language', value) document.cookie = `user-language=${value};path=/;max-age=${60 * 60 * 24 * 365};samesite=lax` setContextLanguage(value as any) toast.success(t('profile.languageUpdateSuccess')) } setTimeout(() => router.refresh(), 300) } const handleEmailNotificationsChange = async (enabled: boolean) => { setEmailNotifications(enabled) await updateAISettings({ emailNotifications: enabled }) toast.success(t('settings.settingsSaved')) } const handleDesktopNotificationsChange = async (enabled: boolean) => { setDesktopNotifications(enabled) await updateAISettings({ desktopNotifications: enabled }) toast.success(t('settings.settingsSaved')) } const handleAutoSaveChange = async (enabled: boolean) => { setAutoSave(enabled) await updateAISettings({ autoSave: enabled }) toast.success(t('settings.settingsSaved')) } return (

{t('generalSettings.description')}

{t('settings.language')}

{t('settings.selectLanguage')}

{t('settings.notifications')}

{t('settings.notificationsDesc')}

{t('settings.emailNotifications')}

{t('settings.emailNotificationsDesc')}

) }