import { useEffect, useRef } from 'react'; interface ConfirmDialogProps { title: string; message: string; confirmLabel?: string; cancelLabel?: string; onConfirm: () => void; onCancel: () => void; /** @deprecated Use variant instead */ danger?: boolean; variant?: 'danger' | 'warning' | 'info'; } const VARIANT_STYLES = { danger: 'bg-red-600 hover:bg-red-700 focus:ring-red-500', warning: 'bg-amber-500 hover:bg-amber-600 focus:ring-amber-400', info: 'bg-blue-600 hover:bg-blue-700 focus:ring-blue-500', } as const; export default function ConfirmDialog({ title, message, confirmLabel = 'Confirm', cancelLabel = 'Cancel', onConfirm, onCancel, danger = false, variant, }: ConfirmDialogProps) { const confirmRef = useRef(null); // Resolve variant: explicit variant prop takes priority, then legacy danger boolean const resolvedVariant = variant ?? (danger ? 'danger' : 'info'); useEffect(() => { // Auto-focus the confirm button confirmRef.current?.focus(); const handleKey = (e: KeyboardEvent) => { if (e.key === 'Escape') { e.stopPropagation(); onCancel(); } if (e.key === 'Enter') { e.preventDefault(); onConfirm(); } }; window.addEventListener('keydown', handleKey); return () => window.removeEventListener('keydown', handleKey); }, [onCancel, onConfirm]); return (
e.stopPropagation()} >

{title}

{message}

); }