"use client" import * as React from "react" import { cn } from "@/lib/utils" import { X } from "lucide-react" interface DialogProps { open?: boolean onOpenChange?: (open: boolean) => void children: React.ReactNode } const DialogContext = React.createContext<{ open: boolean setOpen: (open: boolean) => void } | null>(null) function Dialog({ open: controlledOpen, onOpenChange, children }: DialogProps) { const [internalOpen, setInternalOpen] = React.useState(false) const open = controlledOpen !== undefined ? controlledOpen : internalOpen const setOpen = onOpenChange || setInternalOpen return ( {children} ) } function useDialog() { const context = React.useContext(DialogContext) if (!context) { throw new Error("useDialog must be used within a Dialog") } return context } interface DialogTriggerProps { children: React.ReactNode asChild?: boolean } function DialogTrigger({ children, asChild }: DialogTriggerProps) { const { setOpen } = useDialog() if (asChild && React.isValidElement(children)) { return React.cloneElement(children as React.ReactElement, { onClick: (e: React.MouseEvent) => { (children as React.ReactElement).props.onClick?.(e) setOpen(true) } }) } return ( ) } interface DialogContentProps { children: React.ReactNode className?: string } function DialogContent({ children, className }: DialogContentProps) { const { open, setOpen } = useDialog() if (!open) return null return (
{/* Backdrop */}
setOpen(false)} /> {/* Content */}
{children}
{/* Close button */}
) } function DialogHeader({ className, ...props }: React.HTMLAttributes) { return (
) } function DialogTitle({ className, ...props }: React.HTMLAttributes) { return (

) } function DialogDescription({ className, ...props }: React.HTMLAttributes) { return (

) } export { Dialog, DialogTrigger, DialogContent, DialogHeader, DialogTitle, DialogDescription, }