'use client' import { useState } from 'react' import { performSignOut } from '@/lib/auth-client' import { Loader2, ShieldAlert } from 'lucide-react' import { toast } from 'sonner' import { useLanguage } from '@/lib/i18n' import { Dialog, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogTitle, } from '@/components/ui/dialog' interface DeleteAccountDialogProps { userEmail: string open: boolean onOpenChange: (open: boolean) => void } export function DeleteAccountDialog({ userEmail, open, onOpenChange }: DeleteAccountDialogProps) { const { t } = useLanguage() const [inputEmail, setInputEmail] = useState('') const [isDeleting, setIsDeleting] = useState(false) const isConfirmed = inputEmail === userEmail const handleDelete = async () => { if (!isConfirmed || isDeleting) return setIsDeleting(true) try { const response = await fetch('/api/user/account', { method: 'DELETE', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ email: userEmail }), }) if (!response.ok) { throw new Error('Deletion failed') } toast.success(t('account.deleteAccount.successRedirect')) await performSignOut('/login?deleted=true') } catch { toast.error(t('account.deleteAccount.errorFailed')) setIsDeleting(false) } } const handleOpenChange = (v: boolean) => { if (isDeleting) return if (!v) setInputEmail('') onOpenChange(v) } return (
{t('account.deleteAccount.dialogTitle')}
{t('account.deleteAccount.dialogDescription')}

{t('account.deleteAccount.whatWillBeDeleted')}

    {[ t('account.deleteAccount.item1'), t('account.deleteAccount.item2'), t('account.deleteAccount.item3'), t('account.deleteAccount.item4'), t('account.deleteAccount.item5'), t('account.deleteAccount.item6'), t('account.deleteAccount.item7'), ].map((item, i) => (
  • {item}
  • ))}
setInputEmail(e.target.value)} placeholder={t('account.deleteAccount.emailPlaceholder')} disabled={isDeleting} className="w-full px-4 py-2.5 bg-white/40 dark:bg-white/5 border border-border rounded-xl text-sm text-ink placeholder:text-concrete/60 focus:outline-none focus:ring-1 focus:ring-rose-400 disabled:opacity-60" autoComplete="off" data-1p-ignore />

{userEmail}

) }