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

//# sourceMappingURL=usePositioner.js.map