"use client";
import * as O from "react";
import { useLayoutEffect as jt } from "react";
import { e as J, g as z, a as X, b as Ut, c as qt, d as Jt, h as Kt, i as ae, m as me, j as _, k as Ot, l as St, r as Ae, s as Gt, n as Et, o as Ie, p as Ct, q as U, f as Re, t as Oe } from "./floating-ui.utils-48URp89E.js";
import { o as Pt } from "./owner-rKN292Q9.js";
import { u as ce } from "./useIsoLayoutEffect-DpJo20by.js";
import { u as We } from "./useValueAsRef-LhoZc6As.js";
import { u as Qt } from "./useStableCallback-CudqoENs.js";
import { u as Zt } from "./DirectionContext-BSOheMwC.js";
import { f as _e, a as k, h as G, g as Q, j as mt, b as K, i as ne, k as Dt, l as ze, m as ge, n as Se, o as en, p as Mt, q as tn, e as Ne, d as Ye, r as Ce } from "./floating-ui.utils.dom-jr2suqy2.js";
import * as nn from "react-dom";
import { u as on, F as sn, P as rn, b as cn, D as ln } from "./popupStateMapping-BT9Y_jIq.js";
import { a as an } from "./useBaseUiId-C8Dq0BQq.js";
import { a as fn, E as un } from "./useRenderElement-DNB2vtF1.js";
function gt(e, t, o) {
  let {
    reference: n,
    floating: i
  } = e;
  const s = X(t), r = Ot(t), c = Et(r), a = z(t), m = s === "y", l = n.x + n.width / 2 - i.width / 2, f = n.y + n.height / 2 - i.height / 2, g = n[c] / 2 - i[c] / 2;
  let u;
  switch (a) {
    case "top":
      u = {
        x: l,
        y: n.y - i.height
      };
      break;
    case "bottom":
      u = {
        x: l,
        y: n.y + n.height
      };
      break;
    case "right":
      u = {
        x: n.x + n.width,
        y: f
      };
      break;
    case "left":
      u = {
        x: n.x - i.width,
        y: f
      };
      break;
    default:
      u = {
        x: n.x,
        y: n.y
      };
  }
  switch (ae(t)) {
    case "start":
      u[r] -= g * (o && m ? -1 : 1);
      break;
    case "end":
      u[r] += g * (o && m ? -1 : 1);
      break;
  }
  return u;
}
async function dn(e, t) {
  var o;
  t === void 0 && (t = {});
  const {
    x: n,
    y: i,
    platform: s,
    rects: r,
    elements: c,
    strategy: a
  } = e, {
    boundary: m = "clippingAncestors",
    rootBoundary: l = "viewport",
    elementContext: f = "floating",
    altBoundary: g = !1,
    padding: u = 0
  } = J(t, e), d = St(u), x = c[g ? f === "floating" ? "reference" : "floating" : f], w = Ae(await s.getClippingRect({
    element: (o = await (s.isElement == null ? void 0 : s.isElement(x))) == null || o ? x : x.contextElement || await (s.getDocumentElement == null ? void 0 : s.getDocumentElement(c.floating)),
    boundary: m,
    rootBoundary: l,
    strategy: a
  })), y = f === "floating" ? {
    x: n,
    y: i,
    width: r.floating.width,
    height: r.floating.height
  } : r.reference, b = await (s.getOffsetParent == null ? void 0 : s.getOffsetParent(c.floating)), R = await (s.isElement == null ? void 0 : s.isElement(b)) ? await (s.getScale == null ? void 0 : s.getScale(b)) || {
    x: 1,
    y: 1
  } : {
    x: 1,
    y: 1
  }, A = Ae(s.convertOffsetParentRelativeRectToViewportRelativeRect ? await s.convertOffsetParentRelativeRectToViewportRelativeRect({
    elements: c,
    rect: y,
    offsetParent: b,
    strategy: a
  }) : y);
  return {
    top: (w.top - A.top + d.top) / R.y,
    bottom: (A.bottom - w.bottom + d.bottom) / R.y,
    left: (w.left - A.left + d.left) / R.x,
    right: (A.right - w.right + d.right) / R.x
  };
}
const mn = 50, gn = async (e, t, o) => {
  const {
    placement: n = "bottom",
    strategy: i = "absolute",
    middleware: s = [],
    platform: r
  } = o, c = r.detectOverflow ? r : {
    ...r,
    detectOverflow: dn
  }, a = await (r.isRTL == null ? void 0 : r.isRTL(t));
  let m = await r.getElementRects({
    reference: e,
    floating: t,
    strategy: i
  }), {
    x: l,
    y: f
  } = gt(m, n, a), g = n, u = 0;
  const d = {};
  for (let h = 0; h < s.length; h++) {
    const x = s[h];
    if (!x)
      continue;
    const {
      name: w,
      fn: y
    } = x, {
      x: b,
      y: R,
      data: A,
      reset: S
    } = await y({
      x: l,
      y: f,
      initialPlacement: n,
      placement: g,
      strategy: i,
      middlewareData: d,
      rects: m,
      platform: c,
      elements: {
        reference: e,
        floating: t
      }
    });
    l = b ?? l, f = R ?? f, d[w] = {
      ...d[w],
      ...A
    }, S && u < mn && (u++, typeof S == "object" && (S.placement && (g = S.placement), S.rects && (m = S.rects === !0 ? await r.getElementRects({
      reference: e,
      floating: t,
      strategy: i
    }) : S.rects), {
      x: l,
      y: f
    } = gt(m, g, a)), h = -1);
  }
  return {
    x: l,
    y: f,
    placement: g,
    strategy: i,
    middlewareData: d
  };
}, hn = function(e) {
  return e === void 0 && (e = {}), {
    name: "flip",
    options: e,
    async fn(t) {
      var o, n;
      const {
        placement: i,
        middlewareData: s,
        rects: r,
        initialPlacement: c,
        platform: a,
        elements: m
      } = t, {
        mainAxis: l = !0,
        crossAxis: f = !0,
        fallbackPlacements: g,
        fallbackStrategy: u = "bestFit",
        fallbackAxisSideDirection: d = "none",
        flipAlignment: h = !0,
        ...x
      } = J(e, t);
      if ((o = s.arrow) != null && o.alignmentOffset)
        return {};
      const w = z(i), y = X(c), b = z(c) === c, R = await (a.isRTL == null ? void 0 : a.isRTL(m.floating)), A = g || (b || !h ? [Ut(c)] : qt(c)), S = d !== "none";
      !g && S && A.push(...Jt(c, h, d, R));
      const v = [c, ...A], E = await a.detectOverflow(t, x), B = [];
      let L = ((n = s.flip) == null ? void 0 : n.overflows) || [];
      if (l && B.push(E[w]), f) {
        const $ = Kt(i, r, R);
        B.push(E[$[0]], E[$[1]]);
      }
      if (L = [...L, {
        placement: i,
        overflows: B
      }], !B.every(($) => $ <= 0)) {
        var H, W;
        const $ = (((H = s.flip) == null ? void 0 : H.index) || 0) + 1, M = v[$];
        if (M && (!(f === "alignment" ? y !== X(M) : !1) || // We leave the current main axis only if every placement on that axis
        // overflows the main axis.
        L.every((p) => X(p.placement) === y ? p.overflows[0] > 0 : !0)))
          return {
            data: {
              index: $,
              overflows: L
            },
            reset: {
              placement: M
            }
          };
        let T = (W = L.filter((F) => F.overflows[0] <= 0).sort((F, p) => F.overflows[1] - p.overflows[1])[0]) == null ? void 0 : W.placement;
        if (!T)
          switch (u) {
            case "bestFit": {
              var D;
              const F = (D = L.filter((p) => {
                if (S) {
                  const P = X(p.placement);
                  return P === y || // Create a bias to the `y` side axis due to horizontal
                  // reading directions favoring greater width.
                  P === "y";
                }
                return !0;
              }).map((p) => [p.placement, p.overflows.filter((P) => P > 0).reduce((P, N) => P + N, 0)]).sort((p, P) => p[1] - P[1])[0]) == null ? void 0 : D[0];
              F && (T = F);
              break;
            }
            case "initialPlacement":
              T = c;
              break;
          }
        if (i !== T)
          return {
            reset: {
              placement: T
            }
          };
      }
      return {};
    }
  };
};
function ht(e, t) {
  return {
    top: e.top - t.height,
    right: e.right - t.width,
    bottom: e.bottom - t.height,
    left: e.left - t.width
  };
}
function pt(e) {
  return Gt.some((t) => e[t] >= 0);
}
const pn = function(e) {
  return e === void 0 && (e = {}), {
    name: "hide",
    options: e,
    async fn(t) {
      const {
        rects: o,
        platform: n
      } = t, {
        strategy: i = "referenceHidden",
        ...s
      } = J(e, t);
      switch (i) {
        case "referenceHidden": {
          const r = await n.detectOverflow(t, {
            ...s,
            elementContext: "reference"
          }), c = ht(r, o.reference);
          return {
            data: {
              referenceHiddenOffsets: c,
              referenceHidden: pt(c)
            }
          };
        }
        case "escaped": {
          const r = await n.detectOverflow(t, {
            ...s,
            altBoundary: !0
          }), c = ht(r, o.floating);
          return {
            data: {
              escapedOffsets: c,
              escaped: pt(c)
            }
          };
        }
        default:
          return {};
      }
    }
  };
}, Tt = /* @__PURE__ */ new Set(["left", "top"]);
async function xn(e, t) {
  const {
    placement: o,
    platform: n,
    elements: i
  } = e, s = await (n.isRTL == null ? void 0 : n.isRTL(i.floating)), r = z(o), c = ae(o), a = X(o) === "y", m = Tt.has(r) ? -1 : 1, l = s && a ? -1 : 1, f = J(t, e);
  let {
    mainAxis: g,
    crossAxis: u,
    alignmentAxis: d
  } = typeof f == "number" ? {
    mainAxis: f,
    crossAxis: 0,
    alignmentAxis: null
  } : {
    mainAxis: f.mainAxis || 0,
    crossAxis: f.crossAxis || 0,
    alignmentAxis: f.alignmentAxis
  };
  return c && typeof d == "number" && (u = c === "end" ? d * -1 : d), a ? {
    x: u * l,
    y: g * m
  } : {
    x: g * m,
    y: u * l
  };
}
const wn = function(e) {
  return e === void 0 && (e = 0), {
    name: "offset",
    options: e,
    async fn(t) {
      var o, n;
      const {
        x: i,
        y: s,
        placement: r,
        middlewareData: c
      } = t, a = await xn(t, e);
      return r === ((o = c.offset) == null ? void 0 : o.placement) && (n = c.arrow) != null && n.alignmentOffset ? {} : {
        x: i + a.x,
        y: s + a.y,
        data: {
          ...a,
          placement: r
        }
      };
    }
  };
}, yn = function(e) {
  return e === void 0 && (e = {}), {
    name: "shift",
    options: e,
    async fn(t) {
      const {
        x: o,
        y: n,
        placement: i,
        platform: s
      } = t, {
        mainAxis: r = !0,
        crossAxis: c = !1,
        limiter: a = {
          fn: (w) => {
            let {
              x: y,
              y: b
            } = w;
            return {
              x: y,
              y: b
            };
          }
        },
        ...m
      } = J(e, t), l = {
        x: o,
        y: n
      }, f = await s.detectOverflow(t, m), g = X(z(i)), u = Ct(g);
      let d = l[u], h = l[g];
      if (r) {
        const w = u === "y" ? "top" : "left", y = u === "y" ? "bottom" : "right", b = d + f[w], R = d - f[y];
        d = Ie(b, d, R);
      }
      if (c) {
        const w = g === "y" ? "top" : "left", y = g === "y" ? "bottom" : "right", b = h + f[w], R = h - f[y];
        h = Ie(b, h, R);
      }
      const x = a.fn({
        ...t,
        [u]: d,
        [g]: h
      });
      return {
        ...x,
        data: {
          x: x.x - o,
          y: x.y - n,
          enabled: {
            [u]: r,
            [g]: c
          }
        }
      };
    }
  };
}, Rn = function(e) {
  return e === void 0 && (e = {}), {
    options: e,
    fn(t) {
      const {
        x: o,
        y: n,
        placement: i,
        rects: s,
        middlewareData: r
      } = t, {
        offset: c = 0,
        mainAxis: a = !0,
        crossAxis: m = !0
      } = J(e, t), l = {
        x: o,
        y: n
      }, f = X(i), g = Ct(f);
      let u = l[g], d = l[f];
      const h = J(c, t), x = typeof h == "number" ? {
        mainAxis: h,
        crossAxis: 0
      } : {
        mainAxis: 0,
        crossAxis: 0,
        ...h
      };
      if (a) {
        const b = g === "y" ? "height" : "width", R = s.reference[g] - s.floating[b] + x.mainAxis, A = s.reference[g] + s.reference[b] - x.mainAxis;
        u < R ? u = R : u > A && (u = A);
      }
      if (m) {
        var w, y;
        const b = g === "y" ? "width" : "height", R = Tt.has(z(i)), A = s.reference[f] - s.floating[b] + (R && ((w = r.offset) == null ? void 0 : w[f]) || 0) + (R ? 0 : x.crossAxis), S = s.reference[f] + s.reference[b] + (R ? 0 : ((y = r.offset) == null ? void 0 : y[f]) || 0) - (R ? x.crossAxis : 0);
        d < A ? d = A : d > S && (d = S);
      }
      return {
        [g]: u,
        [f]: d
      };
    }
  };
}, vn = function(e) {
  return e === void 0 && (e = {}), {
    name: "size",
    options: e,
    async fn(t) {
      var o, n;
      const {
        placement: i,
        rects: s,
        platform: r,
        elements: c
      } = t, {
        apply: a = () => {
        },
        ...m
      } = J(e, t), l = await r.detectOverflow(t, m), f = z(i), g = ae(i), u = X(i) === "y", {
        width: d,
        height: h
      } = s.floating;
      let x, w;
      f === "top" || f === "bottom" ? (x = f, w = g === (await (r.isRTL == null ? void 0 : r.isRTL(c.floating)) ? "start" : "end") ? "left" : "right") : (w = f, x = g === "end" ? "top" : "bottom");
      const y = h - l.top - l.bottom, b = d - l.left - l.right, R = me(h - l[x], y), A = me(d - l[w], b), S = !t.middlewareData.shift;
      let v = R, E = A;
      if ((o = t.middlewareData.shift) != null && o.enabled.x && (E = b), (n = t.middlewareData.shift) != null && n.enabled.y && (v = y), S && !g) {
        const L = _(l.left, 0), H = _(l.right, 0), W = _(l.top, 0), D = _(l.bottom, 0);
        u ? E = d - 2 * (L !== 0 || H !== 0 ? L + H : _(l.left, l.right)) : v = h - 2 * (W !== 0 || D !== 0 ? W + D : _(l.top, l.bottom));
      }
      await a({
        ...t,
        availableWidth: E,
        availableHeight: v
      });
      const B = await r.getDimensions(c.floating);
      return d !== B.width || h !== B.height ? {
        reset: {
          rects: !0
        }
      } : {};
    }
  };
};
function Lt(e) {
  const t = K(e);
  let o = parseFloat(t.width) || 0, n = parseFloat(t.height) || 0;
  const i = ne(e), s = i ? e.offsetWidth : o, r = i ? e.offsetHeight : n, c = Oe(o) !== s || Oe(n) !== r;
  return c && (o = s, n = r), {
    width: o,
    height: n,
    $: c
  };
}
function Xe(e) {
  return k(e) ? e : e.contextElement;
}
function le(e) {
  const t = Xe(e);
  if (!ne(t))
    return U(1);
  const o = t.getBoundingClientRect(), {
    width: n,
    height: i,
    $: s
  } = Lt(t);
  let r = (s ? Oe(o.width) : o.width) / n, c = (s ? Oe(o.height) : o.height) / i;
  return (!r || !Number.isFinite(r)) && (r = 1), (!c || !Number.isFinite(c)) && (c = 1), {
    x: r,
    y: c
  };
}
const bn = /* @__PURE__ */ U(0);
function Ft(e) {
  const t = Q(e);
  return !Dt() || !t.visualViewport ? bn : {
    x: t.visualViewport.offsetLeft,
    y: t.visualViewport.offsetTop
  };
}
function An(e, t, o) {
  return t === void 0 && (t = !1), !o || t && o !== Q(e) ? !1 : t;
}
function te(e, t, o, n) {
  t === void 0 && (t = !1), o === void 0 && (o = !1);
  const i = e.getBoundingClientRect(), s = Xe(e);
  let r = U(1);
  t && (n ? k(n) && (r = le(n)) : r = le(e));
  const c = An(s, o, n) ? Ft(s) : U(0);
  let a = (i.left + c.x) / r.x, m = (i.top + c.y) / r.y, l = i.width / r.x, f = i.height / r.y;
  if (s) {
    const g = Q(s), u = n && k(n) ? Q(n) : n;
    let d = g, h = mt(d);
    for (; h && n && u !== d; ) {
      const x = le(h), w = h.getBoundingClientRect(), y = K(h), b = w.left + (h.clientLeft + parseFloat(y.paddingLeft)) * x.x, R = w.top + (h.clientTop + parseFloat(y.paddingTop)) * x.y;
      a *= x.x, m *= x.y, l *= x.x, f *= x.y, a += b, m += R, d = Q(h), h = mt(d);
    }
  }
  return Ae({
    width: l,
    height: f,
    x: a,
    y: m
  });
}
function Pe(e, t) {
  const o = Ce(e).scrollLeft;
  return t ? t.left + o : te(G(e)).left + o;
}
function kt(e, t) {
  const o = e.getBoundingClientRect(), n = o.left + t.scrollLeft - Pe(e, o), i = o.top + t.scrollTop;
  return {
    x: n,
    y: i
  };
}
function On(e) {
  let {
    elements: t,
    rect: o,
    offsetParent: n,
    strategy: i
  } = e;
  const s = i === "fixed", r = G(n), c = t ? ze(t.floating) : !1;
  if (n === r || c && s)
    return o;
  let a = {
    scrollLeft: 0,
    scrollTop: 0
  }, m = U(1);
  const l = U(0), f = ne(n);
  if ((f || !f && !s) && ((Ne(n) !== "body" || Ye(r)) && (a = Ce(n)), f)) {
    const u = te(n);
    m = le(n), l.x = u.x + n.clientLeft, l.y = u.y + n.clientTop;
  }
  const g = r && !f && !s ? kt(r, a) : U(0);
  return {
    width: o.width * m.x,
    height: o.height * m.y,
    x: o.x * m.x - a.scrollLeft * m.x + l.x + g.x,
    y: o.y * m.y - a.scrollTop * m.y + l.y + g.y
  };
}
function Sn(e) {
  return Array.from(e.getClientRects());
}
function En(e) {
  const t = G(e), o = Ce(e), n = e.ownerDocument.body, i = _(t.scrollWidth, t.clientWidth, n.scrollWidth, n.clientWidth), s = _(t.scrollHeight, t.clientHeight, n.scrollHeight, n.clientHeight);
  let r = -o.scrollLeft + Pe(e);
  const c = -o.scrollTop;
  return K(n).direction === "rtl" && (r += _(t.clientWidth, n.clientWidth) - i), {
    width: i,
    height: s,
    x: r,
    y: c
  };
}
const xt = 25;
function Cn(e, t) {
  const o = Q(e), n = G(e), i = o.visualViewport;
  let s = n.clientWidth, r = n.clientHeight, c = 0, a = 0;
  if (i) {
    s = i.width, r = i.height;
    const l = Dt();
    (!l || l && t === "fixed") && (c = i.offsetLeft, a = i.offsetTop);
  }
  const m = Pe(n);
  if (m <= 0) {
    const l = n.ownerDocument, f = l.body, g = getComputedStyle(f), u = l.compatMode === "CSS1Compat" && parseFloat(g.marginLeft) + parseFloat(g.marginRight) || 0, d = Math.abs(n.clientWidth - f.clientWidth - u);
    d <= xt && (s -= d);
  } else m <= xt && (s += m);
  return {
    width: s,
    height: r,
    x: c,
    y: a
  };
}
function Pn(e, t) {
  const o = te(e, !0, t === "fixed"), n = o.top + e.clientTop, i = o.left + e.clientLeft, s = ne(e) ? le(e) : U(1), r = e.clientWidth * s.x, c = e.clientHeight * s.y, a = i * s.x, m = n * s.y;
  return {
    width: r,
    height: c,
    x: a,
    y: m
  };
}
function wt(e, t, o) {
  let n;
  if (t === "viewport")
    n = Cn(e, o);
  else if (t === "document")
    n = En(G(e));
  else if (k(t))
    n = Pn(t, o);
  else {
    const i = Ft(e);
    n = {
      x: t.x - i.x,
      y: t.y - i.y,
      width: t.width,
      height: t.height
    };
  }
  return Ae(n);
}
function $t(e, t) {
  const o = ge(e);
  return o === t || !k(o) || Se(o) ? !1 : K(o).position === "fixed" || $t(o, t);
}
function Dn(e, t) {
  const o = t.get(e);
  if (o)
    return o;
  let n = _e(e, [], !1).filter((c) => k(c) && Ne(c) !== "body"), i = null;
  const s = K(e).position === "fixed";
  let r = s ? ge(e) : e;
  for (; k(r) && !Se(r); ) {
    const c = K(r), a = Mt(r);
    !a && c.position === "fixed" && (i = null), (s ? !a && !i : !a && c.position === "static" && !!i && (i.position === "absolute" || i.position === "fixed") || Ye(r) && !a && $t(e, r)) ? n = n.filter((l) => l !== r) : i = c, r = ge(r);
  }
  return t.set(e, n), n;
}
function Mn(e) {
  let {
    element: t,
    boundary: o,
    rootBoundary: n,
    strategy: i
  } = e;
  const r = [...o === "clippingAncestors" ? ze(t) ? [] : Dn(t, this._c) : [].concat(o), n], c = wt(t, r[0], i);
  let a = c.top, m = c.right, l = c.bottom, f = c.left;
  for (let g = 1; g < r.length; g++) {
    const u = wt(t, r[g], i);
    a = _(u.top, a), m = me(u.right, m), l = me(u.bottom, l), f = _(u.left, f);
  }
  return {
    width: m - f,
    height: l - a,
    x: f,
    y: a
  };
}
function Tn(e) {
  const {
    width: t,
    height: o
  } = Lt(e);
  return {
    width: t,
    height: o
  };
}
function Ln(e, t, o) {
  const n = ne(t), i = G(t), s = o === "fixed", r = te(e, !0, s, t);
  let c = {
    scrollLeft: 0,
    scrollTop: 0
  };
  const a = U(0);
  function m() {
    a.x = Pe(i);
  }
  if (n || !n && !s)
    if ((Ne(t) !== "body" || Ye(i)) && (c = Ce(t)), n) {
      const u = te(t, !0, s, t);
      a.x = u.x + t.clientLeft, a.y = u.y + t.clientTop;
    } else i && m();
  s && !n && i && m();
  const l = i && !n && !s ? kt(i, c) : U(0), f = r.left + c.scrollLeft - a.x - l.x, g = r.top + c.scrollTop - a.y - l.y;
  return {
    x: f,
    y: g,
    width: r.width,
    height: r.height
  };
}
function Be(e) {
  return K(e).position === "static";
}
function yt(e, t) {
  if (!ne(e) || K(e).position === "fixed")
    return null;
  if (t)
    return t(e);
  let o = e.offsetParent;
  return G(e) === o && (o = o.ownerDocument.body), o;
}
function Ht(e, t) {
  const o = Q(e);
  if (ze(e))
    return o;
  if (!ne(e)) {
    let i = ge(e);
    for (; i && !Se(i); ) {
      if (k(i) && !Be(i))
        return i;
      i = ge(i);
    }
    return o;
  }
  let n = yt(e, t);
  for (; n && en(n) && Be(n); )
    n = yt(n, t);
  return n && Se(n) && Be(n) && !Mt(n) ? o : n || tn(e) || o;
}
const Fn = async function(e) {
  const t = this.getOffsetParent || Ht, o = this.getDimensions, n = await o(e.floating);
  return {
    reference: Ln(e.reference, await t(e.floating), e.strategy),
    floating: {
      x: 0,
      y: 0,
      width: n.width,
      height: n.height
    }
  };
};
function kn(e) {
  return K(e).direction === "rtl";
}
const $n = {
  convertOffsetParentRelativeRectToViewportRelativeRect: On,
  getDocumentElement: G,
  getClippingRect: Mn,
  getOffsetParent: Ht,
  getElementRects: Fn,
  getClientRects: Sn,
  getDimensions: Tn,
  getScale: le,
  isElement: k,
  isRTL: kn
};
function Wt(e, t) {
  return e.x === t.x && e.y === t.y && e.width === t.width && e.height === t.height;
}
function Hn(e, t) {
  let o = null, n;
  const i = G(e);
  function s() {
    var c;
    clearTimeout(n), (c = o) == null || c.disconnect(), o = null;
  }
  function r(c, a) {
    c === void 0 && (c = !1), a === void 0 && (a = 1), s();
    const m = e.getBoundingClientRect(), {
      left: l,
      top: f,
      width: g,
      height: u
    } = m;
    if (c || t(), !g || !u)
      return;
    const d = Re(f), h = Re(i.clientWidth - (l + g)), x = Re(i.clientHeight - (f + u)), w = Re(l), b = {
      rootMargin: -d + "px " + -h + "px " + -x + "px " + -w + "px",
      threshold: _(0, me(1, a)) || 1
    };
    let R = !0;
    function A(S) {
      const v = S[0].intersectionRatio;
      if (v !== a) {
        if (!R)
          return r();
        v ? r(!1, v) : n = setTimeout(() => {
          r(!1, 1e-7);
        }, 1e3);
      }
      v === 1 && !Wt(m, e.getBoundingClientRect()) && r(), R = !1;
    }
    try {
      o = new IntersectionObserver(A, {
        ...b,
        // Handle <iframe>s
        root: i.ownerDocument
      });
    } catch {
      o = new IntersectionObserver(A, b);
    }
    o.observe(e);
  }
  return r(!0), s;
}
function Rt(e, t, o, n) {
  n === void 0 && (n = {});
  const {
    ancestorScroll: i = !0,
    ancestorResize: s = !0,
    elementResize: r = typeof ResizeObserver == "function",
    layoutShift: c = typeof IntersectionObserver == "function",
    animationFrame: a = !1
  } = n, m = Xe(e), l = i || s ? [...m ? _e(m) : [], ...t ? _e(t) : []] : [];
  l.forEach((w) => {
    i && w.addEventListener("scroll", o, {
      passive: !0
    }), s && w.addEventListener("resize", o);
  });
  const f = m && c ? Hn(m, o) : null;
  let g = -1, u = null;
  r && (u = new ResizeObserver((w) => {
    let [y] = w;
    y && y.target === m && u && t && (u.unobserve(t), cancelAnimationFrame(g), g = requestAnimationFrame(() => {
      var b;
      (b = u) == null || b.observe(t);
    })), o();
  }), m && !a && u.observe(m), t && u.observe(t));
  let d, h = a ? te(e) : null;
  a && x();
  function x() {
    const w = te(e);
    h && !Wt(h, w) && o(), h = w, d = requestAnimationFrame(x);
  }
  return o(), () => {
    var w;
    l.forEach((y) => {
      i && y.removeEventListener("scroll", o), s && y.removeEventListener("resize", o);
    }), f?.(), (w = u) == null || w.disconnect(), u = null, a && cancelAnimationFrame(d);
  };
}
const Wn = wn, Bn = yn, Vn = hn, In = vn, _n = pn, zn = Rn, Nn = (e, t, o) => {
  const n = /* @__PURE__ */ new Map(), i = {
    platform: $n,
    ...o
  }, s = {
    ...i.platform,
    _c: n
  };
  return gn(e, t, {
    ...i,
    platform: s
  });
};
var Yn = typeof document < "u", Xn = function() {
}, ve = Yn ? jt : Xn;
function Ee(e, t) {
  if (e === t)
    return !0;
  if (typeof e != typeof t)
    return !1;
  if (typeof e == "function" && e.toString() === t.toString())
    return !0;
  let o, n, i;
  if (e && t && typeof e == "object") {
    if (Array.isArray(e)) {
      if (o = e.length, o !== t.length) return !1;
      for (n = o; n-- !== 0; )
        if (!Ee(e[n], t[n]))
          return !1;
      return !0;
    }
    if (i = Object.keys(e), o = i.length, o !== Object.keys(t).length)
      return !1;
    for (n = o; n-- !== 0; )
      if (!{}.hasOwnProperty.call(t, i[n]))
        return !1;
    for (n = o; n-- !== 0; ) {
      const s = i[n];
      if (!(s === "_owner" && e.$$typeof) && !Ee(e[s], t[s]))
        return !1;
    }
    return !0;
  }
  return e !== e && t !== t;
}
function Bt(e) {
  return typeof window > "u" ? 1 : (e.ownerDocument.defaultView || window).devicePixelRatio || 1;
}
function vt(e, t) {
  const o = Bt(e);
  return Math.round(t * o) / o;
}
function Ve(e) {
  const t = O.useRef(e);
  return ve(() => {
    t.current = e;
  }), t;
}
function jn(e) {
  e === void 0 && (e = {});
  const {
    placement: t = "bottom",
    strategy: o = "absolute",
    middleware: n = [],
    platform: i,
    elements: {
      reference: s,
      floating: r
    } = {},
    transform: c = !0,
    whileElementsMounted: a,
    open: m
  } = e, [l, f] = O.useState({
    x: 0,
    y: 0,
    strategy: o,
    placement: t,
    middlewareData: {},
    isPositioned: !1
  }), [g, u] = O.useState(n);
  Ee(g, n) || u(n);
  const [d, h] = O.useState(null), [x, w] = O.useState(null), y = O.useCallback((p) => {
    p !== S.current && (S.current = p, h(p));
  }, []), b = O.useCallback((p) => {
    p !== v.current && (v.current = p, w(p));
  }, []), R = s || d, A = r || x, S = O.useRef(null), v = O.useRef(null), E = O.useRef(l), B = a != null, L = Ve(a), H = Ve(i), W = Ve(m), D = O.useCallback(() => {
    if (!S.current || !v.current)
      return;
    const p = {
      placement: t,
      strategy: o,
      middleware: g
    };
    H.current && (p.platform = H.current), Nn(S.current, v.current, p).then((P) => {
      const N = {
        ...P,
        // 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: W.current !== !1
      };
      $.current && !Ee(E.current, N) && (E.current = N, nn.flushSync(() => {
        f(N);
      }));
    });
  }, [g, t, o, H, W]);
  ve(() => {
    m === !1 && E.current.isPositioned && (E.current.isPositioned = !1, f((p) => ({
      ...p,
      isPositioned: !1
    })));
  }, [m]);
  const $ = O.useRef(!1);
  ve(() => ($.current = !0, () => {
    $.current = !1;
  }), []), ve(() => {
    if (R && (S.current = R), A && (v.current = A), R && A) {
      if (L.current)
        return L.current(R, A, D);
      D();
    }
  }, [R, A, D, L, B]);
  const M = O.useMemo(() => ({
    reference: S,
    floating: v,
    setReference: y,
    setFloating: b
  }), [y, b]), T = O.useMemo(() => ({
    reference: R,
    floating: A
  }), [R, A]), F = O.useMemo(() => {
    const p = {
      position: o,
      left: 0,
      top: 0
    };
    if (!T.floating)
      return p;
    const P = vt(T.floating, l.x), N = vt(T.floating, l.y);
    return c ? {
      ...p,
      transform: "translate(" + P + "px, " + N + "px)",
      ...Bt(T.floating) >= 1.5 && {
        willChange: "transform"
      }
    } : {
      position: o,
      left: P,
      top: N
    };
  }, [o, c, T.floating, l.x, l.y]);
  return O.useMemo(() => ({
    ...l,
    update: D,
    refs: M,
    elements: T,
    floatingStyles: F
  }), [l, D, M, T, F]);
}
const Un = (e, t) => {
  const o = Wn(e);
  return {
    name: o.name,
    fn: o.fn,
    options: [e, t]
  };
}, qn = (e, t) => {
  const o = Bn(e);
  return {
    name: o.name,
    fn: o.fn,
    options: [e, t]
  };
}, Jn = (e, t) => ({
  fn: zn(e).fn,
  options: [e, t]
}), Kn = (e, t) => {
  const o = Vn(e);
  return {
    name: o.name,
    fn: o.fn,
    options: [e, t]
  };
}, Gn = (e, t) => {
  const o = In(e);
  return {
    name: o.name,
    fn: o.fn,
    options: [e, t]
  };
}, Qn = (e, t) => {
  const o = _n(e);
  return {
    name: o.name,
    fn: o.fn,
    options: [e, t]
  };
};
function Zn(e) {
  const {
    open: t = !1,
    onOpenChange: o,
    elements: n = {}
  } = e, i = an(), s = on() != null;
  if (process.env.NODE_ENV !== "production") {
    const c = n.reference;
    c && !k(c) && console.error("Cannot pass a virtual element to the `elements.reference` option,", "as it must be a real DOM element. Use `context.setPositionReference()`", "instead.");
  }
  const r = fn(() => new sn({
    open: t,
    onOpenChange: o,
    referenceElement: n.reference ?? null,
    floatingElement: n.floating ?? null,
    triggerElements: new rn(),
    floatingId: i,
    nested: s,
    noEmit: !1
  })).current;
  return ce(() => {
    const c = {
      open: t,
      floatingId: i
    };
    n.reference !== void 0 && (c.referenceElement = n.reference, c.domReferenceElement = k(n.reference) ? n.reference : null), n.floating !== void 0 && (c.floatingElement = n.floating), r.update(c);
  }, [t, i, n.reference, n.floating, r]), r.context.onOpenChange = o, r.context.nested = s, r.context.noEmit = !1, r;
}
function eo(e = {}) {
  const {
    nodeId: t,
    externalTree: o
  } = e, n = Zn(e), i = e.rootContext || n, s = {
    reference: i.useState("referenceElement"),
    floating: i.useState("floatingElement"),
    domReference: i.useState("domReferenceElement")
  }, [r, c] = O.useState(null), a = O.useRef(null), m = cn(o);
  ce(() => {
    s.domReference && (a.current = s.domReference);
  }, [s.domReference]);
  const l = jn({
    ...e,
    elements: {
      ...s,
      ...r && {
        reference: r
      }
    }
  }), f = O.useCallback((v) => {
    const E = k(v) ? {
      getBoundingClientRect: () => v.getBoundingClientRect(),
      getClientRects: () => v.getClientRects(),
      contextElement: v
    } : v;
    c(E), l.refs.setReference(E);
  }, [l.refs]), [g, u] = O.useState(null), [d, h] = O.useState(null);
  i.useSyncedValue("referenceElement", g), i.useSyncedValue("domReferenceElement", k(g) ? g : null), i.useSyncedValue("floatingElement", d);
  const x = O.useCallback((v) => {
    (k(v) || v === null) && (a.current = v, u(v)), (k(l.refs.reference.current) || l.refs.reference.current === null || // Don't allow setting virtual elements using the old technique back to
    // `null` to support `positionReference` + an unstable `reference`
    // callback ref.
    v !== null && !k(v)) && l.refs.setReference(v);
  }, [l.refs, u]), w = O.useCallback((v) => {
    h(v), l.refs.setFloating(v);
  }, [l.refs]), y = O.useMemo(() => ({
    ...l.refs,
    setReference: x,
    setFloating: w,
    setPositionReference: f,
    domReference: a
  }), [l.refs, x, w, f]), b = O.useMemo(() => ({
    ...l.elements,
    domReference: s.domReference
  }), [l.elements, s.domReference]), R = i.useState("open"), A = i.useState("floatingId"), S = O.useMemo(() => ({
    ...l,
    dataRef: i.context.dataRef,
    open: R,
    onOpenChange: i.setOpen,
    events: i.context.events,
    floatingId: A,
    refs: y,
    elements: b,
    nodeId: t,
    rootStore: i
  }), [l, y, b, t, i, R, A]);
  return ce(() => {
    i.context.dataRef.current.floatingContext = S;
    const v = m?.nodesRef.current.find((E) => E.id === t);
    v && (v.context = S);
  }), O.useMemo(() => ({
    ...l,
    context: S,
    refs: y,
    elements: b,
    rootStore: i
  }), [l, y, b, S, i]);
}
const to = (e) => ({
  name: "arrow",
  options: e,
  async fn(t) {
    const {
      x: o,
      y: n,
      placement: i,
      rects: s,
      platform: r,
      elements: c,
      middlewareData: a
    } = t, {
      element: m,
      padding: l = 0,
      offsetParent: f = "real"
    } = J(e, t) || {};
    if (m == null)
      return {};
    const g = St(l), u = {
      x: o,
      y: n
    }, d = Ot(i), h = Et(d), x = await r.getDimensions(m), w = d === "y", y = w ? "top" : "left", b = w ? "bottom" : "right", R = w ? "clientHeight" : "clientWidth", A = s.reference[h] + s.reference[d] - u[d] - s.floating[h], S = u[d] - s.reference[d], v = f === "real" ? await r.getOffsetParent?.(m) : c.floating;
    let E = c.floating[R] || s.floating[h];
    (!E || !await r.isElement?.(v)) && (E = c.floating[R] || s.floating[h]);
    const B = A / 2 - S / 2, L = E / 2 - x[h] / 2 - 1, H = Math.min(g[y], L), W = Math.min(g[b], L), D = H, $ = E - x[h] - W, M = E / 2 - x[h] / 2 + B, T = Ie(D, M, $), F = !a.arrow && ae(i) != null && M !== T && s.reference[h] / 2 - (M < D ? H : W) - x[h] / 2 < 0, p = F ? M < D ? M - D : M - $ : 0;
    return {
      [d]: u[d] + p,
      data: {
        [d]: T,
        centerOffset: M - T - p,
        ...F && {
          alignmentOffset: p
        }
      },
      reset: F
    };
  }
}), no = (e, t) => ({
  ...to(e),
  options: [e, t]
}), oo = {
  name: "hide",
  async fn(e) {
    const {
      width: t,
      height: o,
      x: n,
      y: i
    } = e.rects.reference, s = t === 0 && o === 0 && n === 0 && i === 0;
    return {
      data: {
        referenceHidden: (await Qn().fn(e)).data?.referenceHidden || s
      }
    };
  }
}, be = {
  sideX: "left",
  sideY: "top"
}, wo = {
  name: "adaptiveOrigin",
  async fn(e) {
    const {
      x: t,
      y: o,
      rects: {
        floating: n
      },
      elements: {
        floating: i
      },
      platform: s,
      strategy: r,
      placement: c
    } = e, a = Q(i), m = a.getComputedStyle(i);
    if (!(m.transitionDuration !== "0s" && m.transitionDuration !== ""))
      return {
        x: t,
        y: o,
        data: be
      };
    const f = await s.getOffsetParent?.(i);
    let g = {
      width: 0,
      height: 0
    };
    if (r === "fixed" && a?.visualViewport)
      g = {
        width: a.visualViewport.width,
        height: a.visualViewport.height
      };
    else if (f === a) {
      const y = Pt(i);
      g = {
        width: y.documentElement.clientWidth,
        height: y.documentElement.clientHeight
      };
    } else await s.isElement?.(f) && (g = await s.getDimensions(f));
    const u = z(c);
    let d = t, h = o;
    u === "left" && (d = g.width - (t + n.width)), u === "top" && (h = g.height - (o + n.height));
    const x = u === "left" ? "right" : be.sideX, w = u === "top" ? "bottom" : be.sideY;
    return {
      x: d,
      y: h,
      data: {
        sideX: x,
        sideY: w
      }
    };
  }
};
function Vt(e, t, o) {
  const n = e === "inline-start" || e === "inline-end";
  return {
    top: "top",
    right: n ? o ? "inline-start" : "inline-end" : "right",
    bottom: "bottom",
    left: n ? o ? "inline-end" : "inline-start" : "left"
  }[t];
}
function bt(e, t, o) {
  const {
    rects: n,
    placement: i
  } = e;
  return {
    side: Vt(t, z(i), o),
    align: ae(i) || "center",
    anchor: {
      width: n.reference.width,
      height: n.reference.height
    },
    positioner: {
      width: n.floating.width,
      height: n.floating.height
    }
  };
}
function yo(e) {
  const {
    // Public parameters
    anchor: t,
    positionMethod: o = "absolute",
    side: n = "bottom",
    sideOffset: i = 0,
    align: s = "center",
    alignOffset: r = 0,
    collisionBoundary: c,
    collisionPadding: a = 5,
    sticky: m = !1,
    arrowPadding: l = 5,
    disableAnchorTracking: f = !1,
    // Private parameters
    keepMounted: g = !1,
    floatingRootContext: u,
    mounted: d,
    collisionAvoidance: h,
    shiftCrossAxis: x = !1,
    nodeId: w,
    adaptiveOrigin: y,
    lazyFlip: b = !1,
    externalTree: R
  } = e, [A, S] = O.useState(null);
  !d && A !== null && S(null);
  const v = h.side || "flip", E = h.align || "flip", B = h.fallbackAxisSide || "end", L = typeof t == "function" ? t : void 0, H = Qt(L), W = L ? H : t, D = We(t), M = Zt() === "rtl", T = A || {
    top: "top",
    right: "right",
    bottom: "bottom",
    left: "left",
    "inline-end": M ? "left" : "right",
    "inline-start": M ? "right" : "left"
  }[n], F = s === "center" ? T : `${T}-${s}`;
  let p = a;
  const P = 1, N = n === "bottom" ? P : 0, je = n === "top" ? P : 0, Ue = n === "right" ? P : 0, qe = n === "left" ? P : 0;
  typeof p == "number" ? p = {
    top: p + N,
    right: p + qe,
    bottom: p + je,
    left: p + Ue
  } : p && (p = {
    top: (p.top || 0) + N,
    right: (p.right || 0) + qe,
    bottom: (p.bottom || 0) + je,
    left: (p.left || 0) + Ue
  });
  const he = {
    boundary: c === "clipping-ancestors" ? "clippingAncestors" : c,
    padding: p
  }, oe = O.useRef(null), De = We(i), Me = We(r), pe = [Un((C) => {
    const V = bt(C, n, M), j = typeof De.current == "function" ? De.current(V) : De.current, I = typeof Me.current == "function" ? Me.current(V) : Me.current;
    return {
      mainAxis: j,
      crossAxis: I,
      alignmentAxis: I
    };
  }, [typeof i != "function" ? i : 0, typeof r != "function" ? r : 0, M, n])], Je = E === "none" && v !== "shift", Ke = !Je && (m || x || v === "shift"), Ge = v === "none" ? null : Kn({
    ...he,
    // Ensure the popup flips if it's been limited by its --available-height and it resizes.
    // Since the size() padding is smaller than the flip() padding, flip() will take precedence.
    padding: {
      top: p.top + P,
      right: p.right + P,
      bottom: p.bottom + P,
      left: p.left + P
    },
    mainAxis: !x && v === "flip",
    crossAxis: E === "flip" ? "alignment" : !1,
    fallbackAxisSideDirection: B
  }), Qe = Je ? null : qn((C) => {
    const V = Pt(C.elements.floating).documentElement;
    return {
      ...he,
      // Use the Layout Viewport to avoid shifting around when pinch-zooming
      // for context menus.
      rootBoundary: x ? {
        x: 0,
        y: 0,
        width: V.clientWidth,
        height: V.clientHeight
      } : void 0,
      mainAxis: E !== "none",
      crossAxis: Ke,
      limiter: m || x ? void 0 : Jn((j) => {
        if (!oe.current)
          return {};
        const {
          width: I,
          height: q
        } = oe.current.getBoundingClientRect(), Y = X(z(j.placement)), ee = Y === "y" ? I : q, re = Y === "y" ? p.left + p.right : p.top + p.bottom;
        return {
          offset: ee / 2 + re / 2
        };
      })
    };
  }, [he, m, x, p, E]);
  v === "shift" || E === "shift" || s === "center" ? pe.push(Qe, Ge) : pe.push(Ge, Qe), pe.push(Gn({
    ...he,
    apply({
      elements: {
        floating: C
      },
      availableWidth: V,
      availableHeight: j,
      rects: I
    }) {
      const q = C.style;
      q.setProperty("--available-width", `${V}px`), q.setProperty("--available-height", `${j}px`);
      const Y = window.devicePixelRatio || 1, {
        x: ee,
        y: re,
        width: ye,
        height: Fe
      } = I.reference, ke = (Math.round((ee + ye) * Y) - Math.round(ee * Y)) / Y, $e = (Math.round((re + Fe) * Y) - Math.round(re * Y)) / Y;
      q.setProperty("--anchor-width", `${ke}px`), q.setProperty("--anchor-height", `${$e}px`);
    }
  }), no(() => ({
    // `transform-origin` calculations rely on an element existing. If the arrow hasn't been set,
    // we'll create a fake element.
    element: oe.current || document.createElement("div"),
    padding: l,
    offsetParent: "floating"
  }), [l]), {
    name: "transformOrigin",
    fn(C) {
      const {
        elements: V,
        middlewareData: j,
        placement: I,
        rects: q,
        y: Y
      } = C, ee = z(I), re = X(ee), ye = oe.current, Fe = j.arrow?.x || 0, ke = j.arrow?.y || 0, $e = ye?.clientWidth || 0, It = ye?.clientHeight || 0, He = Fe + $e / 2, dt = ke + It / 2, _t = Math.abs(j.shift?.y || 0), zt = q.reference.height / 2, de = typeof i == "function" ? i(bt(C, n, M)) : i, Nt = _t > de, Yt = {
        top: `${He}px calc(100% + ${de}px)`,
        bottom: `${He}px ${-de}px`,
        left: `calc(100% + ${de}px) ${dt}px`,
        right: `${-de}px ${dt}px`
      }[ee], Xt = `${He}px ${q.reference.y + zt - Y}px`;
      return V.floating.style.setProperty("--transform-origin", Ke && re === "y" && Nt ? Xt : Yt), {};
    }
  }, oo, y), ce(() => {
    !d && u && u.update({
      referenceElement: null,
      floatingElement: null,
      domReferenceElement: null
    });
  }, [d, u]);
  const Te = O.useMemo(() => ({
    elementResize: !f && typeof ResizeObserver < "u",
    layoutShift: !f && typeof IntersectionObserver < "u"
  }), [f]), {
    refs: ie,
    elements: fe,
    x: Ze,
    y: et,
    middlewareData: se,
    update: xe,
    placement: tt,
    context: nt,
    isPositioned: Z,
    floatingStyles: ot
  } = eo({
    rootContext: u,
    placement: F,
    middleware: pe,
    strategy: o,
    whileElementsMounted: g ? void 0 : (...C) => Rt(...C, Te),
    nodeId: w,
    externalTree: R
  }), {
    sideX: it,
    sideY: st
  } = se.adaptiveOrigin || be, Le = Z ? o : "fixed", rt = O.useMemo(() => {
    const C = y ? {
      position: Le,
      [it]: Ze,
      [st]: et
    } : {
      position: Le,
      ...ot
    };
    return Z || (C.opacity = 0), C;
  }, [y, Le, it, Ze, st, et, ot, Z]), we = O.useRef(null);
  ce(() => {
    if (!d)
      return;
    const C = D.current, V = typeof C == "function" ? C() : C, I = (At(V) ? V.current : V) || null || null;
    I !== we.current && (ie.setPositionReference(I), we.current = I);
  }, [d, ie, W, D]), O.useEffect(() => {
    if (!d)
      return;
    const C = D.current;
    typeof C != "function" && At(C) && C.current !== we.current && (ie.setPositionReference(C.current), we.current = C.current);
  }, [d, ie, W, D]), O.useEffect(() => {
    if (g && d && fe.domReference && fe.floating)
      return Rt(fe.domReference, fe.floating, xe, Te);
  }, [g, d, fe, xe, Te]);
  const ue = z(tt), ct = Vt(n, ue, M), lt = ae(tt) || "center", at = !!se.hide?.referenceHidden;
  ce(() => {
    b && d && Z && S(ue);
  }, [b, d, Z, ue]);
  const ft = O.useMemo(() => ({
    position: "absolute",
    top: se.arrow?.y,
    left: se.arrow?.x
  }), [se.arrow]), ut = se.arrow?.centerOffset !== 0;
  return O.useMemo(() => ({
    positionerStyles: rt,
    arrowStyles: ft,
    arrowRef: oe,
    arrowUncentered: ut,
    side: ct,
    align: lt,
    physicalSide: ue,
    anchorHidden: at,
    refs: ie,
    context: nt,
    isPositioned: Z,
    update: xe
  }), [rt, ft, oe, ut, ct, lt, ue, at, ie, nt, Z, xe]);
}
function At(e) {
  return e != null && "current" in e;
}
function Ro(e) {
  return e === "starting" ? ln : un;
}
export {
  wo as a,
  Zn as b,
  Ro as g,
  $n as p,
  yo as u
};
