import React, { useEffect, useId, useRef } from 'react'; interface ModalShellProps { title: string; edit: boolean; onClose: () => void; onSave: () => void; onDelete?: () => void; canSave?: boolean; children: React.ReactNode; } const ModalShell: React.FC = ({ title, edit, onClose, onSave, onDelete, canSave = true, children }) => { const titleId = useId(); const onCloseRef = useRef(onClose); onCloseRef.current = onClose; useEffect(() => { const handleKeyDown = (e: KeyboardEvent) => { if (e.key === 'Escape') onCloseRef.current(); }; document.addEventListener('keydown', handleKeyDown); return () => document.removeEventListener('keydown', handleKeyDown); }, []); const handleOverlayClick = (e: React.MouseEvent) => { if (e.target === e.currentTarget) { onClose(); } }; return (

{title}

{children}
{edit && onDelete && ( )}
); }; export default ModalShell;