import {
  Heading
} from "./chunk-BESTU2AY.js";
import {
  usePortalContainer
} from "./chunk-U7N2PWMO.js";
import {
  IconButton
} from "./chunk-XK6VEVOK.js";
import {
  __objRest,
  __spreadProps,
  __spreadValues
} from "./chunk-CRTRMMJ7.js";

// src/atoms/dialog.tsx
import * as RadixDialog from "@radix-ui/react-dialog";
import { Cross1Icon } from "@radix-ui/react-icons";
import { Flex, Theme } from "@radix-ui/themes";
import { useEffect, useRef } from "react";
import { jsx, jsxs } from "react/jsx-runtime";
var preventDefault = (e) => {
  e.preventDefault();
};
function Content2(props) {
  const _a = props, {
    children,
    style = {},
    width,
    maxWidth,
    minWidth,
    maxHeight,
    height,
    minHeight,
    title,
    buttons,
    hideCloseButton,
    className
  } = _a, rest = __objRest(_a, [
    "children",
    "style",
    "width",
    "maxWidth",
    "minWidth",
    "maxHeight",
    "height",
    "minHeight",
    "title",
    "buttons",
    "hideCloseButton",
    "className"
  ]);
  const { dialogContainerRef } = usePortalContainer();
  return /* @__PURE__ */ jsx(RadixDialog.Portal, { container: dialogContainerRef.current, children: /* @__PURE__ */ jsx(Theme, { asChild: true, children: /* @__PURE__ */ jsx(RadixDialog.Overlay, { className: "DialogOverlay", children: /* @__PURE__ */ jsxs(
    RadixDialog.Content,
    __spreadProps(__spreadValues({
      className: `DialogContent ${className || ""}`,
      onPointerDownOutside: preventDefault,
      style: __spreadValues({
        width,
        maxWidth,
        minWidth,
        maxHeight,
        height,
        minHeight
      }, style)
    }, rest), {
      children: [
        /* @__PURE__ */ jsxs(Flex, { gap: "2", justify: "between", width: "100%", children: [
          /* @__PURE__ */ jsx(RadixDialog.Title, { asChild: true, children: typeof title === "string" && title !== "" ? /* @__PURE__ */ jsx(Heading, { mb: "2", variant: "heading3", children: title }) : title }),
          !hideCloseButton && /* @__PURE__ */ jsx(RadixDialog.Close, { asChild: true, className: "DialogClose", children: /* @__PURE__ */ jsx(IconButton, { color: "gray", variant: "ghost", children: /* @__PURE__ */ jsx(Cross1Icon, {}) }) })
        ] }),
        children,
        buttons ? /* @__PURE__ */ jsx(Flex, { gap: "3", justify: "end", mt: "3", width: "100%", children: buttons }) : null
      ]
    })
  ) }) }) });
}
function Close2(_a) {
  var _b = _a, {
    children
  } = _b, rest = __objRest(_b, [
    "children"
  ]);
  return /* @__PURE__ */ jsx(RadixDialog.Close, __spreadProps(__spreadValues({ asChild: true }, rest), { children }));
}
function Trigger2(_a) {
  var _b = _a, {
    children
  } = _b, rest = __objRest(_b, [
    "children"
  ]);
  return /* @__PURE__ */ jsx(RadixDialog.Trigger, __spreadProps(__spreadValues({ asChild: true }, rest), { children }));
}
function Root2(props) {
  const prevOpenRef = useRef(void 0);
  const cleanupExecutedRef = useRef(false);
  useEffect(() => {
    const prevOpen = prevOpenRef.current;
    const currentOpen = props.open;
    if (prevOpen === true && currentOpen === false && !cleanupExecutedRef.current) {
      cleanupExecutedRef.current = true;
      const timer = setTimeout(() => {
        var _a;
        try {
          const activeElement = document.activeElement;
          (_a = activeElement == null ? void 0 : activeElement.blur) == null ? void 0 : _a.call(activeElement);
          document.body.style.pointerEvents = "";
        } catch (e) {
        } finally {
          cleanupExecutedRef.current = false;
        }
      }, 100);
      return () => {
        clearTimeout(timer);
        cleanupExecutedRef.current = false;
      };
    }
    prevOpenRef.current = currentOpen;
  }, [props.open]);
  return /* @__PURE__ */ jsx(RadixDialog.Root, __spreadValues({}, props));
}
var Dialog = {
  Root: Root2,
  Trigger: Trigger2,
  Content: Content2,
  Close: Close2,
  Description: RadixDialog.Description,
  Title: RadixDialog.Title
};

export {
  Dialog
};
//# sourceMappingURL=chunk-YQRJ52FA.js.map