'use client'; import { useEffect, useRef } from 'react'; interface Props { isOpen: boolean; onClose: () => void; title: string; size?: 'sm' | 'md' | 'lg' | 'xl'; children: React.ReactNode; footer?: React.ReactNode; } const sizes = { sm: 'max-w-md', md: 'max-w-2xl', lg: 'max-w-4xl', xl: 'max-w-6xl' }; export default function Modal({ isOpen, onClose, title, size = 'md', children, footer }: Props) { const overlayRef = useRef(null); useEffect(() => { if (!isOpen) return; const h = (e: KeyboardEvent) => { if (e.key === 'Escape') onClose(); }; document.addEventListener('keydown', h); document.body.style.overflow = 'hidden'; return () => { document.removeEventListener('keydown', h); document.body.style.overflow = ''; }; }, [isOpen, onClose]); if (!isOpen) return null; return (
{ if (e.target === overlayRef.current) onClose(); }} className="fixed inset-0 z-[100] bg-black/50 flex items-center justify-center p-4" role="dialog" aria-modal="true" aria-label={title}>
{/* Header */}

{title}

{/* Body */}
{children}
{/* Footer */} {footer &&
{footer}
}
); }