import * as i from "react";
import { P as p, c as g, a as V, u as q } from "./index-DCcK_d4W.mjs";
import { u as _ } from "./index-DLcqcWxM.mjs";
import { c as K, a as U } from "./index-DOfn3ixy.mjs";
import { u as R } from "./index-CEQ35j8b.mjs";
import { P as Y, R as Z, h as z, u as J, F as Q, D as X } from "./index-CLMd7NJE.mjs";
import { P as h } from "./index-DDrLXRUs.mjs";
import { jsx as s, jsxs as N, Fragment as O } from "react/jsx-runtime";
var m = "Dialog", [I] = K(m), [ee, u] = I(m), x = (e) => {
  const {
    __scopeDialog: o,
    children: r,
    open: a,
    defaultOpen: n,
    onOpenChange: t,
    modal: l = !0
  } = e, c = i.useRef(null), f = i.useRef(null), [v, C] = q({
    prop: a,
    defaultProp: n ?? !1,
    onChange: t,
    caller: m
  });
  return /* @__PURE__ */ s(
    ee,
    {
      scope: o,
      triggerRef: c,
      contentRef: f,
      contentId: R(),
      titleId: R(),
      descriptionId: R(),
      open: v,
      onOpenChange: C,
      onOpenToggle: i.useCallback(() => C((H) => !H), [C]),
      modal: l,
      children: r
    }
  );
};
x.displayName = m;
var A = "DialogTrigger", T = i.forwardRef(
  (e, o) => {
    const { __scopeDialog: r, ...a } = e, n = u(A, r), t = _(o, n.triggerRef);
    return /* @__PURE__ */ s(
      p.button,
      {
        type: "button",
        "aria-haspopup": "dialog",
        "aria-expanded": n.open,
        "aria-controls": n.contentId,
        "data-state": y(n.open),
        ...a,
        ref: t,
        onClick: g(e.onClick, n.onOpenToggle)
      }
    );
  }
);
T.displayName = A;
var P = "DialogPortal", [te, b] = I(P, {
  forceMount: void 0
}), M = (e) => {
  const { __scopeDialog: o, forceMount: r, children: a, container: n } = e, t = u(P, o);
  return /* @__PURE__ */ s(te, { scope: o, forceMount: r, children: i.Children.map(a, (l) => /* @__PURE__ */ s(h, { present: r || t.open, children: /* @__PURE__ */ s(Y, { asChild: !0, container: n, children: l }) })) });
};
M.displayName = P;
var D = "DialogOverlay", w = i.forwardRef(
  (e, o) => {
    const r = b(D, e.__scopeDialog), { forceMount: a = r.forceMount, ...n } = e, t = u(D, e.__scopeDialog);
    return t.modal ? /* @__PURE__ */ s(h, { present: a || t.open, children: /* @__PURE__ */ s(ne, { ...n, ref: o }) }) : null;
  }
);
w.displayName = D;
var oe = V("DialogOverlay.RemoveScroll"), ne = i.forwardRef(
  (e, o) => {
    const { __scopeDialog: r, ...a } = e, n = u(D, r);
    return (
      // Make sure `Content` is scrollable even when it doesn't live inside `RemoveScroll`
      // ie. when `Overlay` and `Content` are siblings
      /* @__PURE__ */ s(Z, { as: oe, allowPinchZoom: !0, shards: [n.contentRef], children: /* @__PURE__ */ s(
        p.div,
        {
          "data-state": y(n.open),
          ...a,
          ref: o,
          style: { pointerEvents: "auto", ...a.style }
        }
      ) })
    );
  }
), d = "DialogContent", F = i.forwardRef(
  (e, o) => {
    const r = b(d, e.__scopeDialog), { forceMount: a = r.forceMount, ...n } = e, t = u(d, e.__scopeDialog);
    return /* @__PURE__ */ s(h, { present: a || t.open, children: t.modal ? /* @__PURE__ */ s(re, { ...n, ref: o }) : /* @__PURE__ */ s(ae, { ...n, ref: o }) });
  }
);
F.displayName = d;
var re = i.forwardRef(
  (e, o) => {
    const r = u(d, e.__scopeDialog), a = i.useRef(null), n = _(o, r.contentRef, a);
    return i.useEffect(() => {
      const t = a.current;
      if (t) return z(t);
    }, []), /* @__PURE__ */ s(
      S,
      {
        ...e,
        ref: n,
        trapFocus: r.open,
        disableOutsidePointerEvents: !0,
        onCloseAutoFocus: g(e.onCloseAutoFocus, (t) => {
          t.preventDefault(), r.triggerRef.current?.focus();
        }),
        onPointerDownOutside: g(e.onPointerDownOutside, (t) => {
          const l = t.detail.originalEvent, c = l.button === 0 && l.ctrlKey === !0;
          (l.button === 2 || c) && t.preventDefault();
        }),
        onFocusOutside: g(
          e.onFocusOutside,
          (t) => t.preventDefault()
        )
      }
    );
  }
), ae = i.forwardRef(
  (e, o) => {
    const r = u(d, e.__scopeDialog), a = i.useRef(!1), n = i.useRef(!1);
    return /* @__PURE__ */ s(
      S,
      {
        ...e,
        ref: o,
        trapFocus: !1,
        disableOutsidePointerEvents: !1,
        onCloseAutoFocus: (t) => {
          e.onCloseAutoFocus?.(t), t.defaultPrevented || (a.current || r.triggerRef.current?.focus(), t.preventDefault()), a.current = !1, n.current = !1;
        },
        onInteractOutside: (t) => {
          e.onInteractOutside?.(t), t.defaultPrevented || (a.current = !0, t.detail.originalEvent.type === "pointerdown" && (n.current = !0));
          const l = t.target;
          r.triggerRef.current?.contains(l) && t.preventDefault(), t.detail.originalEvent.type === "focusin" && n.current && t.preventDefault();
        }
      }
    );
  }
), S = i.forwardRef(
  (e, o) => {
    const { __scopeDialog: r, trapFocus: a, onOpenAutoFocus: n, onCloseAutoFocus: t, ...l } = e, c = u(d, r), f = i.useRef(null), v = _(o, f);
    return J(), /* @__PURE__ */ N(O, { children: [
      /* @__PURE__ */ s(
        Q,
        {
          asChild: !0,
          loop: !0,
          trapped: a,
          onMountAutoFocus: n,
          onUnmountAutoFocus: t,
          children: /* @__PURE__ */ s(
            X,
            {
              role: "dialog",
              id: c.contentId,
              "aria-describedby": c.descriptionId,
              "aria-labelledby": c.titleId,
              "data-state": y(c.open),
              ...l,
              ref: v,
              onDismiss: () => c.onOpenChange(!1)
            }
          )
        }
      ),
      /* @__PURE__ */ N(O, { children: [
        /* @__PURE__ */ s(se, { titleId: c.titleId }),
        /* @__PURE__ */ s(ce, { contentRef: f, descriptionId: c.descriptionId })
      ] })
    ] });
  }
), E = "DialogTitle", W = i.forwardRef(
  (e, o) => {
    const { __scopeDialog: r, ...a } = e, n = u(E, r);
    return /* @__PURE__ */ s(p.h2, { id: n.titleId, ...a, ref: o });
  }
);
W.displayName = E;
var k = "DialogDescription", G = i.forwardRef(
  (e, o) => {
    const { __scopeDialog: r, ...a } = e, n = u(k, r);
    return /* @__PURE__ */ s(p.p, { id: n.descriptionId, ...a, ref: o });
  }
);
G.displayName = k;
var L = "DialogClose", $ = i.forwardRef(
  (e, o) => {
    const { __scopeDialog: r, ...a } = e, n = u(L, r);
    return /* @__PURE__ */ s(
      p.button,
      {
        type: "button",
        ...a,
        ref: o,
        onClick: g(e.onClick, () => n.onOpenChange(!1))
      }
    );
  }
);
$.displayName = L;
function y(e) {
  return e ? "open" : "closed";
}
var B = "DialogTitleWarning", [me, j] = U(B, {
  contentName: d,
  titleName: E,
  docsSlug: "dialog"
}), se = ({ titleId: e }) => {
  const o = j(B), r = `\`${o.contentName}\` requires a \`${o.titleName}\` for the component to be accessible for screen reader users.

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

For more information, see https://radix-ui.com/primitives/docs/components/${o.docsSlug}`;
  return i.useEffect(() => {
    e && (document.getElementById(e) || console.error(r));
  }, [r, e]), null;
}, ie = "DialogDescriptionWarning", ce = ({ contentRef: e, descriptionId: o }) => {
  const a = `Warning: Missing \`Description\` or \`aria-describedby={undefined}\` for {${j(ie).contentName}}.`;
  return i.useEffect(() => {
    const n = e.current?.getAttribute("aria-describedby");
    o && n && (document.getElementById(o) || console.warn(a));
  }, [a, e, o]), null;
}, ve = x, Ce = T, Re = M, _e = w, he = F, Pe = W, Ee = G, ye = $;
export {
  he as C,
  Ee as D,
  _e as O,
  Re as P,
  ve as R,
  Pe as T,
  ye as a,
  Ce as b
};
//# sourceMappingURL=index-CKCTy3ZL.mjs.map
