import React, { ReactNode, useEffect } from 'react'; import { X } from 'lucide-react'; import { HelpTooltip } from './HelpTooltip'; export interface ModalProps { isOpen: boolean; onClose: () => void; title: string; subtitle?: string; helpText?: ReactNode; children: ReactNode; maxWidth?: 'sm' | 'md' | 'lg' | 'xl' | '2xl' | '3xl' | '4xl' | '5xl' | '6xl' | 'full'; size?: 'sm' | 'md' | 'lg' | 'xl' | '2xl' | '3xl' | '4xl' | '5xl' | '6xl' | 'full' | string; } export const Modal: React.FC = ({ isOpen, onClose, title, subtitle, helpText, children, maxWidth = 'lg', size, }) => { useEffect(() => { const handleKeyDown = (e: KeyboardEvent) => { if (e.key === 'Escape') onClose(); }; const handleDismissSubordinates = () => { onClose(); }; if (isOpen) { document.body.style.overflow = 'hidden'; window.addEventListener('keydown', handleKeyDown); window.addEventListener('pfm:dismiss-subordinates', handleDismissSubordinates); } return () => { document.body.style.overflow = 'unset'; window.removeEventListener('keydown', handleKeyDown); window.removeEventListener('pfm:dismiss-subordinates', handleDismissSubordinates); }; }, [isOpen, onClose]); if (!isOpen) return null; const effectiveSize = (size || maxWidth) as string; const maxWidthClassMap: Record = { sm: 'max-w-sm', md: 'max-w-md', lg: 'max-w-lg', xl: 'max-w-xl', '2xl': 'max-w-2xl', '3xl': 'max-w-3xl', '4xl': 'max-w-4xl', '5xl': 'max-w-5xl', '6xl': 'max-w-6xl', full: 'max-w-full', }; const maxWidthClass = maxWidthClassMap[effectiveSize] || 'max-w-lg'; return (
e.stopPropagation()} >

{title}

{helpText && ( )}
{subtitle &&

{subtitle}

}
{children}
); };