import { useEffect } from 'react'; interface Props { title: string; open: boolean; onClose: () => void; children: React.ReactNode; // Wider for dense edit forms (e.g. player detail with multiple sections). size?: 'sm' | 'md' | 'lg' | 'xl'; // Sticky action bar at the bottom — pass buttons here so the form // body can scroll but the actions stay visible on small screens. footer?: React.ReactNode; } export function Modal({ title, open, onClose, children, size = 'md', footer }: Props) { useEffect(() => { if (!open) return; const onKey = (e: KeyboardEvent) => { if (e.key === 'Escape') onClose(); }; document.addEventListener('keydown', onKey); const prevOverflow = document.body.style.overflow; document.body.style.overflow = 'hidden'; return () => { document.removeEventListener('keydown', onKey); document.body.style.overflow = prevOverflow; }; }, [open, onClose]); if (!open) return null; const sizeClass = { sm: 'max-w-sm', md: 'max-w-lg', lg: 'max-w-2xl', xl: 'max-w-4xl', }[size]; return (
e.stopPropagation()} >

{title}

{children}
{footer && (
{footer}
)}
); }