import * as s from "react";
import { composeEventHandlers as p } from "../../../../../@radix-ui_primitive@1.1.0/node_modules/@radix-ui/primitive/dist/index.js";
import { useComposedRefs as C } from "../../../../../@radix-ui_react-compose-refs@1.1.0_@types_react@18.3.3_react@18.3.0-canary-3d9b20132-20240124/node_modules/@radix-ui/react-compose-refs/dist/index.js";
import { createContextScope as B, createContext as H } from "../../../../../@radix-ui_react-context@1.1.0_@types_react@18.3.3_react@18.3.0-canary-3d9b20132-20240124/node_modules/@radix-ui/react-context/dist/index.js";
import { useId as x } from "../../../../../@radix-ui_react-id@1.1.0_@types_react@18.3.3_react@18.3.0-canary-3d9b20132-20240124/node_modules/@radix-ui/react-id/dist/index.js";
import { useControllableState as V } from "../../../../../@radix-ui_react-use-controllable-state@1.1.0_@types_react@18.3.3_react@18.3.0-canary-3d9b20132-20240124/node_modules/@radix-ui/react-use-controllable-state/dist/index.js";
import { DismissableLayer as q } from "../../../../../@radix-ui_react-dismissable-layer@1.1.0_@types_react-dom@18.3.6_@types_react@18.3.3__@t_540819d22b5f34e77f512765c1a78ce5/node_modules/@radix-ui/react-dismissable-layer/dist/index.js";
import { FocusScope as K } from "../../../../../@radix-ui_react-focus-scope@1.1.0_@types_react-dom@18.3.6_@types_react@18.3.3__@types_r_c5413b53d4356de1cc2ff1163dee68dc/node_modules/@radix-ui/react-focus-scope/dist/index.js";
import { Portal as U } from "../../../../../@radix-ui_react-portal@1.1.1_@types_react-dom@18.3.6_@types_react@18.3.3__@types_react@_d91fd04d10d265136bf0d35a7b9375b2/node_modules/@radix-ui/react-portal/dist/index.js";
import { Presence as R } from "../../../../../@radix-ui_react-presence@1.1.0_@types_react-dom@18.3.6_@types_react@18.3.3__@types_reac_4a916339a724b4591202705df11dd5fc/node_modules/@radix-ui/react-presence/dist/index.js";
import { Primitive as g } from "../../../../../@radix-ui_react-primitive@2.0.0_@types_react-dom@18.3.6_@types_react@18.3.3__@types_rea_bdcf182289a3a76356f07e550726e479/node_modules/@radix-ui/react-primitive/dist/index.js";
import { useFocusGuards as Y } from "../../../../../@radix-ui_react-focus-guards@1.1.0_@types_react@18.3.3_react@18.3.0-canary-3d9b20132-20240124/node_modules/@radix-ui/react-focus-guards/dist/index.js";
import Z from "../../../../../react-remove-scroll@2.5.7_@types_react@18.3.3_react@18.3.0-canary-3d9b20132-20240124/node_modules/react-remove-scroll/dist/es2015/Combination.js";
import { hideOthers as z } from "../../../../../aria-hidden@1.2.6/node_modules/aria-hidden/dist/es2015/index.js";
import { Slot as J } from "../../../../../@radix-ui_react-slot@1.1.0_@types_react@18.3.3_react@18.3.0-canary-3d9b20132-20240124/node_modules/@radix-ui/react-slot/dist/index.js";
import { j as i } from "../../../../../../../_virtual/jsx-runtime.js";
var _ = "Dialog", [P, _e] = B(_), [Q, u] = P(_), y = (e) => {
  const {
    __scopeDialog: t,
    children: n,
    open: a,
    defaultOpen: r,
    onOpenChange: o,
    modal: l = !0
  } = e, c = s.useRef(null), f = s.useRef(null), [D = !1, v] = V({
    prop: a,
    defaultProp: r,
    onChange: o
  });
  return /* @__PURE__ */ i.jsx(
    Q,
    {
      scope: t,
      triggerRef: c,
      contentRef: f,
      contentId: x(),
      titleId: x(),
      descriptionId: x(),
      open: D,
      onOpenChange: v,
      onOpenToggle: s.useCallback(() => v(($) => !$), [v]),
      modal: l,
      children: n
    }
  );
};
y.displayName = _;
var I = "DialogTrigger", O = s.forwardRef(
  (e, t) => {
    const { __scopeDialog: n, ...a } = e, r = u(I, n), o = C(t, r.triggerRef);
    return /* @__PURE__ */ i.jsx(
      g.button,
      {
        type: "button",
        "aria-haspopup": "dialog",
        "aria-expanded": r.open,
        "aria-controls": r.contentId,
        "data-state": N(r.open),
        ...a,
        ref: o,
        onClick: p(e.onClick, r.onOpenToggle)
      }
    );
  }
);
O.displayName = I;
var h = "DialogPortal", [X, A] = P(h, {
  forceMount: void 0
}), j = (e) => {
  const { __scopeDialog: t, forceMount: n, children: a, container: r } = e, o = u(h, t);
  return /* @__PURE__ */ i.jsx(X, { scope: t, forceMount: n, children: s.Children.map(a, (l) => /* @__PURE__ */ i.jsx(R, { present: n || o.open, children: /* @__PURE__ */ i.jsx(U, { asChild: !0, container: r, children: l }) })) });
};
j.displayName = h;
var m = "DialogOverlay", T = s.forwardRef(
  (e, t) => {
    const n = A(m, e.__scopeDialog), { forceMount: a = n.forceMount, ...r } = e, o = u(m, e.__scopeDialog);
    return o.modal ? /* @__PURE__ */ i.jsx(R, { present: a || o.open, children: /* @__PURE__ */ i.jsx(ee, { ...r, ref: t }) }) : null;
  }
);
T.displayName = m;
var ee = s.forwardRef(
  (e, t) => {
    const { __scopeDialog: n, ...a } = e, r = u(m, n);
    return (
      // Make sure `Content` is scrollable even when it doesn't live inside `RemoveScroll`
      // ie. when `Overlay` and `Content` are siblings
      /* @__PURE__ */ i.jsx(Z, { as: J, allowPinchZoom: !0, shards: [r.contentRef], children: /* @__PURE__ */ i.jsx(
        g.div,
        {
          "data-state": N(r.open),
          ...a,
          ref: t,
          style: { pointerEvents: "auto", ...a.style }
        }
      ) })
    );
  }
), d = "DialogContent", b = s.forwardRef(
  (e, t) => {
    const n = A(d, e.__scopeDialog), { forceMount: a = n.forceMount, ...r } = e, o = u(d, e.__scopeDialog);
    return /* @__PURE__ */ i.jsx(R, { present: a || o.open, children: o.modal ? /* @__PURE__ */ i.jsx(oe, { ...r, ref: t }) : /* @__PURE__ */ i.jsx(te, { ...r, ref: t }) });
  }
);
b.displayName = d;
var oe = s.forwardRef(
  (e, t) => {
    const n = u(d, e.__scopeDialog), a = s.useRef(null), r = C(t, n.contentRef, a);
    return s.useEffect(() => {
      const o = a.current;
      if (o) return z(o);
    }, []), /* @__PURE__ */ i.jsx(
      M,
      {
        ...e,
        ref: r,
        trapFocus: n.open,
        disableOutsidePointerEvents: !0,
        onCloseAutoFocus: p(e.onCloseAutoFocus, (o) => {
          o.preventDefault(), n.triggerRef.current?.focus();
        }),
        onPointerDownOutside: p(e.onPointerDownOutside, (o) => {
          const l = o.detail.originalEvent, c = l.button === 0 && l.ctrlKey === !0;
          (l.button === 2 || c) && o.preventDefault();
        }),
        onFocusOutside: p(
          e.onFocusOutside,
          (o) => o.preventDefault()
        )
      }
    );
  }
), te = s.forwardRef(
  (e, t) => {
    const n = u(d, e.__scopeDialog), a = s.useRef(!1), r = s.useRef(!1);
    return /* @__PURE__ */ i.jsx(
      M,
      {
        ...e,
        ref: t,
        trapFocus: !1,
        disableOutsidePointerEvents: !1,
        onCloseAutoFocus: (o) => {
          e.onCloseAutoFocus?.(o), o.defaultPrevented || (a.current || n.triggerRef.current?.focus(), o.preventDefault()), a.current = !1, r.current = !1;
        },
        onInteractOutside: (o) => {
          e.onInteractOutside?.(o), o.defaultPrevented || (a.current = !0, o.detail.originalEvent.type === "pointerdown" && (r.current = !0));
          const l = o.target;
          n.triggerRef.current?.contains(l) && o.preventDefault(), o.detail.originalEvent.type === "focusin" && r.current && o.preventDefault();
        }
      }
    );
  }
), M = s.forwardRef(
  (e, t) => {
    const { __scopeDialog: n, trapFocus: a, onOpenAutoFocus: r, onCloseAutoFocus: o, ...l } = e, c = u(d, n), f = s.useRef(null), D = C(t, f);
    return Y(), /* @__PURE__ */ i.jsxs(i.Fragment, { children: [
      /* @__PURE__ */ i.jsx(
        K,
        {
          asChild: !0,
          loop: !0,
          trapped: a,
          onMountAutoFocus: r,
          onUnmountAutoFocus: o,
          children: /* @__PURE__ */ i.jsx(
            q,
            {
              role: "dialog",
              id: c.contentId,
              "aria-describedby": c.descriptionId,
              "aria-labelledby": c.titleId,
              "data-state": N(c.open),
              ...l,
              ref: D,
              onDismiss: () => c.onOpenChange(!1)
            }
          )
        }
      ),
      /* @__PURE__ */ i.jsxs(i.Fragment, { children: [
        /* @__PURE__ */ i.jsx(re, { titleId: c.titleId }),
        /* @__PURE__ */ i.jsx(ae, { contentRef: f, descriptionId: c.descriptionId })
      ] })
    ] });
  }
), E = "DialogTitle", w = s.forwardRef(
  (e, t) => {
    const { __scopeDialog: n, ...a } = e, r = u(E, n);
    return /* @__PURE__ */ i.jsx(g.h2, { id: r.titleId, ...a, ref: t });
  }
);
w.displayName = E;
var F = "DialogDescription", S = s.forwardRef(
  (e, t) => {
    const { __scopeDialog: n, ...a } = e, r = u(F, n);
    return /* @__PURE__ */ i.jsx(g.p, { id: r.descriptionId, ...a, ref: t });
  }
);
S.displayName = F;
var W = "DialogClose", k = s.forwardRef(
  (e, t) => {
    const { __scopeDialog: n, ...a } = e, r = u(W, n);
    return /* @__PURE__ */ i.jsx(
      g.button,
      {
        type: "button",
        ...a,
        ref: t,
        onClick: p(e.onClick, () => r.onOpenChange(!1))
      }
    );
  }
);
k.displayName = W;
function N(e) {
  return e ? "open" : "closed";
}
var G = "DialogTitleWarning", [he, L] = H(G, {
  contentName: d,
  titleName: E,
  docsSlug: "dialog"
}), re = ({ titleId: e }) => {
  const t = L(G), n = `\`${t.contentName}\` requires a \`${t.titleName}\` for the component to be accessible for screen reader users.

If you want to hide the \`${t.titleName}\`, you can wrap it with our VisuallyHidden component.

For more information, see https://radix-ui.com/primitives/docs/components/${t.docsSlug}`;
  return s.useEffect(() => {
    e && (document.getElementById(e) || console.error(n));
  }, [n, e]), null;
}, ne = "DialogDescriptionWarning", ae = ({ contentRef: e, descriptionId: t }) => {
  const a = `Warning: Missing \`Description\` or \`aria-describedby={undefined}\` for {${L(ne).contentName}}.`;
  return s.useEffect(() => {
    const r = e.current?.getAttribute("aria-describedby");
    t && r && (document.getElementById(t) || console.warn(a));
  }, [a, e, t]), null;
}, Ee = y, Ne = O, Pe = j, ye = T, Ie = b, Oe = w, Ae = S, je = k;
export {
  je as Close,
  Ie as Content,
  Ae as Description,
  y as Dialog,
  k as DialogClose,
  b as DialogContent,
  S as DialogDescription,
  T as DialogOverlay,
  j as DialogPortal,
  w as DialogTitle,
  O as DialogTrigger,
  ye as Overlay,
  Pe as Portal,
  Ee as Root,
  Oe as Title,
  Ne as Trigger,
  he as WarningProvider,
  _e as createDialogScope
};
//# sourceMappingURL=index.js.map
