import React, { useEffect, useRef } from "react"; export default function ConfirmModal({ open, title = "Confirmar", message = "¿Estás seguro?", confirmText = "Confirmar", cancelText = "Cancelar", danger = false, loading = false, onConfirm, onClose, }: { open: boolean; title?: string; message?: string; confirmText?: string; cancelText?: string; danger?: boolean; loading?: boolean; onConfirm: () => void | Promise; onClose: () => void; }) { const panelRef = useRef(null); useEffect(() => { if (!open) return; const onKey = (e: KeyboardEvent) => { if (e.key === "Escape") onClose(); }; document.addEventListener("keydown", onKey); return () => document.removeEventListener("keydown", onKey); }, [open, onClose]); useEffect(() => { if (!open) return; // enfoque inicial para accesibilidad const t = setTimeout(() => panelRef.current?.focus(), 0); return () => clearTimeout(t); }, [open]); if (!open) return null; return (
{/* Backdrop */}
); }