import { useState, useEffect, useCallback, type ReactNode } from 'react' import { X, Maximize2, Minimize2 } from 'lucide-react' import { cn } from '@/lib/utils' interface ModalProps { isOpen: boolean onClose: () => void title: string children: ReactNode /** Optional footer content that stays fixed at bottom (doesn't scroll) */ footer?: ReactNode size?: 'sm' | 'md' | 'lg' | 'xl' /** If true, a fullscreen toggle button appears in the modal header */ allowFullScreen?: boolean } export function Modal({ isOpen, onClose, title, children, footer, size = 'md', allowFullScreen = false }: ModalProps) { const [isFullScreen, setIsFullScreen] = useState(() => { if (!allowFullScreen) return false try { return localStorage.getItem('rf-editor-fullscreen') === 'true' } catch { return false } }) const toggleFullScreen = () => { const next = !isFullScreen setIsFullScreen(next) try { localStorage.setItem('rf-editor-fullscreen', String(next)) } catch {} } // Close on Escape key const handleKeyDown = useCallback( (e: KeyboardEvent) => { if (e.key === 'Escape') { onClose() } }, [onClose] ) useEffect(() => { if (isOpen) { document.addEventListener('keydown', handleKeyDown) document.body.style.overflow = 'hidden' } return () => { document.removeEventListener('keydown', handleKeyDown) document.body.style.overflow = '' } }, [isOpen, handleKeyDown]) if (!isOpen) return null const sizeClasses = { sm: 'max-w-sm', md: 'max-w-md', lg: 'max-w-full sm:max-w-lg', xl: 'max-w-full sm:max-w-4xl', } return (
{/* Backdrop */} ) } export default Modal