'use client'; import { type ReactNode } from 'react'; import { AlertDialog, AlertDialogAction, AlertDialogCancel, AlertDialogContent, AlertDialogDescription, AlertDialogFooter, AlertDialogHeader, AlertDialogTitle, AlertDialogTrigger, } from '@/components/ui/alert-dialog'; import { cn } from '@/lib/utils'; interface ConfirmationDialogProps { /** The element that triggers the dialog to open */ trigger: ReactNode; title: string; description: string; /** Label for the confirm action button (default: "Delete") */ confirmLabel?: string; /** Label for the cancel button (default: "Cancel") */ cancelLabel?: string; /** Whether the confirm action is destructive — renders in red (default: true) */ destructive?: boolean; /** Called when the user confirms the action */ onConfirm: () => void | Promise; /** Whether the confirm button is in a loading state */ loading?: boolean; } /** * Reusable confirmation dialog for destructive actions (delete, archive, etc.). * Wraps shadcn AlertDialog so the trigger can be any element. */ export function ConfirmationDialog({ trigger, title, description, confirmLabel = 'Delete', cancelLabel = 'Cancel', destructive = true, onConfirm, loading = false, }: ConfirmationDialogProps) { return ( {trigger} {title} {description} {cancelLabel} {loading ? 'Please wait...' : confirmLabel} ); }