import { Button } from "@nous-research/ui/ui/components/button"; import { AlertTriangle } from "lucide-react"; import { useEffect, useRef } from "react"; import { createPortal } from "react-dom"; import { cn, themedBody } from "@/lib/utils"; interface ConfirmDialogProps { cancelLabel?: string; confirmLabel?: string; description?: string; destructive?: boolean; loading?: boolean; onCancel: () => void; onConfirm: () => void; open: boolean; title: string; } export function ConfirmDialog({ cancelLabel = "Cancel", confirmLabel = "Confirm", description, destructive = false, loading = false, onCancel, onConfirm, open, title, }: ConfirmDialogProps) { const dialogRef = useRef(null); useEffect(() => { if (!open) return; const prevActive = document.activeElement as HTMLElement | null; dialogRef.current ?.querySelector("[data-confirm]") ?.focus(); const onKey = (e: KeyboardEvent) => { if (e.key === "Escape") { e.preventDefault(); onCancel(); } }; document.addEventListener("keydown", onKey); const prevOverflow = document.body.style.overflow; document.body.style.overflow = "hidden"; return () => { document.removeEventListener("keydown", onKey); document.body.style.overflow = prevOverflow; prevActive?.focus?.(); }; }, [open, onCancel]); if (!open) return null; return createPortal(
{ if (e.target === e.currentTarget) onCancel(); }} className="fixed inset-0 z-[200] flex items-center justify-center bg-background/85 p-4" >
{destructive && (
)}

{title}

{description && (

{description}

)}
, document.body, ); }