'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' 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') || 'Language set to Auto') } 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') || 'Language updated') } setTimeout(() => router.refresh(), 300) } const handleEmailNotificationsChange = async (enabled: boolean) => { setEmailNotifications(enabled) await updateAISettings({ emailNotifications: enabled }) toast.success(t('settings.settingsSaved') || 'Saved') } const handleDesktopNotificationsChange = async (enabled: boolean) => { setDesktopNotifications(enabled) await updateAISettings({ desktopNotifications: enabled }) toast.success(t('settings.settingsSaved') || 'Saved') } const handleAutoSaveChange = async (enabled: boolean) => { setAutoSave(enabled) await updateAISettings({ autoSave: enabled }) toast.success(t('settings.settingsSaved') || 'Saved') } return (
{t('generalSettings.description')}
{/* 2-column card grid */}{t('settings.selectLanguage')}
{t('settings.notificationsDesc')}
{t('settings.emailNotifications')}
{t('settings.emailNotificationsDesc')}
{t('settings.desktopNotifications')}
{t('settings.desktopNotificationsDesc')}
{t('settings.autoSave') || 'Auto-Save'}
{t('settings.autoSaveDesc') || 'Sauvegarder automatiquement les modifications'}