import * as L from "react";
import { useLayoutEffect as Ut } from "react";
import * as Kt from "react-dom";
function at() {
  return typeof window < "u";
}
function tt(t) {
  return Bt(t) ? (t.nodeName || "").toLowerCase() : "#document";
}
function $(t) {
  var e;
  return (t == null || (e = t.ownerDocument) == null ? void 0 : e.defaultView) || window;
}
function j(t) {
  var e;
  return (e = (Bt(t) ? t.ownerDocument : t.document) || window.document) == null ? void 0 : e.documentElement;
}
function Bt(t) {
  return at() ? t instanceof Node || t instanceof $(t).Node : !1;
}
function N(t) {
  return at() ? t instanceof Element || t instanceof $(t).Element : !1;
}
function Y(t) {
  return at() ? t instanceof HTMLElement || t instanceof $(t).HTMLElement : !1;
}
function St(t) {
  return !at() || typeof ShadowRoot > "u" ? !1 : t instanceof ShadowRoot || t instanceof $(t).ShadowRoot;
}
function ot(t) {
  const {
    overflow: e,
    overflowX: n,
    overflowY: o,
    display: i
  } = H(t);
  return /auto|scroll|overlay|hidden|clip/.test(e + o + n) && i !== "inline" && i !== "contents";
}
function Gt(t) {
  return /^(table|td|th)$/.test(tt(t));
}
function ut(t) {
  try {
    if (t.matches(":popover-open"))
      return !0;
  } catch {
  }
  try {
    return t.matches(":modal");
  } catch {
    return !1;
  }
}
const Jt = /transform|translate|scale|rotate|perspective|filter/, Qt = /paint|layout|strict|content/, G = (t) => !!t && t !== "none";
let ht;
function vt(t) {
  const e = N(t) ? H(t) : t;
  return G(e.transform) || G(e.translate) || G(e.scale) || G(e.rotate) || G(e.perspective) || !bt() && (G(e.backdropFilter) || G(e.filter)) || Jt.test(e.willChange || "") || Qt.test(e.contain || "");
}
function Zt(t) {
  let e = U(t);
  for (; Y(e) && !Z(e); ) {
    if (vt(e))
      return e;
    if (ut(e))
      return null;
    e = U(e);
  }
  return null;
}
function bt() {
  return ht == null && (ht = typeof CSS < "u" && CSS.supports && CSS.supports("-webkit-backdrop-filter", "none")), ht;
}
function Z(t) {
  return /^(html|body|#document)$/.test(tt(t));
}
function H(t) {
  return $(t).getComputedStyle(t);
}
function dt(t) {
  return N(t) ? {
    scrollLeft: t.scrollLeft,
    scrollTop: t.scrollTop
  } : {
    scrollLeft: t.scrollX,
    scrollTop: t.scrollY
  };
}
function U(t) {
  if (tt(t) === "html")
    return t;
  const e = (
    // Step into the shadow DOM of the parent of a slotted node.
    t.assignedSlot || // DOM Element detected.
    t.parentNode || // ShadowRoot detected.
    St(t) && t.host || // Fallback.
    j(t)
  );
  return St(e) ? e.host : e;
}
function Nt(t) {
  const e = U(t);
  return Z(e) ? t.ownerDocument ? t.ownerDocument.body : t.body : Y(e) && ot(e) ? e : Nt(e);
}
function nt(t, e, n) {
  var o;
  e === void 0 && (e = []), n === void 0 && (n = !0);
  const i = Nt(t), r = i === ((o = t.ownerDocument) == null ? void 0 : o.body), s = $(i);
  if (r) {
    const c = wt(s);
    return e.concat(s, s.visualViewport || [], ot(i) ? i : [], c && n ? nt(c) : []);
  } else
    return e.concat(i, nt(i, [], n));
}
function wt(t) {
  return t.parent && Object.getPrototypeOf(t.parent) ? t.frameElement : null;
}
const te = ["top", "right", "bottom", "left"], K = Math.min, F = Math.max, st = Math.round, it = Math.floor, z = (t) => ({
  x: t,
  y: t
}), ee = {
  left: "right",
  right: "left",
  bottom: "top",
  top: "bottom"
};
function xt(t, e, n) {
  return F(t, K(e, n));
}
function I(t, e) {
  return typeof t == "function" ? t(e) : t;
}
function X(t) {
  return t.split("-")[0];
}
function et(t) {
  return t.split("-")[1];
}
function Rt(t) {
  return t === "x" ? "y" : "x";
}
function At(t) {
  return t === "y" ? "height" : "width";
}
function V(t) {
  const e = t[0];
  return e === "t" || e === "b" ? "y" : "x";
}
function Ot(t) {
  return Rt(V(t));
}
function ne(t, e, n) {
  n === void 0 && (n = !1);
  const o = et(t), i = Ot(t), r = At(i);
  let s = i === "x" ? o === (n ? "end" : "start") ? "right" : "left" : o === "start" ? "bottom" : "top";
  return e.reference[r] > e.floating[r] && (s = ct(s)), [s, ct(s)];
}
function oe(t) {
  const e = ct(t);
  return [yt(t), e, yt(e)];
}
function yt(t) {
  return t.includes("start") ? t.replace("start", "end") : t.replace("end", "start");
}
const Et = ["left", "right"], Lt = ["right", "left"], ie = ["top", "bottom"], re = ["bottom", "top"];
function se(t, e, n) {
  switch (t) {
    case "top":
    case "bottom":
      return n ? e ? Lt : Et : e ? Et : Lt;
    case "left":
    case "right":
      return e ? ie : re;
    default:
      return [];
  }
}
function ce(t, e, n, o) {
  const i = et(t);
  let r = se(X(t), n === "start", o);
  return i && (r = r.map((s) => s + "-" + i), e && (r = r.concat(r.map(yt)))), r;
}
function ct(t) {
  const e = X(t);
  return ee[e] + t.slice(e.length);
}
function le(t) {
  return {
    top: 0,
    right: 0,
    bottom: 0,
    left: 0,
    ...t
  };
}
function Ht(t) {
  return typeof t != "number" ? le(t) : {
    top: t,
    right: t,
    bottom: t,
    left: t
  };
}
function lt(t) {
  const {
    x: e,
    y: n,
    width: o,
    height: i
  } = t;
  return {
    width: o,
    height: i,
    top: n,
    left: e,
    right: e + o,
    bottom: n + i,
    x: e,
    y: n
  };
}
function Pt(t, e, n) {
  let {
    reference: o,
    floating: i
  } = t;
  const r = V(e), s = Ot(e), c = At(s), a = X(e), d = r === "y", l = o.x + o.width / 2 - i.width / 2, u = o.y + o.height / 2 - i.height / 2, m = o[c] / 2 - i[c] / 2;
  let f;
  switch (a) {
    case "top":
      f = {
        x: l,
        y: o.y - i.height
      };
      break;
    case "bottom":
      f = {
        x: l,
        y: o.y + o.height
      };
      break;
    case "right":
      f = {
        x: o.x + o.width,
        y: u
      };
      break;
    case "left":
      f = {
        x: o.x - i.width,
        y: u
      };
      break;
    default:
      f = {
        x: o.x,
        y: o.y
      };
  }
  switch (et(e)) {
    case "start":
      f[s] -= m * (n && d ? -1 : 1);
      break;
    case "end":
      f[s] += m * (n && d ? -1 : 1);
      break;
  }
  return f;
}
async function fe(t, e) {
  var n;
  e === void 0 && (e = {});
  const {
    x: o,
    y: i,
    platform: r,
    rects: s,
    elements: c,
    strategy: a
  } = t, {
    boundary: d = "clippingAncestors",
    rootBoundary: l = "viewport",
    elementContext: u = "floating",
    altBoundary: m = !1,
    padding: f = 0
  } = I(e, t), h = Ht(f), w = c[m ? u === "floating" ? "reference" : "floating" : u], p = lt(await r.getClippingRect({
    element: (n = await (r.isElement == null ? void 0 : r.isElement(w))) == null || n ? w : w.contextElement || await (r.getDocumentElement == null ? void 0 : r.getDocumentElement(c.floating)),
    boundary: d,
    rootBoundary: l,
    strategy: a
  })), v = u === "floating" ? {
    x: o,
    y: i,
    width: s.floating.width,
    height: s.floating.height
  } : s.reference, y = await (r.getOffsetParent == null ? void 0 : r.getOffsetParent(c.floating)), x = await (r.isElement == null ? void 0 : r.isElement(y)) ? await (r.getScale == null ? void 0 : r.getScale(y)) || {
    x: 1,
    y: 1
  } : {
    x: 1,
    y: 1
  }, b = lt(r.convertOffsetParentRelativeRectToViewportRelativeRect ? await r.convertOffsetParentRelativeRectToViewportRelativeRect({
    elements: c,
    rect: v,
    offsetParent: y,
    strategy: a
  }) : v);
  return {
    top: (p.top - b.top + h.top) / x.y,
    bottom: (b.bottom - p.bottom + h.bottom) / x.y,
    left: (p.left - b.left + h.left) / x.x,
    right: (b.right - p.right + h.right) / x.x
  };
}
const ae = 50, ue = async (t, e, n) => {
  const {
    placement: o = "bottom",
    strategy: i = "absolute",
    middleware: r = [],
    platform: s
  } = n, c = s.detectOverflow ? s : {
    ...s,
    detectOverflow: fe
  }, a = await (s.isRTL == null ? void 0 : s.isRTL(e));
  let d = await s.getElementRects({
    reference: t,
    floating: e,
    strategy: i
  }), {
    x: l,
    y: u
  } = Pt(d, o, a), m = o, f = 0;
  const h = {};
  for (let g = 0; g < r.length; g++) {
    const w = r[g];
    if (!w)
      continue;
    const {
      name: p,
      fn: v
    } = w, {
      x: y,
      y: x,
      data: b,
      reset: R
    } = await v({
      x: l,
      y: u,
      initialPlacement: o,
      placement: m,
      strategy: i,
      middlewareData: h,
      rects: d,
      platform: c,
      elements: {
        reference: t,
        floating: e
      }
    });
    l = y ?? l, u = x ?? u, h[p] = {
      ...h[p],
      ...b
    }, R && f < ae && (f++, typeof R == "object" && (R.placement && (m = R.placement), R.rects && (d = R.rects === !0 ? await s.getElementRects({
      reference: t,
      floating: e,
      strategy: i
    }) : R.rects), {
      x: l,
      y: u
    } = Pt(d, m, a)), g = -1);
  }
  return {
    x: l,
    y: u,
    placement: m,
    strategy: i,
    middlewareData: h
  };
}, de = (t) => ({
  name: "arrow",
  options: t,
  async fn(e) {
    const {
      x: n,
      y: o,
      placement: i,
      rects: r,
      platform: s,
      elements: c,
      middlewareData: a
    } = e, {
      element: d,
      padding: l = 0
    } = I(t, e) || {};
    if (d == null)
      return {};
    const u = Ht(l), m = {
      x: n,
      y: o
    }, f = Ot(i), h = At(f), g = await s.getDimensions(d), w = f === "y", p = w ? "top" : "left", v = w ? "bottom" : "right", y = w ? "clientHeight" : "clientWidth", x = r.reference[h] + r.reference[f] - m[f] - r.floating[h], b = m[f] - r.reference[f], R = await (s.getOffsetParent == null ? void 0 : s.getOffsetParent(d));
    let O = R ? R[y] : 0;
    (!O || !await (s.isElement == null ? void 0 : s.isElement(R))) && (O = c.floating[y] || r.floating[h]);
    const P = x / 2 - b / 2, W = O / 2 - g[h] / 2 - 1, E = K(u[p], W), B = K(u[v], W), M = E, D = O - g[h] - B, C = O / 2 - g[h] / 2 + P, _ = xt(M, C, D), S = !a.arrow && et(i) != null && C !== _ && r.reference[h] / 2 - (C < M ? E : B) - g[h] / 2 < 0, T = S ? C < M ? C - M : C - D : 0;
    return {
      [f]: m[f] + T,
      data: {
        [f]: _,
        centerOffset: C - _ - T,
        ...S && {
          alignmentOffset: T
        }
      },
      reset: S
    };
  }
}), me = function(t) {
  return t === void 0 && (t = {}), {
    name: "flip",
    options: t,
    async fn(e) {
      var n, o;
      const {
        placement: i,
        middlewareData: r,
        rects: s,
        initialPlacement: c,
        platform: a,
        elements: d
      } = e, {
        mainAxis: l = !0,
        crossAxis: u = !0,
        fallbackPlacements: m,
        fallbackStrategy: f = "bestFit",
        fallbackAxisSideDirection: h = "none",
        flipAlignment: g = !0,
        ...w
      } = I(t, e);
      if ((n = r.arrow) != null && n.alignmentOffset)
        return {};
      const p = X(i), v = V(c), y = X(c) === c, x = await (a.isRTL == null ? void 0 : a.isRTL(d.floating)), b = m || (y || !g ? [ct(c)] : oe(c)), R = h !== "none";
      !m && R && b.push(...ce(c, g, h, x));
      const O = [c, ...b], P = await a.detectOverflow(e, w), W = [];
      let E = ((o = r.flip) == null ? void 0 : o.overflows) || [];
      if (l && W.push(P[p]), u) {
        const C = ne(i, s, x);
        W.push(P[C[0]], P[C[1]]);
      }
      if (E = [...E, {
        placement: i,
        overflows: W
      }], !W.every((C) => C <= 0)) {
        var B, M;
        const C = (((B = r.flip) == null ? void 0 : B.index) || 0) + 1, _ = O[C];
        if (_ && (!(u === "alignment" ? v !== V(_) : !1) || // We leave the current main axis only if every placement on that axis
        // overflows the main axis.
        E.every((A) => V(A.placement) === v ? A.overflows[0] > 0 : !0)))
          return {
            data: {
              index: C,
              overflows: E
            },
            reset: {
              placement: _
            }
          };
        let S = (M = E.filter((T) => T.overflows[0] <= 0).sort((T, A) => T.overflows[1] - A.overflows[1])[0]) == null ? void 0 : M.placement;
        if (!S)
          switch (f) {
            case "bestFit": {
              var D;
              const T = (D = E.filter((A) => {
                if (R) {
                  const k = V(A.placement);
                  return k === v || // Create a bias to the `y` side axis due to horizontal
                  // reading directions favoring greater width.
                  k === "y";
                }
                return !0;
              }).map((A) => [A.placement, A.overflows.filter((k) => k > 0).reduce((k, q) => k + q, 0)]).sort((A, k) => A[1] - k[1])[0]) == null ? void 0 : D[0];
              T && (S = T);
              break;
            }
            case "initialPlacement":
              S = c;
              break;
          }
        if (i !== S)
          return {
            reset: {
              placement: S
            }
          };
      }
      return {};
    }
  };
};
function Dt(t, e) {
  return {
    top: t.top - e.height,
    right: t.right - e.width,
    bottom: t.bottom - e.height,
    left: t.left - e.width
  };
}
function Tt(t) {
  return te.some((e) => t[e] >= 0);
}
const he = function(t) {
  return t === void 0 && (t = {}), {
    name: "hide",
    options: t,
    async fn(e) {
      const {
        rects: n,
        platform: o
      } = e, {
        strategy: i = "referenceHidden",
        ...r
      } = I(t, e);
      switch (i) {
        case "referenceHidden": {
          const s = await o.detectOverflow(e, {
            ...r,
            elementContext: "reference"
          }), c = Dt(s, n.reference);
          return {
            data: {
              referenceHiddenOffsets: c,
              referenceHidden: Tt(c)
            }
          };
        }
        case "escaped": {
          const s = await o.detectOverflow(e, {
            ...r,
            altBoundary: !0
          }), c = Dt(s, n.floating);
          return {
            data: {
              escapedOffsets: c,
              escaped: Tt(c)
            }
          };
        }
        default:
          return {};
      }
    }
  };
}, _t = /* @__PURE__ */ new Set(["left", "top"]);
async function ge(t, e) {
  const {
    placement: n,
    platform: o,
    elements: i
  } = t, r = await (o.isRTL == null ? void 0 : o.isRTL(i.floating)), s = X(n), c = et(n), a = V(n) === "y", d = _t.has(s) ? -1 : 1, l = r && a ? -1 : 1, u = I(e, t);
  let {
    mainAxis: m,
    crossAxis: f,
    alignmentAxis: h
  } = typeof u == "number" ? {
    mainAxis: u,
    crossAxis: 0,
    alignmentAxis: null
  } : {
    mainAxis: u.mainAxis || 0,
    crossAxis: u.crossAxis || 0,
    alignmentAxis: u.alignmentAxis
  };
  return c && typeof h == "number" && (f = c === "end" ? h * -1 : h), a ? {
    x: f * l,
    y: m * d
  } : {
    x: m * d,
    y: f * l
  };
}
const pe = function(t) {
  return t === void 0 && (t = 0), {
    name: "offset",
    options: t,
    async fn(e) {
      var n, o;
      const {
        x: i,
        y: r,
        placement: s,
        middlewareData: c
      } = e, a = await ge(e, t);
      return s === ((n = c.offset) == null ? void 0 : n.placement) && (o = c.arrow) != null && o.alignmentOffset ? {} : {
        x: i + a.x,
        y: r + a.y,
        data: {
          ...a,
          placement: s
        }
      };
    }
  };
}, we = function(t) {
  return t === void 0 && (t = {}), {
    name: "shift",
    options: t,
    async fn(e) {
      const {
        x: n,
        y: o,
        placement: i,
        platform: r
      } = e, {
        mainAxis: s = !0,
        crossAxis: c = !1,
        limiter: a = {
          fn: (p) => {
            let {
              x: v,
              y
            } = p;
            return {
              x: v,
              y
            };
          }
        },
        ...d
      } = I(t, e), l = {
        x: n,
        y: o
      }, u = await r.detectOverflow(e, d), m = V(X(i)), f = Rt(m);
      let h = l[f], g = l[m];
      if (s) {
        const p = f === "y" ? "top" : "left", v = f === "y" ? "bottom" : "right", y = h + u[p], x = h - u[v];
        h = xt(y, h, x);
      }
      if (c) {
        const p = m === "y" ? "top" : "left", v = m === "y" ? "bottom" : "right", y = g + u[p], x = g - u[v];
        g = xt(y, g, x);
      }
      const w = a.fn({
        ...e,
        [f]: h,
        [m]: g
      });
      return {
        ...w,
        data: {
          x: w.x - n,
          y: w.y - o,
          enabled: {
            [f]: s,
            [m]: c
          }
        }
      };
    }
  };
}, xe = function(t) {
  return t === void 0 && (t = {}), {
    options: t,
    fn(e) {
      const {
        x: n,
        y: o,
        placement: i,
        rects: r,
        middlewareData: s
      } = e, {
        offset: c = 0,
        mainAxis: a = !0,
        crossAxis: d = !0
      } = I(t, e), l = {
        x: n,
        y: o
      }, u = V(i), m = Rt(u);
      let f = l[m], h = l[u];
      const g = I(c, e), w = typeof g == "number" ? {
        mainAxis: g,
        crossAxis: 0
      } : {
        mainAxis: 0,
        crossAxis: 0,
        ...g
      };
      if (a) {
        const y = m === "y" ? "height" : "width", x = r.reference[m] - r.floating[y] + w.mainAxis, b = r.reference[m] + r.reference[y] - w.mainAxis;
        f < x ? f = x : f > b && (f = b);
      }
      if (d) {
        var p, v;
        const y = m === "y" ? "width" : "height", x = _t.has(X(i)), b = r.reference[u] - r.floating[y] + (x && ((p = s.offset) == null ? void 0 : p[u]) || 0) + (x ? 0 : w.crossAxis), R = r.reference[u] + r.reference[y] + (x ? 0 : ((v = s.offset) == null ? void 0 : v[u]) || 0) - (x ? w.crossAxis : 0);
        h < b ? h = b : h > R && (h = R);
      }
      return {
        [m]: f,
        [u]: h
      };
    }
  };
}, ye = function(t) {
  return t === void 0 && (t = {}), {
    name: "size",
    options: t,
    async fn(e) {
      var n, o;
      const {
        placement: i,
        rects: r,
        platform: s,
        elements: c
      } = e, {
        apply: a = () => {
        },
        ...d
      } = I(t, e), l = await s.detectOverflow(e, d), u = X(i), m = et(i), f = V(i) === "y", {
        width: h,
        height: g
      } = r.floating;
      let w, p;
      u === "top" || u === "bottom" ? (w = u, p = m === (await (s.isRTL == null ? void 0 : s.isRTL(c.floating)) ? "start" : "end") ? "left" : "right") : (p = u, w = m === "end" ? "top" : "bottom");
      const v = g - l.top - l.bottom, y = h - l.left - l.right, x = K(g - l[w], v), b = K(h - l[p], y), R = !e.middlewareData.shift;
      let O = x, P = b;
      if ((n = e.middlewareData.shift) != null && n.enabled.x && (P = y), (o = e.middlewareData.shift) != null && o.enabled.y && (O = v), R && !m) {
        const E = F(l.left, 0), B = F(l.right, 0), M = F(l.top, 0), D = F(l.bottom, 0);
        f ? P = h - 2 * (E !== 0 || B !== 0 ? E + B : F(l.left, l.right)) : O = g - 2 * (M !== 0 || D !== 0 ? M + D : F(l.top, l.bottom));
      }
      await a({
        ...e,
        availableWidth: P,
        availableHeight: O
      });
      const W = await s.getDimensions(c.floating);
      return h !== W.width || g !== W.height ? {
        reset: {
          rects: !0
        }
      } : {};
    }
  };
};
function Vt(t) {
  const e = H(t);
  let n = parseFloat(e.width) || 0, o = parseFloat(e.height) || 0;
  const i = Y(t), r = i ? t.offsetWidth : n, s = i ? t.offsetHeight : o, c = st(n) !== r || st(o) !== s;
  return c && (n = r, o = s), {
    width: n,
    height: o,
    $: c
  };
}
function Ct(t) {
  return N(t) ? t : t.contextElement;
}
function Q(t) {
  const e = Ct(t);
  if (!Y(e))
    return z(1);
  const n = e.getBoundingClientRect(), {
    width: o,
    height: i,
    $: r
  } = Vt(e);
  let s = (r ? st(n.width) : n.width) / o, c = (r ? st(n.height) : n.height) / i;
  return (!s || !Number.isFinite(s)) && (s = 1), (!c || !Number.isFinite(c)) && (c = 1), {
    x: s,
    y: c
  };
}
const ve = /* @__PURE__ */ z(0);
function zt(t) {
  const e = $(t);
  return !bt() || !e.visualViewport ? ve : {
    x: e.visualViewport.offsetLeft,
    y: e.visualViewport.offsetTop
  };
}
function be(t, e, n) {
  return e === void 0 && (e = !1), !n || e && n !== $(t) ? !1 : e;
}
function J(t, e, n, o) {
  e === void 0 && (e = !1), n === void 0 && (n = !1);
  const i = t.getBoundingClientRect(), r = Ct(t);
  let s = z(1);
  e && (o ? N(o) && (s = Q(o)) : s = Q(t));
  const c = be(r, n, o) ? zt(r) : z(0);
  let a = (i.left + c.x) / s.x, d = (i.top + c.y) / s.y, l = i.width / s.x, u = i.height / s.y;
  if (r) {
    const m = $(r), f = o && N(o) ? $(o) : o;
    let h = m, g = wt(h);
    for (; g && o && f !== h; ) {
      const w = Q(g), p = g.getBoundingClientRect(), v = H(g), y = p.left + (g.clientLeft + parseFloat(v.paddingLeft)) * w.x, x = p.top + (g.clientTop + parseFloat(v.paddingTop)) * w.y;
      a *= w.x, d *= w.y, l *= w.x, u *= w.y, a += y, d += x, h = $(g), g = wt(h);
    }
  }
  return lt({
    width: l,
    height: u,
    x: a,
    y: d
  });
}
function mt(t, e) {
  const n = dt(t).scrollLeft;
  return e ? e.left + n : J(j(t)).left + n;
}
function jt(t, e) {
  const n = t.getBoundingClientRect(), o = n.left + e.scrollLeft - mt(t, n), i = n.top + e.scrollTop;
  return {
    x: o,
    y: i
  };
}
function Re(t) {
  let {
    elements: e,
    rect: n,
    offsetParent: o,
    strategy: i
  } = t;
  const r = i === "fixed", s = j(o), c = e ? ut(e.floating) : !1;
  if (o === s || c && r)
    return n;
  let a = {
    scrollLeft: 0,
    scrollTop: 0
  }, d = z(1);
  const l = z(0), u = Y(o);
  if ((u || !u && !r) && ((tt(o) !== "body" || ot(s)) && (a = dt(o)), u)) {
    const f = J(o);
    d = Q(o), l.x = f.x + o.clientLeft, l.y = f.y + o.clientTop;
  }
  const m = s && !u && !r ? jt(s, a) : z(0);
  return {
    width: n.width * d.x,
    height: n.height * d.y,
    x: n.x * d.x - a.scrollLeft * d.x + l.x + m.x,
    y: n.y * d.y - a.scrollTop * d.y + l.y + m.y
  };
}
function Ae(t) {
  return Array.from(t.getClientRects());
}
function Oe(t) {
  const e = j(t), n = dt(t), o = t.ownerDocument.body, i = F(e.scrollWidth, e.clientWidth, o.scrollWidth, o.clientWidth), r = F(e.scrollHeight, e.clientHeight, o.scrollHeight, o.clientHeight);
  let s = -n.scrollLeft + mt(t);
  const c = -n.scrollTop;
  return H(o).direction === "rtl" && (s += F(e.clientWidth, o.clientWidth) - i), {
    width: i,
    height: r,
    x: s,
    y: c
  };
}
const Mt = 25;
function Ce(t, e) {
  const n = $(t), o = j(t), i = n.visualViewport;
  let r = o.clientWidth, s = o.clientHeight, c = 0, a = 0;
  if (i) {
    r = i.width, s = i.height;
    const l = bt();
    (!l || l && e === "fixed") && (c = i.offsetLeft, a = i.offsetTop);
  }
  const d = mt(o);
  if (d <= 0) {
    const l = o.ownerDocument, u = l.body, m = getComputedStyle(u), f = l.compatMode === "CSS1Compat" && parseFloat(m.marginLeft) + parseFloat(m.marginRight) || 0, h = Math.abs(o.clientWidth - u.clientWidth - f);
    h <= Mt && (r -= h);
  } else d <= Mt && (r += d);
  return {
    width: r,
    height: s,
    x: c,
    y: a
  };
}
function Se(t, e) {
  const n = J(t, !0, e === "fixed"), o = n.top + t.clientTop, i = n.left + t.clientLeft, r = Y(t) ? Q(t) : z(1), s = t.clientWidth * r.x, c = t.clientHeight * r.y, a = i * r.x, d = o * r.y;
  return {
    width: s,
    height: c,
    x: a,
    y: d
  };
}
function kt(t, e, n) {
  let o;
  if (e === "viewport")
    o = Ce(t, n);
  else if (e === "document")
    o = Oe(j(t));
  else if (N(e))
    o = Se(e, n);
  else {
    const i = zt(t);
    o = {
      x: e.x - i.x,
      y: e.y - i.y,
      width: e.width,
      height: e.height
    };
  }
  return lt(o);
}
function It(t, e) {
  const n = U(t);
  return n === e || !N(n) || Z(n) ? !1 : H(n).position === "fixed" || It(n, e);
}
function Ee(t, e) {
  const n = e.get(t);
  if (n)
    return n;
  let o = nt(t, [], !1).filter((c) => N(c) && tt(c) !== "body"), i = null;
  const r = H(t).position === "fixed";
  let s = r ? U(t) : t;
  for (; N(s) && !Z(s); ) {
    const c = H(s), a = vt(s);
    !a && c.position === "fixed" && (i = null), (r ? !a && !i : !a && c.position === "static" && !!i && (i.position === "absolute" || i.position === "fixed") || ot(s) && !a && It(t, s)) ? o = o.filter((l) => l !== s) : i = c, s = U(s);
  }
  return e.set(t, o), o;
}
function Le(t) {
  let {
    element: e,
    boundary: n,
    rootBoundary: o,
    strategy: i
  } = t;
  const s = [...n === "clippingAncestors" ? ut(e) ? [] : Ee(e, this._c) : [].concat(n), o], c = kt(e, s[0], i);
  let a = c.top, d = c.right, l = c.bottom, u = c.left;
  for (let m = 1; m < s.length; m++) {
    const f = kt(e, s[m], i);
    a = F(f.top, a), d = K(f.right, d), l = K(f.bottom, l), u = F(f.left, u);
  }
  return {
    width: d - u,
    height: l - a,
    x: u,
    y: a
  };
}
function Pe(t) {
  const {
    width: e,
    height: n
  } = Vt(t);
  return {
    width: e,
    height: n
  };
}
function De(t, e, n) {
  const o = Y(e), i = j(e), r = n === "fixed", s = J(t, !0, r, e);
  let c = {
    scrollLeft: 0,
    scrollTop: 0
  };
  const a = z(0);
  function d() {
    a.x = mt(i);
  }
  if (o || !o && !r)
    if ((tt(e) !== "body" || ot(i)) && (c = dt(e)), o) {
      const f = J(e, !0, r, e);
      a.x = f.x + e.clientLeft, a.y = f.y + e.clientTop;
    } else i && d();
  r && !o && i && d();
  const l = i && !o && !r ? jt(i, c) : z(0), u = s.left + c.scrollLeft - a.x - l.x, m = s.top + c.scrollTop - a.y - l.y;
  return {
    x: u,
    y: m,
    width: s.width,
    height: s.height
  };
}
function gt(t) {
  return H(t).position === "static";
}
function Ft(t, e) {
  if (!Y(t) || H(t).position === "fixed")
    return null;
  if (e)
    return e(t);
  let n = t.offsetParent;
  return j(t) === n && (n = n.ownerDocument.body), n;
}
function Xt(t, e) {
  const n = $(t);
  if (ut(t))
    return n;
  if (!Y(t)) {
    let i = U(t);
    for (; i && !Z(i); ) {
      if (N(i) && !gt(i))
        return i;
      i = U(i);
    }
    return n;
  }
  let o = Ft(t, e);
  for (; o && Gt(o) && gt(o); )
    o = Ft(o, e);
  return o && Z(o) && gt(o) && !vt(o) ? n : o || Zt(t) || n;
}
const Te = async function(t) {
  const e = this.getOffsetParent || Xt, n = this.getDimensions, o = await n(t.floating);
  return {
    reference: De(t.reference, await e(t.floating), t.strategy),
    floating: {
      x: 0,
      y: 0,
      width: o.width,
      height: o.height
    }
  };
};
function Me(t) {
  return H(t).direction === "rtl";
}
const ke = {
  convertOffsetParentRelativeRectToViewportRelativeRect: Re,
  getDocumentElement: j,
  getClippingRect: Le,
  getOffsetParent: Xt,
  getElementRects: Te,
  getClientRects: Ae,
  getDimensions: Pe,
  getScale: Q,
  isElement: N,
  isRTL: Me
};
function Yt(t, e) {
  return t.x === e.x && t.y === e.y && t.width === e.width && t.height === e.height;
}
function Fe(t, e) {
  let n = null, o;
  const i = j(t);
  function r() {
    var c;
    clearTimeout(o), (c = n) == null || c.disconnect(), n = null;
  }
  function s(c, a) {
    c === void 0 && (c = !1), a === void 0 && (a = 1), r();
    const d = t.getBoundingClientRect(), {
      left: l,
      top: u,
      width: m,
      height: f
    } = d;
    if (c || e(), !m || !f)
      return;
    const h = it(u), g = it(i.clientWidth - (l + m)), w = it(i.clientHeight - (u + f)), p = it(l), y = {
      rootMargin: -h + "px " + -g + "px " + -w + "px " + -p + "px",
      threshold: F(0, K(1, a)) || 1
    };
    let x = !0;
    function b(R) {
      const O = R[0].intersectionRatio;
      if (O !== a) {
        if (!x)
          return s();
        O ? s(!1, O) : o = setTimeout(() => {
          s(!1, 1e-7);
        }, 1e3);
      }
      O === 1 && !Yt(d, t.getBoundingClientRect()) && s(), x = !1;
    }
    try {
      n = new IntersectionObserver(b, {
        ...y,
        // Handle <iframe>s
        root: i.ownerDocument
      });
    } catch {
      n = new IntersectionObserver(b, y);
    }
    n.observe(t);
  }
  return s(!0), r;
}
function Ye(t, e, n, o) {
  o === void 0 && (o = {});
  const {
    ancestorScroll: i = !0,
    ancestorResize: r = !0,
    elementResize: s = typeof ResizeObserver == "function",
    layoutShift: c = typeof IntersectionObserver == "function",
    animationFrame: a = !1
  } = o, d = Ct(t), l = i || r ? [...d ? nt(d) : [], ...e ? nt(e) : []] : [];
  l.forEach((p) => {
    i && p.addEventListener("scroll", n, {
      passive: !0
    }), r && p.addEventListener("resize", n);
  });
  const u = d && c ? Fe(d, n) : null;
  let m = -1, f = null;
  s && (f = new ResizeObserver((p) => {
    let [v] = p;
    v && v.target === d && f && e && (f.unobserve(e), cancelAnimationFrame(m), m = requestAnimationFrame(() => {
      var y;
      (y = f) == null || y.observe(e);
    })), n();
  }), d && !a && f.observe(d), e && f.observe(e));
  let h, g = a ? J(t) : null;
  a && w();
  function w() {
    const p = J(t);
    g && !Yt(g, p) && n(), g = p, h = requestAnimationFrame(w);
  }
  return n(), () => {
    var p;
    l.forEach((v) => {
      i && v.removeEventListener("scroll", n), r && v.removeEventListener("resize", n);
    }), u?.(), (p = f) == null || p.disconnect(), f = null, a && cancelAnimationFrame(h);
  };
}
const $e = pe, We = we, Be = me, Ne = ye, He = he, $t = de, _e = xe, Ve = (t, e, n) => {
  const o = /* @__PURE__ */ new Map(), i = {
    platform: ke,
    ...n
  }, r = {
    ...i.platform,
    _c: o
  };
  return ue(t, e, {
    ...i,
    platform: r
  });
};
var ze = typeof document < "u", je = function() {
}, rt = ze ? Ut : je;
function ft(t, e) {
  if (t === e)
    return !0;
  if (typeof t != typeof e)
    return !1;
  if (typeof t == "function" && t.toString() === e.toString())
    return !0;
  let n, o, i;
  if (t && e && typeof t == "object") {
    if (Array.isArray(t)) {
      if (n = t.length, n !== e.length) return !1;
      for (o = n; o-- !== 0; )
        if (!ft(t[o], e[o]))
          return !1;
      return !0;
    }
    if (i = Object.keys(t), n = i.length, n !== Object.keys(e).length)
      return !1;
    for (o = n; o-- !== 0; )
      if (!{}.hasOwnProperty.call(e, i[o]))
        return !1;
    for (o = n; o-- !== 0; ) {
      const r = i[o];
      if (!(r === "_owner" && t.$$typeof) && !ft(t[r], e[r]))
        return !1;
    }
    return !0;
  }
  return t !== t && e !== e;
}
function qt(t) {
  return typeof window > "u" ? 1 : (t.ownerDocument.defaultView || window).devicePixelRatio || 1;
}
function Wt(t, e) {
  const n = qt(t);
  return Math.round(e * n) / n;
}
function pt(t) {
  const e = L.useRef(t);
  return rt(() => {
    e.current = t;
  }), e;
}
function qe(t) {
  t === void 0 && (t = {});
  const {
    placement: e = "bottom",
    strategy: n = "absolute",
    middleware: o = [],
    platform: i,
    elements: {
      reference: r,
      floating: s
    } = {},
    transform: c = !0,
    whileElementsMounted: a,
    open: d
  } = t, [l, u] = L.useState({
    x: 0,
    y: 0,
    strategy: n,
    placement: e,
    middlewareData: {},
    isPositioned: !1
  }), [m, f] = L.useState(o);
  ft(m, o) || f(o);
  const [h, g] = L.useState(null), [w, p] = L.useState(null), v = L.useCallback((A) => {
    A !== R.current && (R.current = A, g(A));
  }, []), y = L.useCallback((A) => {
    A !== O.current && (O.current = A, p(A));
  }, []), x = r || h, b = s || w, R = L.useRef(null), O = L.useRef(null), P = L.useRef(l), W = a != null, E = pt(a), B = pt(i), M = pt(d), D = L.useCallback(() => {
    if (!R.current || !O.current)
      return;
    const A = {
      placement: e,
      strategy: n,
      middleware: m
    };
    B.current && (A.platform = B.current), Ve(R.current, O.current, A).then((k) => {
      const q = {
        ...k,
        // The floating element's position may be recomputed while it's closed
        // but still mounted (such as when transitioning out). To ensure
        // `isPositioned` will be `false` initially on the next open, avoid
        // setting it to `true` when `open === false` (must be specified).
        isPositioned: M.current !== !1
      };
      C.current && !ft(P.current, q) && (P.current = q, Kt.flushSync(() => {
        u(q);
      }));
    });
  }, [m, e, n, B, M]);
  rt(() => {
    d === !1 && P.current.isPositioned && (P.current.isPositioned = !1, u((A) => ({
      ...A,
      isPositioned: !1
    })));
  }, [d]);
  const C = L.useRef(!1);
  rt(() => (C.current = !0, () => {
    C.current = !1;
  }), []), rt(() => {
    if (x && (R.current = x), b && (O.current = b), x && b) {
      if (E.current)
        return E.current(x, b, D);
      D();
    }
  }, [x, b, D, E, W]);
  const _ = L.useMemo(() => ({
    reference: R,
    floating: O,
    setReference: v,
    setFloating: y
  }), [v, y]), S = L.useMemo(() => ({
    reference: x,
    floating: b
  }), [x, b]), T = L.useMemo(() => {
    const A = {
      position: n,
      left: 0,
      top: 0
    };
    if (!S.floating)
      return A;
    const k = Wt(S.floating, l.x), q = Wt(S.floating, l.y);
    return c ? {
      ...A,
      transform: "translate(" + k + "px, " + q + "px)",
      ...qt(S.floating) >= 1.5 && {
        willChange: "transform"
      }
    } : {
      position: n,
      left: k,
      top: q
    };
  }, [n, c, S.floating, l.x, l.y]);
  return L.useMemo(() => ({
    ...l,
    update: D,
    refs: _,
    elements: S,
    floatingStyles: T
  }), [l, D, _, S, T]);
}
const Ie = (t) => {
  function e(n) {
    return {}.hasOwnProperty.call(n, "current");
  }
  return {
    name: "arrow",
    options: t,
    fn(n) {
      const {
        element: o,
        padding: i
      } = typeof t == "function" ? t(n) : t;
      return o && e(o) ? o.current != null ? $t({
        element: o.current,
        padding: i
      }).fn(n) : {} : o ? $t({
        element: o,
        padding: i
      }).fn(n) : {};
    }
  };
}, Ue = (t, e) => {
  const n = $e(t);
  return {
    name: n.name,
    fn: n.fn,
    options: [t, e]
  };
}, Ke = (t, e) => {
  const n = We(t);
  return {
    name: n.name,
    fn: n.fn,
    options: [t, e]
  };
}, Ge = (t, e) => ({
  fn: _e(t).fn,
  options: [t, e]
}), Je = (t, e) => {
  const n = Be(t);
  return {
    name: n.name,
    fn: n.fn,
    options: [t, e]
  };
}, Qe = (t, e) => {
  const n = Ne(t);
  return {
    name: n.name,
    fn: n.fn,
    options: [t, e]
  };
}, Ze = (t, e) => {
  const n = He(t);
  return {
    name: n.name,
    fn: n.fn,
    options: [t, e]
  };
}, tn = (t, e) => {
  const n = Ie(t);
  return {
    name: n.name,
    fn: n.fn,
    options: [t, e]
  };
};
export {
  St as a,
  N as b,
  bt as c,
  Z as d,
  U as e,
  H as f,
  nt as g,
  Bt as h,
  Y as i,
  tt as j,
  Ye as k,
  Je as l,
  Qe as m,
  tn as n,
  Ue as o,
  Ze as p,
  Ge as q,
  Ke as s,
  qe as u
};
//# sourceMappingURL=floating-ui.react-dom-0ol4sFzt.mjs.map
