'use client' import { useState } from 'react' import { Input } from '@/components/ui/input' import { updateProfile, changePassword } from '@/app/actions/profile' import { updateUserSettings } from '@/app/actions/user-settings' import { performSignOut } from '@/lib/auth-client' import { toast } from 'sonner' import { useLanguage } from '@/lib/i18n' import { User, Mail, Shield, LogOut, Camera, Bell } from 'lucide-react' import { motion } from 'motion/react' import { Avatar, AvatarFallback, AvatarImage } from '@/components/ui/avatar' export function ProfileForm({ user }: { user: { name: string | null; email: string; image: string | null } }) { const { t } = useLanguage() const [desktopNotif, setDesktopNotif] = useState(false) const initial = (user.name || user.email || 'U')[0].toUpperCase() return (
{/* Avatar + Name */}
{user.image ? ( {initial} ) : ( )}

{user.name || 'Utilisateur'}

{user.email}

{/* Personal info */}

{t('profile.description')}

{/* Name edit */}
{ const result = await updateProfile({ name: formData.get('name') as string }) if (result?.error) toast.error(t('profile.updateFailed')) else toast.success(t('profile.updateSuccess')) }} className="p-4 bg-white/40 dark:bg-white/5 border border-border rounded-2xl flex items-center justify-between gap-4">

{t('profile.displayName')}

{/* Email */}

Email

{user.email}

{/* Security / Password */}
{ const result = await changePassword(formData) if (result?.error) { const msg = '_form' in result.error ? result.error._form[0] : result.error.currentPassword?.[0] || result.error.newPassword?.[0] || result.error.confirmPassword?.[0] || t('profile.passwordChangeFailed') toast.error(msg) } else { toast.success(t('profile.passwordChangeSuccess')) } }} className="p-4 bg-white/40 dark:bg-white/5 border border-border rounded-2xl space-y-3">

{t('profile.changePassword')}

{t('profile.changePasswordDescription')}

{/* Preferences */}

{t('profile.preferences')}

{t('profile.desktopNotifications')}

{t('profile.desktopNotificationsDesc')}

{/* Logout */}
) }