'use client' import { useEffect, useRef, useState } from "react" import { X } from 'lucide-react' import { cn } from "@/lib/utils" interface ModalProps { isOpen: boolean onClose: () => void title?: string children: React.ReactNode className?: string } export default function Modal({ isOpen, onClose, title, children, className }: ModalProps) { const overlayRef = useRef(null) const [mounted, setMounted] = useState(false) useEffect(() => { if (isOpen) { setMounted(true) document.body.style.overflow = "hidden" } else { document.body.style.overflow = "" } return () => { document.body.style.overflow = "" } }, [isOpen]) useEffect(() => { const handleEscape = (e: KeyboardEvent) => { if (e.key === "Escape") onClose() } window.addEventListener("keydown", handleEscape) return () => window.removeEventListener("keydown", handleEscape) }, [onClose]) if (!isOpen && !mounted) return null return (
{ if (e.target === overlayRef.current) onClose() }} role="dialog" aria-modal="true" aria-label={title || "Modal"} >
{title &&

{title}

}
{children}
) }