"use client"; import { useState, type ReactNode } from "react"; import { Loader2 } from "lucide-react"; import { AlertDialog, AlertDialogAction, AlertDialogCancel, AlertDialogContent, AlertDialogDescription, AlertDialogFooter, AlertDialogHeader, AlertDialogTitle, AlertDialogTrigger, } from "@/components/ui/alert-dialog"; export function ConfirmDialog({ trigger, title, description, confirmLabel = "Conferma", loadingLabel = "Attendere...", destructive = true, onConfirm, }: { trigger: ReactNode; title: string; description: string; confirmLabel?: string; loadingLabel?: string; destructive?: boolean; onConfirm: () => Promise | void; }) { const [open, setOpen] = useState(false); const [loading, setLoading] = useState(false); const handleConfirm = async () => { setLoading(true); try { await onConfirm(); setOpen(false); } catch (error) { console.error(error); alert("Si รจ verificato un errore. Riprova."); } finally { setLoading(false); } }; return ( {trigger} {title} {description} Annulla { e.preventDefault(); handleConfirm(); }} > {loading && } {loading ? loadingLabel : confirmLabel} ); }