import { useEffect, useId, useRef, type ReactNode } from "react"; import { X } from "lucide-react"; type Props = { open: boolean; onClose: () => void; title: ReactNode; description?: ReactNode; children: ReactNode; footer?: ReactNode; size?: "sm" | "md" | "lg"; closeOnBackdrop?: boolean; }; const sizes = { sm: "max-w-sm", md: "max-w-md", lg: "max-w-2xl", } as const; export function Dialog({ open, onClose, title, description, children, footer, size = "md", closeOnBackdrop = true, }: Props) { const ref = useRef(null); const titleId = useId(); useEffect(() => { const dialog = ref.current; if (!dialog) return; if (open && !dialog.open) dialog.showModal(); if (!open && dialog.open) dialog.close(); }, [open]); useEffect(() => { const dialog = ref.current; if (!dialog) return; const handleClose = () => onClose(); dialog.addEventListener("close", handleClose); return () => dialog.removeEventListener("close", handleClose); }, [onClose]); return ( { if (!closeOnBackdrop) return; if (event.target === ref.current) onClose(); }} className={`fixed inset-0 m-auto h-fit max-h-[calc(100vh-2rem)] w-[calc(100%-2rem)] ${sizes[size]} animate-scale-fade overflow-y-auto rounded-2xl border border-zinc-700/60 bg-zinc-800/95 p-0 text-zinc-100 shadow-2xl backdrop:bg-zinc-950/60 backdrop:backdrop-blur-sm`} >

{title}

{description ?

{description}

: null}
{children}
{footer ? (
{footer}
) : null}
); }