"use client"; import { useEffect, type ReactNode } from "react"; import { X } from "lucide-react"; interface ConfirmDialogProps { open: boolean; title: string; /** Body content — plain text or richer markup (e.g. an avatar row). */ children?: ReactNode; confirmLabel: string; cancelLabel?: string; /** "danger" renders a red confirm button for destructive actions. */ tone?: "default" | "danger"; /** Disables the buttons and swaps the confirm label while pending. */ busy?: boolean; busyLabel?: string; onConfirm: () => void; onCancel: () => void; } /** * Small confirmation modal in the app's dialog style (overlay + card), * replacing bare window.confirm() prompts. Closes on Escape and on * overlay click; the cancel button takes initial focus so a stray Enter * never triggers a destructive action. */ export function ConfirmDialog({ open, title, children, confirmLabel, cancelLabel = "Cancel", tone = "default", busy = false, busyLabel, onConfirm, onCancel, }: ConfirmDialogProps) { useEffect(() => { if (!open) return; const onKeyDown = (event: KeyboardEvent) => { if (event.key === "Escape" && !busy) onCancel(); }; window.addEventListener("keydown", onKeyDown); return () => window.removeEventListener("keydown", onKeyDown); }, [open, busy, onCancel]); if (!open) return null; return (
{ if (!busy) onCancel(); }} >
e.stopPropagation()} className="w-full max-w-sm rounded-2xl border border-[var(--border)] bg-[var(--card)] p-5 shadow-xl" >

{title}

{children && (
{children}
)}
); }