"use client";
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
import * as React from "react";
import * as DialogPrimitive from "@radix-ui/react-dialog";
import { VisuallyHidden } from "@radix-ui/react-visually-hidden";
import { XIcon } from "lucide-react";
import { cn } from "../../lib/utils";
import { useAppPortalContainer } from "./portal-container-context";
function Dialog({ ...props }) {
    return _jsx(DialogPrimitive.Root, { "data-slot": "dialog", ...props });
}
function DialogTrigger({ ...props }) {
    return _jsx(DialogPrimitive.Trigger, { "data-slot": "dialog-trigger", ...props });
}
function DialogPortal({ container, ...props }) {
    const appContainer = useAppPortalContainer();
    return (_jsx(DialogPrimitive.Portal, { "data-slot": "dialog-portal", container: container ?? appContainer, ...props }));
}
function DialogClose({ ...props }) {
    return _jsx(DialogPrimitive.Close, { "data-slot": "dialog-close", ...props });
}
function DialogOverlay({ className, ...props }) {
    return (_jsx(DialogPrimitive.Overlay, { "data-slot": "dialog-overlay", className: cn("data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 fixed inset-0 z-[100] bg-black/50 backdrop-blur-sm", className), ...props }));
}
function containsDialogDescription(children) {
    return React.Children.toArray(children).some((child) => {
        if (!React.isValidElement(child)) {
            return false;
        }
        if (child.type === DialogDescription ||
            child.type === DialogPrimitive.Description) {
            return true;
        }
        return containsDialogDescription(child.props.children);
    });
}
function DialogContent({ className, children, showCloseButton = true, overlayClassName, onInteractOutside, onPointerDownOutside, onFocusOutside, ...props }) {
    const hasDialogDescription = React.useMemo(() => containsDialogDescription(children), [children]);
    const handleInteractOutside = React.useCallback((event) => {
        const tourActive = document.body.getAttribute("data-tour-active") === "true";
        if (tourActive) {
            event.preventDefault();
            return;
        }
        if (onInteractOutside) {
            onInteractOutside(event);
        }
    }, [onInteractOutside]);
    return (_jsxs(DialogPortal, { "data-slot": "dialog-portal", children: [_jsx(DialogOverlay, { className: overlayClassName }), _jsxs(DialogPrimitive.Content, { "data-slot": "dialog-content", "data-testid": "dialog-content", ...props, ...(!hasDialogDescription && props["aria-describedby"] === undefined
                    ? { "aria-describedby": undefined }
                    : {}), className: cn("bg-background data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 fixed top-[50%] left-[50%] z-101 flex max-h-[calc(100dvh-2rem)] w-full max-w-[calc(100%-2rem)] translate-x-[-50%] translate-y-[-50%] flex-col overflow-hidden rounded-2xl border shadow-2xl duration-200", className), onInteractOutside: handleInteractOutside, onPointerDownOutside: onPointerDownOutside, onFocusOutside: onFocusOutside, children: [children, _jsx(VisuallyHidden, { children: _jsx(DialogPrimitive.Title, { children: "Dialog" }) }), showCloseButton && (_jsxs(DialogPrimitive.Close, { "data-slot": "dialog-close", className: "ring-offset-background focus:ring-ring data-[state=open]:bg-accent data-[state=open]:text-muted-foreground absolute top-7 right-7 z-50 cursor-pointer rounded-full p-1.5 opacity-70 transition-opacity hover:bg-gray-100 hover:opacity-100 focus:ring-2 focus:ring-offset-2 focus:outline-hidden disabled:pointer-events-none [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4", "data-testid": "dialog-close", children: [_jsx(XIcon, {}), _jsx("span", { className: "sr-only", children: "Close" })] }))] })] }));
}
function DialogHeader({ className, ...props }) {
    return (_jsx("div", { "data-slot": "dialog-header", className: cn("flex flex-col gap-2 px-8 pt-8 text-left", className), ...props }));
}
function DialogFooter({ className, ...props }) {
    return (_jsx("div", { "data-slot": "dialog-footer", className: cn("flex flex-col-reverse gap-3 px-8 pb-8 sm:flex-row sm:justify-end", className), ...props }));
}
function DialogTitle({ className, ...props }) {
    return (_jsx(DialogPrimitive.Title, { "data-slot": "dialog-title", className: cn("text-xl leading-none font-bold tracking-tight", className), ...props }));
}
function DialogDescription({ className, ...props }) {
    return (_jsx(DialogPrimitive.Description, { "data-slot": "dialog-description", className: cn("text-muted-foreground text-sm", className), ...props }));
}
export { Dialog, DialogClose, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogOverlay, DialogPortal, DialogTitle, DialogTrigger, };
//# sourceMappingURL=dialog.js.map