import React, { useEffect, useCallback, useRef } from 'react' import { X } from 'lucide-react' const sizeClasses: Record = { sm: 'max-w-sm', md: 'max-w-md', lg: 'max-w-lg', xl: 'max-w-2xl', '2xl': 'max-w-4xl', '3xl': 'max-w-5xl', } interface ModalProps { isOpen: boolean onClose: () => void title?: React.ReactNode children?: React.ReactNode size?: string footer?: React.ReactNode hideCloseButton?: boolean } export default function Modal({ isOpen, onClose, title, children, size = 'md', footer, hideCloseButton = false, }: ModalProps) { const handleEsc = useCallback((e: KeyboardEvent) => { if (e.key === 'Escape') onClose() }, [onClose]) useEffect(() => { if (isOpen) { document.addEventListener('keydown', handleEsc) document.body.style.overflow = 'hidden' } return () => { document.removeEventListener('keydown', handleEsc) document.body.style.overflow = '' } }, [isOpen, handleEsc]) const mouseDownTarget = useRef(null) if (!isOpen) return null return (
{ mouseDownTarget.current = e.target }} onClick={e => { if (e.target === e.currentTarget && mouseDownTarget.current === e.currentTarget) onClose() mouseDownTarget.current = null }} >
e.stopPropagation()} > {/* Header */}

{title}

{!hideCloseButton && ( )}
{/* Body */}
{children}
{/* Footer */} {footer && (
{footer}
)}
) }