import { useEffect, type ReactNode } from "react"; import { motion, AnimatePresence } from "framer-motion"; import useReducedMotion from "../hooks/useReducedMotion"; import useModalLock from "../hooks/useModalLock"; interface ConfirmModalProps { isOpen: boolean; onClose: () => void; onConfirm: () => void; title: string; message: ReactNode; confirmText?: string; cancelText?: string; type?: "danger" | "warning" | "default" | "info"; confirmVariant?: "danger" | "primary"; loading?: boolean; } function ConfirmIcon({ type }: { type: string }) { switch (type) { case "danger": return ( ); case "info": return ( ); case "warning": return ( ); default: return ( ); } } export default function ConfirmModal({ isOpen, onClose, onConfirm, title, message, confirmText = "Potvrdit", cancelText = "Zrušit", type = "default", confirmVariant, loading, }: ConfirmModalProps) { const reducedMotion = useReducedMotion(); // Lock body scroll while open (ref-counted, nesting-safe) — matches FormModal. useModalLock(isOpen); useEffect(() => { if (!isOpen) return; function handleKeyDown(e: KeyboardEvent) { if (e.key === "Escape" && !loading) { onClose(); } } window.addEventListener("keydown", handleKeyDown); return () => window.removeEventListener("keydown", handleKeyDown); }, [isOpen, loading, onClose]); const duration = reducedMotion ? 0 : 0.22; const ease = [0.16, 1, 0.3, 1] as const; return ( {isOpen && ( !loading && onClose()} /> {title} {message} {cancelText} {loading ? "Zpracování..." : confirmText} )} ); }
{message}