import { $ as I, d as T, a as w, e as z } from "./utils-CrjF8U_E.es.js";
import { a as U, b as H, c as V, d as K, e as g, f as j, g as F } from "./Dialog-7Yf08giu.es.js";
import { $ as h } from "./mergeProps-B-cqsBhL.es.js";
import { $ as y } from "./filterDOMProps-Cxz9cAAv.es.js";
import { $ as C } from "./useObjectRef-CaJ5pgjX.es.js";
import { $ as W } from "./scrollIntoView-Btu7DgIo.es.js";
import { c as x } from "./SelectionManager-GNsyMc-q.es.js";
import c, { useState as k, useEffect as R, forwardRef as D, useContext as m, useRef as q, createContext as S, useMemo as G } from "react";
import { $ as P } from "./SSRProvider-CQ9PmFV6.es.js";
import { $ as p, a as L } from "./animation-BfmkkMe7.es.js";
import { $ as J } from "./OverlayArrow-DQTbb80n.es.js";
let l = typeof document < "u" && window.visualViewport;
function Q() {
  let t = P(), [e, i] = k(() => t ? {
    width: 0,
    height: 0
  } : O());
  return R(() => {
    let a = () => {
      l && l.scale > 1 || i((r) => {
        let n = O();
        return n.width === r.width && n.height === r.height ? r : n;
      });
    }, d, s = (r) => {
      l && l.scale > 1 || x(r.target) && (d = requestAnimationFrame(() => {
        (!document.activeElement || !x(document.activeElement)) && i((n) => {
          let o = {
            width: window.innerWidth,
            height: window.innerHeight
          };
          return o.width === n.width && o.height === n.height ? n : o;
        });
      }));
    };
    return window.addEventListener("blur", s, !0), l ? l.addEventListener("resize", a) : window.addEventListener("resize", a), () => {
      cancelAnimationFrame(d), window.removeEventListener("blur", s, !0), l ? l.removeEventListener("resize", a) : window.removeEventListener("resize", a);
    };
  }, []), e;
}
function O() {
  return {
    // Multiply by the visualViewport scale to get the "natural" size, unaffected by pinch zooming.
    width: l ? l.width * l.scale : window.innerWidth,
    height: l ? l.height * l.scale : window.innerHeight
  };
}
function X(t, e, i) {
  let { overlayProps: a, underlayProps: d } = U({
    ...t,
    isOpen: e.isOpen,
    onClose: e.close
  }, i);
  return H({
    isDisabled: !e.isOpen
  }), V(), R(() => {
    if (e.isOpen && i.current) return K([
      i.current
    ], {
      shouldUseInert: !0
    });
  }, [
    e.isOpen,
    i
  ]), {
    modalProps: h(a),
    underlayProps: d
  };
}
const Y = /* @__PURE__ */ S(null), E = /* @__PURE__ */ S(null), ue = /* @__PURE__ */ D(function(e, i) {
  if (m(E)) {
    if (process.env.NODE_ENV !== "production" && (e.onOpenChange || e.defaultOpen !== void 0 || e.isOpen !== void 0)) {
      const _ = /* @__PURE__ */ new Set([
        "isDismissable",
        "isKeyboardDismissDisabled",
        "isOpen",
        "defaultOpen",
        "onOpenChange",
        "isEntering",
        "isExiting",
        "UNSTABLE_portalContainer",
        "shouldCloseOnInteractOutside"
      ]), A = Object.keys(e).filter((B) => _.has(B));
      console.warn(`This modal is already wrapped in a ModalOverlay, props [${A.join(", ")}] should be placed on the ModalOverlay instead.`);
    }
    return /* @__PURE__ */ c.createElement(v, {
      ...e,
      modalRef: i
    }, e.children);
  }
  let { isDismissable: d, isKeyboardDismissDisabled: s, isOpen: r, defaultOpen: n, onOpenChange: o, children: f, isEntering: $, isExiting: u, UNSTABLE_portalContainer: b, shouldCloseOnInteractOutside: M, ...N } = e;
  return /* @__PURE__ */ c.createElement(ee, {
    isDismissable: d,
    isKeyboardDismissDisabled: s,
    isOpen: r,
    defaultOpen: n,
    onOpenChange: o,
    isEntering: $,
    isExiting: u,
    UNSTABLE_portalContainer: b,
    shouldCloseOnInteractOutside: M
  }, /* @__PURE__ */ c.createElement(v, {
    ...N,
    modalRef: i
  }, f));
});
function Z(t, e) {
  [t, e] = I(t, e, Y);
  let i = m(g), a = J(t), d = t.isOpen != null || t.defaultOpen != null || !i ? a : i;
  d === i && process.env.NODE_ENV !== "production" && (t.onOpenChange || t.defaultOpen !== void 0 || t.isOpen !== void 0) && console.warn("This modals state is controlled by a trigger, place onOpenChange on the trigger instead.");
  let s = C(e), r = q(null), n = p(s, d.isOpen), o = p(r, d.isOpen), f = n || o || t.isExiting || !1, $ = P();
  return !d.isOpen && !f || $ ? null : /* @__PURE__ */ c.createElement(te, {
    ...t,
    state: d,
    isExiting: f,
    overlayRef: s,
    modalRef: r
  });
}
const ee = /* @__PURE__ */ D(Z);
function te({ UNSTABLE_portalContainer: t, ...e }) {
  let i = e.modalRef, { state: a } = e, { modalProps: d, underlayProps: s } = X(e, a, i), r = L(e.overlayRef) || e.isEntering || !1, n = w({
    ...e,
    defaultClassName: "react-aria-ModalOverlay",
    values: {
      isEntering: r,
      isExiting: e.isExiting,
      state: a
    }
  }), o = Q(), f;
  if (typeof document < "u") {
    let u = W(document.body) ? document.body : document.scrollingElement || document.documentElement, b = u.getBoundingClientRect().height % 1;
    f = u.scrollHeight - b;
  }
  let $ = {
    ...n.style,
    "--visual-viewport-height": o.height + "px",
    "--page-height": f !== void 0 ? f + "px" : void 0
  };
  return /* @__PURE__ */ c.createElement(F, {
    isExiting: e.isExiting,
    portalContainer: t
  }, /* @__PURE__ */ c.createElement("div", {
    ...h(y(e, {
      global: !0
    }), s),
    ...n,
    style: $,
    ref: e.overlayRef,
    "data-entering": r || void 0,
    "data-exiting": e.isExiting || void 0
  }, /* @__PURE__ */ c.createElement(z, {
    values: [
      [
        E,
        {
          modalProps: d,
          modalRef: i,
          isExiting: e.isExiting,
          isDismissable: e.isDismissable
        }
      ],
      [
        g,
        a
      ]
    ]
  }, n.children)));
}
function v(t) {
  let { modalProps: e, modalRef: i, isExiting: a, isDismissable: d } = m(E), s = m(g), r = G(() => T(t.modalRef, i), [
    t.modalRef,
    i
  ]), n = C(r), o = L(n), f = w({
    ...t,
    defaultClassName: "react-aria-Modal",
    values: {
      isEntering: o,
      isExiting: a,
      state: s
    }
  });
  return /* @__PURE__ */ c.createElement("div", {
    ...h(y(t, {
      global: !0
    }), e),
    ...f,
    ref: n,
    "data-entering": o || void 0,
    "data-exiting": a || void 0
  }, d && /* @__PURE__ */ c.createElement(j, {
    onDismiss: s.close
  }), f.children);
}
export {
  ee as $,
  ue as a
};
//# sourceMappingURL=Modal-DCxn1MEV.es.js.map
