"use client"; import * as React from "react"; import { Dialog, DialogContent, DialogHeader, DialogTitle, DialogDescription, DialogFooter, DialogBody } from "@/components/ui/dialog"; import { Button } from "@/components/ui/button"; import { Input } from "@/components/ui/input"; export interface ConfirmDialogProps { open: boolean; onOpenChange: (open: boolean) => void; title: React.ReactNode; description?: React.ReactNode; confirmLabel?: string; cancelLabel?: string; destructive?: boolean; /** When set, the user must type this exact string to enable the confirm button. */ typeToConfirm?: string; onConfirm: () => Promise | void; children?: React.ReactNode; } export function ConfirmDialog({ open, onOpenChange, title, description, confirmLabel = "Confirm", cancelLabel = "Cancel", destructive, typeToConfirm, onConfirm, children }: ConfirmDialogProps) { const [busy, setBusy] = React.useState(false); const [typed, setTyped] = React.useState(""); const canConfirm = !typeToConfirm || typed.trim() === typeToConfirm; const handleOpenChange = (v: boolean) => { if (!v) setTyped(""); onOpenChange(v); }; return ( {title} {description ? {description} : null} {children || typeToConfirm ? ( {children} {typeToConfirm ? (

Type {typeToConfirm} to confirm.

setTyped(e.target.value)} autoComplete="off" spellCheck={false} aria-label="Confirmation text" />
) : null}
) : null}
); }