import { h as ve } from "./openLink-m90p5mer.es.js";
import { $ as G } from "./number-dMxJejI6.es.js";
import { useEffect as K, useState as ge, useRef as V, useCallback as X, useContext as $e, createContext as ce } from "react";
import { b as q } from "./mergeProps-B-cqsBhL.es.js";
import { $ as he } from "./useEffectEvent-B4Fd4l1o.es.js";
import { $ as be } from "./context-BfHy4NgG.es.js";
import { $ as xe } from "./useControlledState-3TGZUXux.es.js";
function Ee() {
  return typeof window.ResizeObserver < "u";
}
function ee(t) {
  const { ref: e, box: l, onResize: r } = t;
  let o = he(r);
  K(() => {
    let n = e?.current;
    if (n)
      if (Ee()) {
        const a = new window.ResizeObserver((f) => {
          f.length && o();
        });
        return a.observe(n, {
          box: l
        }), () => {
          n && a.unobserve(n);
        };
      } else
        return window.addEventListener("resize", o, !1), () => {
          window.removeEventListener("resize", o, !1);
        };
  }, [
    e,
    l
  ]);
}
const I = {
  top: "top",
  bottom: "top",
  left: "left",
  right: "left"
}, W = {
  top: "bottom",
  bottom: "top",
  left: "right",
  right: "left"
}, Pe = {
  top: "left",
  left: "top"
}, J = {
  top: "height",
  left: "width"
}, ae = {
  width: "totalWidth",
  height: "totalHeight"
}, U = {};
let Te = () => typeof document < "u" ? window.visualViewport : null;
function te(t, e) {
  let l = 0, r = 0, o = 0, n = 0, a = 0, f = 0, p = {};
  var s;
  let u = ((s = e?.scale) !== null && s !== void 0 ? s : 1) > 1;
  if (t.tagName === "BODY" || t.tagName === "HTML") {
    let $ = document.documentElement;
    o = $.clientWidth, n = $.clientHeight;
    var h;
    l = (h = e?.width) !== null && h !== void 0 ? h : o;
    var g;
    r = (g = e?.height) !== null && g !== void 0 ? g : n, p.top = $.scrollTop || t.scrollTop, p.left = $.scrollLeft || t.scrollLeft, e && (a = e.offsetTop, f = e.offsetLeft);
  } else
    ({ width: l, height: r, top: a, left: f } = Z(t, !1)), p.top = t.scrollTop, p.left = t.scrollLeft, o = l, n = r;
  if (ve() && (t.tagName === "BODY" || t.tagName === "HTML") && u) {
    p.top = 0, p.left = 0;
    var m;
    a = (m = e?.pageTop) !== null && m !== void 0 ? m : 0;
    var c;
    f = (c = e?.pageLeft) !== null && c !== void 0 ? c : 0;
  }
  return {
    width: l,
    height: r,
    totalWidth: o,
    totalHeight: n,
    scroll: p,
    top: a,
    left: f
  };
}
function we(t) {
  return {
    top: t.scrollTop,
    left: t.scrollLeft,
    width: t.scrollWidth,
    height: t.scrollHeight
  };
}
function oe(t, e, l, r, o, n, a) {
  var f;
  let p = (f = o.scroll[t]) !== null && f !== void 0 ? f : 0, s = r[J[t]], u = a[t] + r.scroll[I[t]] + n, h = a[t] + r.scroll[I[t]] + s - n, g = e - p + r.scroll[I[t]] + a[t] - r[I[t]], m = e - p + l + r.scroll[I[t]] + a[t] - r[I[t]];
  return g < u ? u - g : m > h ? Math.max(h - m, u - g) : 0;
}
function Le(t) {
  let e = window.getComputedStyle(t);
  return {
    top: parseInt(e.marginTop, 10) || 0,
    bottom: parseInt(e.marginBottom, 10) || 0,
    left: parseInt(e.marginLeft, 10) || 0,
    right: parseInt(e.marginRight, 10) || 0
  };
}
function le(t) {
  if (U[t]) return U[t];
  let [e, l] = t.split(" "), r = I[e] || "right", o = Pe[r];
  I[l] || (l = "center");
  let n = J[r], a = J[o];
  return U[t] = {
    placement: e,
    crossPlacement: l,
    axis: r,
    crossAxis: o,
    size: n,
    crossSize: a
  }, U[t];
}
function B(t, e, l, r, o, n, a, f, p, s, u) {
  let { placement: h, crossPlacement: g, axis: m, crossAxis: c, size: $, crossSize: x } = r, P = {};
  var i;
  P[c] = (i = t[c]) !== null && i !== void 0 ? i : 0;
  var _, d, b, v;
  g === "center" ? P[c] += (((_ = t[x]) !== null && _ !== void 0 ? _ : 0) - ((d = l[x]) !== null && d !== void 0 ? d : 0)) / 2 : g !== c && (P[c] += ((b = t[x]) !== null && b !== void 0 ? b : 0) - ((v = l[x]) !== null && v !== void 0 ? v : 0)), P[c] += n;
  const w = t[c] - l[x] + p + s, T = t[c] + t[x] - p - s;
  if (P[c] = G(P[c], w, T), h === m) {
    let M = f ? u[$] : u[ae[$]];
    P[W[m]] = Math.floor(M - t[m] + o);
  } else P[m] = Math.floor(t[m] + t[$] + o);
  return P;
}
function _e(t, e, l, r, o, n, a, f, p, s, u) {
  var h, g;
  let m = (t.top != null ? t.top : p[ae.height] - ((h = t.bottom) !== null && h !== void 0 ? h : 0) - a) - ((g = p.scroll.top) !== null && g !== void 0 ? g : 0), c = s ? l.top : 0;
  var $, x, P;
  let i = {
    // This should be boundary top in container coord system vs viewport top in container coord system
    // For the viewport top, there are several cases
    // 1. pinchzoom case where we want the viewports offset top as top here
    // 2. case where container is offset from the boundary and is contained by the boundary. In this case the top we want here is NOT 0, we want to take boundary's top even though is is a negative number OR the visual viewport, whichever is more restrictive
    top: Math.max(e.top + c, (($ = u?.offsetTop) !== null && $ !== void 0 ? $ : e.top) + c),
    bottom: Math.min(e.top + e.height + c, ((x = u?.offsetTop) !== null && x !== void 0 ? x : 0) + ((P = u?.height) !== null && P !== void 0 ? P : 0))
  };
  var _, d, b, v;
  return f !== "top" ? (
    // We want the distance between the top of the overlay to the bottom of the boundary
    Math.max(0, i.bottom - m - (((_ = o.top) !== null && _ !== void 0 ? _ : 0) + ((d = o.bottom) !== null && d !== void 0 ? d : 0) + n))
  ) : Math.max(0, m + a - i.top - (((b = o.top) !== null && b !== void 0 ? b : 0) + ((v = o.bottom) !== null && v !== void 0 ? v : 0) + n));
}
function ne(t, e, l, r, o, n, a, f) {
  let { placement: p, axis: s, size: u } = n;
  var h, g;
  if (p === s) return Math.max(0, l[s] - ((h = a.scroll[s]) !== null && h !== void 0 ? h : 0) - (t[s] + (f ? e[s] : 0)) - ((g = r[s]) !== null && g !== void 0 ? g : 0) - r[W[s]] - o);
  var m, c;
  return Math.max(0, t[u] + t[s] + (f ? e[s] : 0) - l[s] - l[u] + ((m = a.scroll[s]) !== null && m !== void 0 ? m : 0) - ((c = r[s]) !== null && c !== void 0 ? c : 0) - r[W[s]] - o);
}
function Ce(t, e, l, r, o, n, a, f, p, s, u, h, g, m, c, $, x, P) {
  let i = le(t), { size: _, crossAxis: d, crossSize: b, placement: v, crossPlacement: w } = i, T = B(e, f, l, i, u, h, s, g, c, $, p), M = u, k = ne(f, s, e, o, n + u, i, p, x);
  if (a && l[_] > k) {
    let j = le(`${W[v]} ${w}`), me = B(e, f, l, j, u, h, s, g, c, $, p);
    ne(f, s, e, o, n + u, j, p, x) > k && (i = j, T = me, M = u);
  }
  let S = "bottom";
  i.axis === "top" ? i.placement === "top" ? S = "top" : i.placement === "bottom" && (S = "bottom") : i.crossAxis === "top" && (i.crossPlacement === "top" ? S = "bottom" : i.crossPlacement === "bottom" && (S = "top"));
  let L = oe(d, T[d], l[b], f, p, n, s);
  T[d] += L;
  let R = _e(T, f, s, g, o, n, l.height, S, p, x, P);
  m && m < R && (R = m), l.height = Math.min(l.height, R), T = B(e, f, l, i, M, h, s, g, c, $, p), L = oe(d, T[d], l[b], f, p, n, s), T[d] += L;
  let H = {}, z = e[d] - T[d] - o[I[d]], A = z + 0.5 * e[b];
  const N = c / 2 + $;
  var F, y, C, O;
  const Y = I[d] === "left" ? ((F = o.left) !== null && F !== void 0 ? F : 0) + ((y = o.right) !== null && y !== void 0 ? y : 0) : ((C = o.top) !== null && C !== void 0 ? C : 0) + ((O = o.bottom) !== null && O !== void 0 ? O : 0), se = l[b] - Y - c / 2 - $, fe = e[d] + c / 2 - (T[d] + o[I[d]]), de = e[d] + e[b] - c / 2 - (T[d] + o[I[d]]), pe = G(A, fe, de);
  H[d] = G(pe, N, se), { placement: v, crossPlacement: w } = i, c ? z = H[d] : w === "right" ? z += e[b] : w === "center" && (z += e[b] / 2);
  let D = v === "left" || v === "top" ? l[_] : 0, ue = {
    x: v === "top" || v === "bottom" ? z : D,
    y: v === "left" || v === "right" ? z : D
  };
  return {
    position: T,
    maxHeight: R,
    arrowOffsetLeft: H.left,
    arrowOffsetTop: H.top,
    placement: v,
    triggerAnchorPoint: ue
  };
}
function Re(t) {
  let { placement: e, targetNode: l, overlayNode: r, scrollNode: o, padding: n, shouldFlip: a, boundaryElement: f, offset: p, crossOffset: s, maxHeight: u, arrowSize: h = 0, arrowBoundaryOffset: g = 0 } = t, m = Te(), c = r instanceof HTMLElement ? He(r) : document.documentElement, $ = c === document.documentElement;
  const x = window.getComputedStyle(c).position;
  let P = !!x && x !== "static", i = $ ? Z(l, !1) : re(l, c, !1);
  if (!$) {
    let { marginTop: H, marginLeft: z } = window.getComputedStyle(l);
    i.top += parseInt(H, 10) || 0, i.left += parseInt(z, 10) || 0;
  }
  let _ = Z(r, !0), d = Le(r);
  var b, v;
  _.width += ((b = d.left) !== null && b !== void 0 ? b : 0) + ((v = d.right) !== null && v !== void 0 ? v : 0);
  var w, T;
  _.height += ((w = d.top) !== null && w !== void 0 ? w : 0) + ((T = d.bottom) !== null && T !== void 0 ? T : 0);
  let M = we(o), k = te(f, m), S = te(c, m), L = re(f, c, !1), R = f.contains(c);
  return Ce(e, i, _, M, d, n, a, k, S, L, p, s, P, u, h, g, R, m);
}
function Q(t, e) {
  let { top: l, left: r, width: o, height: n } = t.getBoundingClientRect();
  return e && t instanceof t.ownerDocument.defaultView.HTMLElement && (o = t.offsetWidth, n = t.offsetHeight), {
    top: l,
    left: r,
    width: o,
    height: n
  };
}
function Z(t, e) {
  let { top: l, left: r, width: o, height: n } = Q(t, e), { scrollTop: a, scrollLeft: f, clientTop: p, clientLeft: s } = document.documentElement;
  return {
    top: l + a - p,
    left: r + f - s,
    width: o,
    height: n
  };
}
function re(t, e, l) {
  let r = window.getComputedStyle(t), o;
  if (r.position === "fixed") o = Q(t, l);
  else {
    o = Z(t, l);
    let n = Z(e, l), a = window.getComputedStyle(e);
    n.top += (parseInt(a.borderTopWidth, 10) || 0) - e.scrollTop, n.left += (parseInt(a.borderLeftWidth, 10) || 0) - e.scrollLeft, o.top -= n.top, o.left -= n.left;
  }
  return o.top -= parseInt(r.marginTop, 10) || 0, o.left -= parseInt(r.marginLeft, 10) || 0, o;
}
function He(t) {
  let e = t.offsetParent;
  if (e && e === document.body && window.getComputedStyle(e).position === "static" && !ie(e) && (e = document.documentElement), e == null)
    for (e = t.parentElement; e && !ie(e); ) e = e.parentElement;
  return e || document.documentElement;
}
function ie(t) {
  let e = window.getComputedStyle(t);
  return e.transform !== "none" || /transform|perspective/.test(e.willChange) || e.filter !== "none" || e.contain === "paint" || "backdropFilter" in e && e.backdropFilter !== "none" || "WebkitBackdropFilter" in e && e.WebkitBackdropFilter !== "none";
}
const ze = /* @__PURE__ */ new WeakMap();
function Ie(t) {
  let { triggerRef: e, isOpen: l, onClose: r } = t;
  K(() => {
    if (!l || r === null) return;
    let o = (n) => {
      let a = n.target;
      if (!e.current || a instanceof Node && !a.contains(e.current) || n.target instanceof HTMLInputElement || n.target instanceof HTMLTextAreaElement) return;
      let f = r || ze.get(e.current);
      f && f();
    };
    return window.addEventListener("scroll", o, !0), () => {
      window.removeEventListener("scroll", o, !0);
    };
  }, [
    l,
    r,
    e
  ]);
}
let E = typeof document < "u" ? window.visualViewport : null;
function We(t) {
  let { direction: e } = be(), { arrowSize: l, targetRef: r, overlayRef: o, arrowRef: n, scrollRef: a = o, placement: f = "bottom", containerPadding: p = 12, shouldFlip: s = !0, boundaryElement: u = typeof document < "u" ? document.body : null, offset: h = 0, crossOffset: g = 0, shouldUpdatePosition: m = !0, isOpen: c = !0, onClose: $, maxHeight: x, arrowBoundaryOffset: P = 0 } = t, [i, _] = ge(null), d = [
    m,
    f,
    o.current,
    r.current,
    n?.current,
    a.current,
    p,
    s,
    u,
    h,
    g,
    c,
    e,
    x,
    P,
    l
  ], b = V(E?.scale);
  K(() => {
    c && (b.current = E?.scale);
  }, [
    c
  ]);
  let v = X(() => {
    if (m === !1 || !c || !o.current || !r.current || !u || E?.scale !== b.current) return;
    let L = null;
    if (a.current && a.current.contains(document.activeElement)) {
      var R;
      let C = (R = document.activeElement) === null || R === void 0 ? void 0 : R.getBoundingClientRect(), O = a.current.getBoundingClientRect();
      var H;
      if (L = {
        type: "top",
        offset: ((H = C?.top) !== null && H !== void 0 ? H : 0) - O.top
      }, L.offset > O.height / 2) {
        L.type = "bottom";
        var z;
        L.offset = ((z = C?.bottom) !== null && z !== void 0 ? z : 0) - O.bottom;
      }
    }
    let A = o.current;
    if (!x && o.current) {
      var N;
      A.style.top = "0px", A.style.bottom = "";
      var F;
      A.style.maxHeight = ((F = (N = window.visualViewport) === null || N === void 0 ? void 0 : N.height) !== null && F !== void 0 ? F : window.innerHeight) + "px";
    }
    let y = Re({
      placement: Ae(f, e),
      overlayNode: o.current,
      targetNode: r.current,
      scrollNode: a.current || o.current,
      padding: p,
      shouldFlip: s,
      boundaryElement: u,
      offset: h,
      crossOffset: g,
      maxHeight: x,
      arrowSize: l ?? (n?.current ? Q(n.current, !0).width : 0),
      arrowBoundaryOffset: P
    });
    if (y.position) {
      if (A.style.top = "", A.style.bottom = "", A.style.left = "", A.style.right = "", Object.keys(y.position).forEach((C) => A.style[C] = y.position[C] + "px"), A.style.maxHeight = y.maxHeight != null ? y.maxHeight + "px" : "", L && document.activeElement && a.current) {
        let C = document.activeElement.getBoundingClientRect(), O = a.current.getBoundingClientRect(), Y = C[L.type] - O[L.type];
        a.current.scrollTop += Y - L.offset;
      }
      _(y);
    }
  }, d);
  q(v, d), Se(v), ee({
    ref: o,
    onResize: v
  }), ee({
    ref: r,
    onResize: v
  });
  let w = V(!1);
  q(() => {
    let L, R = () => {
      w.current = !0, clearTimeout(L), L = setTimeout(() => {
        w.current = !1;
      }, 500), v();
    }, H = () => {
      w.current && R();
    };
    return E?.addEventListener("resize", R), E?.addEventListener("scroll", H), () => {
      E?.removeEventListener("resize", R), E?.removeEventListener("scroll", H);
    };
  }, [
    v
  ]);
  let T = X(() => {
    w.current || $?.();
  }, [
    $,
    w
  ]);
  Ie({
    triggerRef: r,
    isOpen: c,
    onClose: $ && T
  });
  var M, k, S;
  return {
    overlayProps: {
      style: {
        position: i ? "absolute" : "fixed",
        top: i ? void 0 : 0,
        left: i ? void 0 : 0,
        zIndex: 1e5,
        ...i?.position,
        maxHeight: (M = i?.maxHeight) !== null && M !== void 0 ? M : "100vh"
      }
    },
    placement: (k = i?.placement) !== null && k !== void 0 ? k : null,
    triggerAnchorPoint: (S = i?.triggerAnchorPoint) !== null && S !== void 0 ? S : null,
    arrowProps: {
      "aria-hidden": "true",
      role: "presentation",
      style: {
        left: i?.arrowOffsetLeft,
        top: i?.arrowOffsetTop
      }
    },
    updatePosition: v
  };
}
function Se(t) {
  q(() => (window.addEventListener("resize", t, !1), () => {
    window.removeEventListener("resize", t, !1);
  }), [
    t
  ]);
}
function Ae(t, e) {
  return e === "rtl" ? t.replace("start", "right").replace("end", "left") : t.replace("start", "left").replace("end", "right");
}
const Me = /* @__PURE__ */ ce({});
function Ye() {
  var t;
  return (t = $e(Me)) !== null && t !== void 0 ? t : {};
}
function je(t) {
  let [e, l] = xe(t.isOpen, t.defaultOpen || !1, t.onOpenChange);
  const r = X(() => {
    l(!0);
  }, [
    l
  ]), o = X(() => {
    l(!1);
  }, [
    l
  ]), n = X(() => {
    l(!e);
  }, [
    l,
    e
  ]);
  return {
    isOpen: e,
    setOpen: l,
    open: r,
    close: o,
    toggle: n
  };
}
const Be = /* @__PURE__ */ ce({
  placement: "bottom"
});
export {
  je as $,
  ee as a,
  Ye as b,
  We as c,
  Be as d,
  ze as e
};
//# sourceMappingURL=OverlayArrow-DQTbb80n.es.js.map
