"use client"; import { ReactNode, useEffect, useState } from "react"; import { createPortal } from "react-dom"; import { X } from "lucide-react"; import { cn } from "@/lib/utils"; interface ModalProps { isOpen: boolean; onClose: () => void; title: string; children: ReactNode; className?: string; } export function Modal({ isOpen, onClose, title, children, className }: ModalProps) { const [isMounted, setIsMounted] = useState(false); const [isClosing, setIsClosing] = useState(false); const [visible, setVisible] = useState(false); useEffect(() => { setIsMounted(true); }, []); useEffect(() => { if (isOpen) { setVisible(true); setIsClosing(false); document.body.style.overflow = "hidden"; } else { if (visible) { setIsClosing(true); const timer = setTimeout(() => { setVisible(false); setIsClosing(false); document.body.style.overflow = "unset"; }, 480); return () => clearTimeout(timer); } } }, [isOpen, visible]); useEffect(() => { return () => { document.body.style.overflow = "unset"; }; }, []); if (!isMounted || !visible) return null; return createPortal(
{/* Backdrop */}
{/* Dialog */}

{title}

{children}
, document.body ); }