import * as m from "react";
import { useLayoutEffect as ot, useEffect as it, useRef as Mt } from "react";
import { j as Lt, k as De, p as je, l as Ft, m as xe, n as Q, o as st, q as Dt, r as Nt, s as ve, t as kt, v as Bt, w as Ie, x as k, y as _, z, B as ee, E as qe, F as U, G as X, J as he, K as Ne, L as ae, M as pe, N as Vt, O as lt, Q as Wt, S as oe, U as Ae, V as ke, W as Be, X as Re, Y as fe, Z as ct } from "./theme.BGpzuiJ2.js";
import { jsxs as $t, jsx as de } from "react/jsx-runtime";
import * as at from "react-dom";
function jt(t) {
  let e = t.activeElement;
  for (; ((n = e) == null || (n = n.shadowRoot) == null ? void 0 : n.activeElement) != null; ) {
    var n;
    e = e.shadowRoot.activeElement;
  }
  return e;
}
function ce(t, e) {
  if (!t || !e)
    return !1;
  const n = e.getRootNode == null ? void 0 : e.getRootNode();
  if (t.contains(e))
    return !0;
  if (n && Lt(n)) {
    let r = e;
    for (; r; ) {
      if (t === r)
        return !0;
      r = r.parentNode || r.host;
    }
  }
  return !1;
}
function qt() {
  return /apple/i.test(navigator.vendor);
}
function Me(t, e) {
  const n = ["mouse", "pen"];
  return n.push("", void 0), n.includes(t);
}
function le(t) {
  return (t == null ? void 0 : t.ownerDocument) || document;
}
function Yt(t) {
  return "composedPath" in t ? t.composedPath()[0] : t.target;
}
/*!
* tabbable 6.2.0
* @license MIT, https://github.com/focus-trap/tabbable/blob/master/LICENSE
*/
var zt = ["input:not([inert])", "select:not([inert])", "textarea:not([inert])", "a[href]:not([inert])", "button:not([inert])", "[tabindex]:not(slot):not([inert])", "audio[controls]:not([inert])", "video[controls]:not([inert])", '[contenteditable]:not([contenteditable="false"]):not([inert])', "details>summary:first-of-type:not([inert])", "details:not([inert])"], Le = /* @__PURE__ */ zt.join(","), ut = typeof Element > "u", ue = ut ? function() {
} : Element.prototype.matches || Element.prototype.msMatchesSelector || Element.prototype.webkitMatchesSelector, be = !ut && Element.prototype.getRootNode ? function(t) {
  var e;
  return t == null || (e = t.getRootNode) === null || e === void 0 ? void 0 : e.call(t);
} : function(t) {
  return t == null ? void 0 : t.ownerDocument;
}, ye = function t(e, n) {
  var r;
  n === void 0 && (n = !0);
  var o = e == null || (r = e.getAttribute) === null || r === void 0 ? void 0 : r.call(e, "inert"), s = o === "" || o === "true", i = s || n && e && t(e.parentNode);
  return i;
}, Ht = function(e) {
  var n, r = e == null || (n = e.getAttribute) === null || n === void 0 ? void 0 : n.call(e, "contenteditable");
  return r === "" || r === "true";
}, Ut = function(e, n, r) {
  if (ye(e))
    return [];
  var o = Array.prototype.slice.apply(e.querySelectorAll(Le));
  return n && ue.call(e, Le) && o.unshift(e), o = o.filter(r), o;
}, _t = function t(e, n, r) {
  for (var o = [], s = Array.from(e); s.length; ) {
    var i = s.shift();
    if (!ye(i, !1))
      if (i.tagName === "SLOT") {
        var l = i.assignedElements(), c = l.length ? l : i.children, a = t(c, !0, r);
        r.flatten ? o.push.apply(o, a) : o.push({
          scopeParent: i,
          candidates: a
        });
      } else {
        var f = ue.call(i, Le);
        f && r.filter(i) && (n || !e.includes(i)) && o.push(i);
        var d = i.shadowRoot || // check for an undisclosed shadow
        typeof r.getShadowRoot == "function" && r.getShadowRoot(i), v = !ye(d, !1) && (!r.shadowRootFilter || r.shadowRootFilter(i));
        if (d && v) {
          var u = t(d === !0 ? i.children : d.children, !0, r);
          r.flatten ? o.push.apply(o, u) : o.push({
            scopeParent: i,
            candidates: u
          });
        } else
          s.unshift.apply(s, i.children);
      }
  }
  return o;
}, ft = function(e) {
  return !isNaN(parseInt(e.getAttribute("tabindex"), 10));
}, dt = function(e) {
  if (!e)
    throw new Error("No node provided");
  return e.tabIndex < 0 && (/^(AUDIO|VIDEO|DETAILS)$/.test(e.tagName) || Ht(e)) && !ft(e) ? 0 : e.tabIndex;
}, Xt = function(e, n) {
  var r = dt(e);
  return r < 0 && n && !ft(e) ? 0 : r;
}, Gt = function(e, n) {
  return e.tabIndex === n.tabIndex ? e.documentOrder - n.documentOrder : e.tabIndex - n.tabIndex;
}, mt = function(e) {
  return e.tagName === "INPUT";
}, Zt = function(e) {
  return mt(e) && e.type === "hidden";
}, Kt = function(e) {
  var n = e.tagName === "DETAILS" && Array.prototype.slice.apply(e.children).some(function(r) {
    return r.tagName === "SUMMARY";
  });
  return n;
}, Jt = function(e, n) {
  for (var r = 0; r < e.length; r++)
    if (e[r].checked && e[r].form === n)
      return e[r];
}, Qt = function(e) {
  if (!e.name)
    return !0;
  var n = e.form || be(e), r = function(l) {
    return n.querySelectorAll('input[type="radio"][name="' + l + '"]');
  }, o;
  if (typeof window < "u" && typeof window.CSS < "u" && typeof window.CSS.escape == "function")
    o = r(window.CSS.escape(e.name));
  else
    try {
      o = r(e.name);
    } catch (i) {
      return console.error("Looks like you have a radio button with a name attribute containing invalid CSS selector characters and need the CSS.escape polyfill: %s", i.message), !1;
    }
  var s = Jt(o, e.form);
  return !s || s === e;
}, en = function(e) {
  return mt(e) && e.type === "radio";
}, tn = function(e) {
  return en(e) && !Qt(e);
}, nn = function(e) {
  var n, r = e && be(e), o = (n = r) === null || n === void 0 ? void 0 : n.host, s = !1;
  if (r && r !== e) {
    var i, l, c;
    for (s = !!((i = o) !== null && i !== void 0 && (l = i.ownerDocument) !== null && l !== void 0 && l.contains(o) || e != null && (c = e.ownerDocument) !== null && c !== void 0 && c.contains(e)); !s && o; ) {
      var a, f, d;
      r = be(o), o = (a = r) === null || a === void 0 ? void 0 : a.host, s = !!((f = o) !== null && f !== void 0 && (d = f.ownerDocument) !== null && d !== void 0 && d.contains(o));
    }
  }
  return s;
}, Ye = function(e) {
  var n = e.getBoundingClientRect(), r = n.width, o = n.height;
  return r === 0 && o === 0;
}, rn = function(e, n) {
  var r = n.displayCheck, o = n.getShadowRoot;
  if (getComputedStyle(e).visibility === "hidden")
    return !0;
  var s = ue.call(e, "details>summary:first-of-type"), i = s ? e.parentElement : e;
  if (ue.call(i, "details:not([open]) *"))
    return !0;
  if (!r || r === "full" || r === "legacy-full") {
    if (typeof o == "function") {
      for (var l = e; e; ) {
        var c = e.parentElement, a = be(e);
        if (c && !c.shadowRoot && o(c) === !0)
          return Ye(e);
        e.assignedSlot ? e = e.assignedSlot : !c && a !== e.ownerDocument ? e = a.host : e = c;
      }
      e = l;
    }
    if (nn(e))
      return !e.getClientRects().length;
    if (r !== "legacy-full")
      return !0;
  } else if (r === "non-zero-area")
    return Ye(e);
  return !1;
}, on = function(e) {
  if (/^(INPUT|BUTTON|SELECT|TEXTAREA)$/.test(e.tagName))
    for (var n = e.parentElement; n; ) {
      if (n.tagName === "FIELDSET" && n.disabled) {
        for (var r = 0; r < n.children.length; r++) {
          var o = n.children.item(r);
          if (o.tagName === "LEGEND")
            return ue.call(n, "fieldset[disabled] *") ? !0 : !o.contains(e);
        }
        return !0;
      }
      n = n.parentElement;
    }
  return !1;
}, sn = function(e, n) {
  return !(n.disabled || // we must do an inert look up to filter out any elements inside an inert ancestor
  //  because we're limited in the type of selectors we can use in JSDom (see related
  //  note related to `candidateSelectors`)
  ye(n) || Zt(n) || rn(n, e) || // For a details element with a summary, the summary element gets the focus
  Kt(n) || on(n));
}, ze = function(e, n) {
  return !(tn(n) || dt(n) < 0 || !sn(e, n));
}, ln = function(e) {
  var n = parseInt(e.getAttribute("tabindex"), 10);
  return !!(isNaN(n) || n >= 0);
}, cn = function t(e) {
  var n = [], r = [];
  return e.forEach(function(o, s) {
    var i = !!o.scopeParent, l = i ? o.scopeParent : o, c = Xt(l, i), a = i ? t(o.candidates) : l;
    c === 0 ? i ? n.push.apply(n, a) : n.push(l) : r.push({
      documentOrder: s,
      tabIndex: c,
      item: o,
      isScope: i,
      content: a
    });
  }), r.sort(Gt).reduce(function(o, s) {
    return s.isScope ? o.push.apply(o, s.content) : o.push(s.content), o;
  }, []).concat(n);
}, gt = function(e, n) {
  n = n || {};
  var r;
  return n.getShadowRoot ? r = _t([e], n.includeContainer, {
    filter: ze.bind(null, n),
    flatten: !1,
    getShadowRoot: n.getShadowRoot,
    shadowRootFilter: ln
  }) : r = Ut(e, n.includeContainer, ze.bind(null, n)), cn(r);
};
function He(t, e, n) {
  let {
    reference: r,
    floating: o
  } = t;
  const s = st(e), i = kt(e), l = Bt(i), c = xe(e), a = s === "y", f = r.x + r.width / 2 - o.width / 2, d = r.y + r.height / 2 - o.height / 2, v = r[l] / 2 - o[l] / 2;
  let u;
  switch (c) {
    case "top":
      u = {
        x: f,
        y: r.y - o.height
      };
      break;
    case "bottom":
      u = {
        x: f,
        y: r.y + r.height
      };
      break;
    case "right":
      u = {
        x: r.x + r.width,
        y: d
      };
      break;
    case "left":
      u = {
        x: r.x - o.width,
        y: d
      };
      break;
    default:
      u = {
        x: r.x,
        y: r.y
      };
  }
  switch (Q(e)) {
    case "start":
      u[i] -= v * (n && a ? -1 : 1);
      break;
    case "end":
      u[i] += v * (n && a ? -1 : 1);
      break;
  }
  return u;
}
const an = async (t, e, n) => {
  const {
    placement: r = "bottom",
    strategy: o = "absolute",
    middleware: s = [],
    platform: i
  } = n, l = s.filter(Boolean), c = await (i.isRTL == null ? void 0 : i.isRTL(e));
  let a = await i.getElementRects({
    reference: t,
    floating: e,
    strategy: o
  }), {
    x: f,
    y: d
  } = He(a, r, c), v = r, u = {}, y = 0;
  for (let g = 0; g < l.length; g++) {
    const {
      name: p,
      fn: b
    } = l[g], {
      x,
      y: w,
      data: E,
      reset: C
    } = await b({
      x: f,
      y: d,
      initialPlacement: r,
      placement: v,
      strategy: o,
      middlewareData: u,
      rects: a,
      platform: i,
      elements: {
        reference: t,
        floating: e
      }
    });
    f = x ?? f, d = w ?? d, u = {
      ...u,
      [p]: {
        ...u[p],
        ...E
      }
    }, C && y <= 50 && (y++, typeof C == "object" && (C.placement && (v = C.placement), C.rects && (a = C.rects === !0 ? await i.getElementRects({
      reference: t,
      floating: e,
      strategy: o
    }) : C.rects), {
      x: f,
      y: d
    } = He(a, v, c)), g = -1);
  }
  return {
    x: f,
    y: d,
    placement: v,
    strategy: o,
    middlewareData: u
  };
};
async function un(t, e) {
  var n;
  e === void 0 && (e = {});
  const {
    x: r,
    y: o,
    platform: s,
    rects: i,
    elements: l,
    strategy: c
  } = t, {
    boundary: a = "clippingAncestors",
    rootBoundary: f = "viewport",
    elementContext: d = "floating",
    altBoundary: v = !1,
    padding: u = 0
  } = De(e, t), y = Nt(u), p = l[v ? d === "floating" ? "reference" : "floating" : d], b = ve(await s.getClippingRect({
    element: (n = await (s.isElement == null ? void 0 : s.isElement(p))) == null || n ? p : p.contextElement || await (s.getDocumentElement == null ? void 0 : s.getDocumentElement(l.floating)),
    boundary: a,
    rootBoundary: f,
    strategy: c
  })), x = d === "floating" ? {
    x: r,
    y: o,
    width: i.floating.width,
    height: i.floating.height
  } : i.reference, w = await (s.getOffsetParent == null ? void 0 : s.getOffsetParent(l.floating)), E = await (s.isElement == null ? void 0 : s.isElement(w)) ? await (s.getScale == null ? void 0 : s.getScale(w)) || {
    x: 1,
    y: 1
  } : {
    x: 1,
    y: 1
  }, C = ve(s.convertOffsetParentRelativeRectToViewportRelativeRect ? await s.convertOffsetParentRelativeRectToViewportRelativeRect({
    elements: l,
    rect: x,
    offsetParent: w,
    strategy: c
  }) : x);
  return {
    top: (b.top - C.top + y.top) / E.y,
    bottom: (C.bottom - b.bottom + y.bottom) / E.y,
    left: (b.left - C.left + y.left) / E.x,
    right: (C.right - b.right + y.right) / E.x
  };
}
function fn(t, e, n) {
  return (t ? [...n.filter((o) => Q(o) === t), ...n.filter((o) => Q(o) !== t)] : n.filter((o) => xe(o) === o)).filter((o) => t ? Q(o) === t || (e ? Dt(o) !== o : !1) : !0);
}
const dn = function(t) {
  return t === void 0 && (t = {}), {
    name: "autoPlacement",
    options: t,
    async fn(e) {
      var n, r, o;
      const {
        rects: s,
        middlewareData: i,
        placement: l,
        platform: c,
        elements: a
      } = e, {
        crossAxis: f = !1,
        alignment: d,
        allowedPlacements: v = je,
        autoAlignment: u = !0,
        ...y
      } = De(t, e), g = d !== void 0 || v === je ? fn(d || null, u, v) : v, p = await un(e, y), b = ((n = i.autoPlacement) == null ? void 0 : n.index) || 0, x = g[b];
      if (x == null)
        return {};
      const w = Ft(x, s, await (c.isRTL == null ? void 0 : c.isRTL(a.floating)));
      if (l !== x)
        return {
          reset: {
            placement: g[0]
          }
        };
      const E = [p[xe(x)], p[w[0]], p[w[1]]], C = [...((r = i.autoPlacement) == null ? void 0 : r.overflows) || [], {
        placement: x,
        overflows: E
      }], L = g[b + 1];
      if (L)
        return {
          data: {
            index: b + 1,
            overflows: C
          },
          reset: {
            placement: L
          }
        };
      const M = C.map((A) => {
        const N = Q(A.placement);
        return [A.placement, N && f ? (
          // Check along the mainAxis and main crossAxis side.
          A.overflows.slice(0, 2).reduce((W, S) => W + S, 0)
        ) : (
          // Check only the mainAxis.
          A.overflows[0]
        ), A.overflows];
      }).sort((A, N) => A[1] - N[1]), $ = ((o = M.filter((A) => A[2].slice(
        0,
        // Aligned placements should not check their opposite crossAxis
        // side.
        Q(A[0]) ? 2 : 3
      ).every((N) => N <= 0))[0]) == null ? void 0 : o[0]) || M[0][0];
      return $ !== l ? {
        data: {
          index: b + 1,
          overflows: C
        },
        reset: {
          placement: $
        }
      } : {};
    }
  };
};
async function mn(t, e) {
  const {
    placement: n,
    platform: r,
    elements: o
  } = t, s = await (r.isRTL == null ? void 0 : r.isRTL(o.floating)), i = xe(n), l = Q(n), c = st(n) === "y", a = ["left", "top"].includes(i) ? -1 : 1, f = s && c ? -1 : 1, d = De(e, t);
  let {
    mainAxis: v,
    crossAxis: u,
    alignmentAxis: y
  } = typeof d == "number" ? {
    mainAxis: d,
    crossAxis: 0,
    alignmentAxis: null
  } : {
    mainAxis: d.mainAxis || 0,
    crossAxis: d.crossAxis || 0,
    alignmentAxis: d.alignmentAxis
  };
  return l && typeof y == "number" && (u = l === "end" ? y * -1 : y), c ? {
    x: u * f,
    y: v * a
  } : {
    x: v * a,
    y: u * f
  };
}
const gn = function(t) {
  return t === void 0 && (t = 0), {
    name: "offset",
    options: t,
    async fn(e) {
      var n, r;
      const {
        x: o,
        y: s,
        placement: i,
        middlewareData: l
      } = e, c = await mn(e, t);
      return i === ((n = l.offset) == null ? void 0 : n.placement) && (r = l.arrow) != null && r.alignmentOffset ? {} : {
        x: o + c.x,
        y: s + c.y,
        data: {
          ...c,
          placement: i
        }
      };
    }
  };
};
function vt(t) {
  const e = U(t);
  let n = parseFloat(e.width) || 0, r = parseFloat(e.height) || 0;
  const o = X(t), s = o ? t.offsetWidth : n, i = o ? t.offsetHeight : r, l = he(n) !== s || he(r) !== i;
  return l && (n = s, r = i), {
    width: n,
    height: r,
    $: l
  };
}
function Ve(t) {
  return k(t) ? t : t.contextElement;
}
function ie(t) {
  const e = Ve(t);
  if (!X(e))
    return z(1);
  const n = e.getBoundingClientRect(), {
    width: r,
    height: o,
    $: s
  } = vt(e);
  let i = (s ? he(n.width) : n.width) / r, l = (s ? he(n.height) : n.height) / o;
  return (!i || !Number.isFinite(i)) && (i = 1), (!l || !Number.isFinite(l)) && (l = 1), {
    x: i,
    y: l
  };
}
const vn = /* @__PURE__ */ z(0);
function ht(t) {
  const e = ee(t);
  return !ct() || !e.visualViewport ? vn : {
    x: e.visualViewport.offsetLeft,
    y: e.visualViewport.offsetTop
  };
}
function hn(t, e, n) {
  return e === void 0 && (e = !1), !n || e && n !== ee(t) ? !1 : e;
}
function te(t, e, n, r) {
  e === void 0 && (e = !1), n === void 0 && (n = !1);
  const o = t.getBoundingClientRect(), s = Ve(t);
  let i = z(1);
  e && (r ? k(r) && (i = ie(r)) : i = ie(t));
  const l = hn(s, n, r) ? ht(s) : z(0);
  let c = (o.left + l.x) / i.x, a = (o.top + l.y) / i.y, f = o.width / i.x, d = o.height / i.y;
  if (s) {
    const v = ee(s), u = r && k(r) ? ee(r) : r;
    let y = v, g = qe(y);
    for (; g && r && u !== y; ) {
      const p = ie(g), b = g.getBoundingClientRect(), x = U(g), w = b.left + (g.clientLeft + parseFloat(x.paddingLeft)) * p.x, E = b.top + (g.clientTop + parseFloat(x.paddingTop)) * p.y;
      c *= p.x, a *= p.y, f *= p.x, d *= p.y, c += w, a += E, y = ee(g), g = qe(y);
    }
  }
  return ve({
    width: f,
    height: d,
    x: c,
    y: a
  });
}
function We(t, e) {
  const n = Re(t).scrollLeft;
  return e ? e.left + n : te(_(t)).left + n;
}
function pt(t, e, n) {
  n === void 0 && (n = !1);
  const r = t.getBoundingClientRect(), o = r.left + e.scrollLeft - (n ? 0 : (
    // RTL <body> scrollbar.
    We(t, r)
  )), s = r.top + e.scrollTop;
  return {
    x: o,
    y: s
  };
}
function pn(t) {
  let {
    elements: e,
    rect: n,
    offsetParent: r,
    strategy: o
  } = t;
  const s = o === "fixed", i = _(r), l = e ? Ne(e.floating) : !1;
  if (r === i || l && s)
    return n;
  let c = {
    scrollLeft: 0,
    scrollTop: 0
  }, a = z(1);
  const f = z(0), d = X(r);
  if ((d || !d && !s) && ((ke(r) !== "body" || Be(i)) && (c = Re(r)), X(r))) {
    const u = te(r);
    a = ie(r), f.x = u.x + r.clientLeft, f.y = u.y + r.clientTop;
  }
  const v = i && !d && !s ? pt(i, c, !0) : z(0);
  return {
    width: n.width * a.x,
    height: n.height * a.y,
    x: n.x * a.x - c.scrollLeft * a.x + f.x + v.x,
    y: n.y * a.y - c.scrollTop * a.y + f.y + v.y
  };
}
function bn(t) {
  return Array.from(t.getClientRects());
}
function yn(t) {
  const e = _(t), n = Re(t), r = t.ownerDocument.body, o = oe(e.scrollWidth, e.clientWidth, r.scrollWidth, r.clientWidth), s = oe(e.scrollHeight, e.clientHeight, r.scrollHeight, r.clientHeight);
  let i = -n.scrollLeft + We(t);
  const l = -n.scrollTop;
  return U(r).direction === "rtl" && (i += oe(e.clientWidth, r.clientWidth) - o), {
    width: o,
    height: s,
    x: i,
    y: l
  };
}
function wn(t, e) {
  const n = ee(t), r = _(t), o = n.visualViewport;
  let s = r.clientWidth, i = r.clientHeight, l = 0, c = 0;
  if (o) {
    s = o.width, i = o.height;
    const a = ct();
    (!a || a && e === "fixed") && (l = o.offsetLeft, c = o.offsetTop);
  }
  return {
    width: s,
    height: i,
    x: l,
    y: c
  };
}
function xn(t, e) {
  const n = te(t, !0, e === "fixed"), r = n.top + t.clientTop, o = n.left + t.clientLeft, s = X(t) ? ie(t) : z(1), i = t.clientWidth * s.x, l = t.clientHeight * s.y, c = o * s.x, a = r * s.y;
  return {
    width: i,
    height: l,
    x: c,
    y: a
  };
}
function Ue(t, e, n) {
  let r;
  if (e === "viewport")
    r = wn(t, n);
  else if (e === "document")
    r = yn(_(t));
  else if (k(e))
    r = xn(e, n);
  else {
    const o = ht(t);
    r = {
      x: e.x - o.x,
      y: e.y - o.y,
      width: e.width,
      height: e.height
    };
  }
  return ve(r);
}
function bt(t, e) {
  const n = ae(t);
  return n === e || !k(n) || pe(n) ? !1 : U(n).position === "fixed" || bt(n, e);
}
function Rn(t, e) {
  const n = e.get(t);
  if (n)
    return n;
  let r = Ie(t, [], !1).filter((l) => k(l) && ke(l) !== "body"), o = null;
  const s = U(t).position === "fixed";
  let i = s ? ae(t) : t;
  for (; k(i) && !pe(i); ) {
    const l = U(i), c = lt(i);
    !c && l.position === "fixed" && (o = null), (s ? !c && !o : !c && l.position === "static" && !!o && ["absolute", "fixed"].includes(o.position) || Be(i) && !c && bt(t, i)) ? r = r.filter((f) => f !== i) : o = l, i = ae(i);
  }
  return e.set(t, r), r;
}
function En(t) {
  let {
    element: e,
    boundary: n,
    rootBoundary: r,
    strategy: o
  } = t;
  const i = [...n === "clippingAncestors" ? Ne(e) ? [] : Rn(e, this._c) : [].concat(n), r], l = i[0], c = i.reduce((a, f) => {
    const d = Ue(e, f, o);
    return a.top = oe(d.top, a.top), a.right = Ae(d.right, a.right), a.bottom = Ae(d.bottom, a.bottom), a.left = oe(d.left, a.left), a;
  }, Ue(e, l, o));
  return {
    width: c.right - c.left,
    height: c.bottom - c.top,
    x: c.left,
    y: c.top
  };
}
function Cn(t) {
  const {
    width: e,
    height: n
  } = vt(t);
  return {
    width: e,
    height: n
  };
}
function Tn(t, e, n) {
  const r = X(e), o = _(e), s = n === "fixed", i = te(t, !0, s, e);
  let l = {
    scrollLeft: 0,
    scrollTop: 0
  };
  const c = z(0);
  if (r || !r && !s)
    if ((ke(e) !== "body" || Be(o)) && (l = Re(e)), r) {
      const v = te(e, !0, s, e);
      c.x = v.x + e.clientLeft, c.y = v.y + e.clientTop;
    } else o && (c.x = We(o));
  const a = o && !r && !s ? pt(o, l) : z(0), f = i.left + l.scrollLeft - c.x - a.x, d = i.top + l.scrollTop - c.y - a.y;
  return {
    x: f,
    y: d,
    width: i.width,
    height: i.height
  };
}
function Ee(t) {
  return U(t).position === "static";
}
function _e(t, e) {
  if (!X(t) || U(t).position === "fixed")
    return null;
  if (e)
    return e(t);
  let n = t.offsetParent;
  return _(t) === n && (n = n.ownerDocument.body), n;
}
function yt(t, e) {
  const n = ee(t);
  if (Ne(t))
    return n;
  if (!X(t)) {
    let o = ae(t);
    for (; o && !pe(o); ) {
      if (k(o) && !Ee(o))
        return o;
      o = ae(o);
    }
    return n;
  }
  let r = _e(t, e);
  for (; r && Vt(r) && Ee(r); )
    r = _e(r, e);
  return r && pe(r) && Ee(r) && !lt(r) ? n : r || Wt(t) || n;
}
const Sn = async function(t) {
  const e = this.getOffsetParent || yt, n = this.getDimensions, r = await n(t.floating);
  return {
    reference: Tn(t.reference, await e(t.floating), t.strategy),
    floating: {
      x: 0,
      y: 0,
      width: r.width,
      height: r.height
    }
  };
};
function On(t) {
  return U(t).direction === "rtl";
}
const Pn = {
  convertOffsetParentRelativeRectToViewportRelativeRect: pn,
  getDocumentElement: _,
  getClippingRect: En,
  getOffsetParent: yt,
  getElementRects: Sn,
  getClientRects: bn,
  getDimensions: Cn,
  getScale: ie,
  isElement: k,
  isRTL: On
};
function wt(t, e) {
  return t.x === e.x && t.y === e.y && t.width === e.width && t.height === e.height;
}
function In(t, e) {
  let n = null, r;
  const o = _(t);
  function s() {
    var l;
    clearTimeout(r), (l = n) == null || l.disconnect(), n = null;
  }
  function i(l, c) {
    l === void 0 && (l = !1), c === void 0 && (c = 1), s();
    const a = t.getBoundingClientRect(), {
      left: f,
      top: d,
      width: v,
      height: u
    } = a;
    if (l || e(), !v || !u)
      return;
    const y = fe(d), g = fe(o.clientWidth - (f + v)), p = fe(o.clientHeight - (d + u)), b = fe(f), w = {
      rootMargin: -y + "px " + -g + "px " + -p + "px " + -b + "px",
      threshold: oe(0, Ae(1, c)) || 1
    };
    let E = !0;
    function C(L) {
      const M = L[0].intersectionRatio;
      if (M !== c) {
        if (!E)
          return i();
        M ? i(!1, M) : r = setTimeout(() => {
          i(!1, 1e-7);
        }, 1e3);
      }
      M === 1 && !wt(a, t.getBoundingClientRect()) && i(), E = !1;
    }
    try {
      n = new IntersectionObserver(C, {
        ...w,
        // Handle <iframe>s
        root: o.ownerDocument
      });
    } catch {
      n = new IntersectionObserver(C, w);
    }
    n.observe(t);
  }
  return i(!0), s;
}
function tr(t, e, n, r) {
  r === void 0 && (r = {});
  const {
    ancestorScroll: o = !0,
    ancestorResize: s = !0,
    elementResize: i = typeof ResizeObserver == "function",
    layoutShift: l = typeof IntersectionObserver == "function",
    animationFrame: c = !1
  } = r, a = Ve(t), f = o || s ? [...a ? Ie(a) : [], ...Ie(e)] : [];
  f.forEach((b) => {
    o && b.addEventListener("scroll", n, {
      passive: !0
    }), s && b.addEventListener("resize", n);
  });
  const d = a && l ? In(a, n) : null;
  let v = -1, u = null;
  i && (u = new ResizeObserver((b) => {
    let [x] = b;
    x && x.target === a && u && (u.unobserve(e), cancelAnimationFrame(v), v = requestAnimationFrame(() => {
      var w;
      (w = u) == null || w.observe(e);
    })), n();
  }), a && !c && u.observe(a), u.observe(e));
  let y, g = c ? te(t) : null;
  c && p();
  function p() {
    const b = te(t);
    g && !wt(g, b) && n(), g = b, y = requestAnimationFrame(p);
  }
  return n(), () => {
    var b;
    f.forEach((x) => {
      o && x.removeEventListener("scroll", n), s && x.removeEventListener("resize", n);
    }), d == null || d(), (b = u) == null || b.disconnect(), u = null, c && cancelAnimationFrame(y);
  };
}
const An = gn, Mn = dn, Ln = (t, e, n) => {
  const r = /* @__PURE__ */ new Map(), o = {
    platform: Pn,
    ...n
  }, s = {
    ...o.platform,
    _c: r
  };
  return an(t, e, {
    ...o,
    platform: s
  });
};
var me = typeof document < "u" ? ot : it;
function we(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, r, o;
  if (t && e && typeof t == "object") {
    if (Array.isArray(t)) {
      if (n = t.length, n !== e.length) return !1;
      for (r = n; r-- !== 0; )
        if (!we(t[r], e[r]))
          return !1;
      return !0;
    }
    if (o = Object.keys(t), n = o.length, n !== Object.keys(e).length)
      return !1;
    for (r = n; r-- !== 0; )
      if (!{}.hasOwnProperty.call(e, o[r]))
        return !1;
    for (r = n; r-- !== 0; ) {
      const s = o[r];
      if (!(s === "_owner" && t.$$typeof) && !we(t[s], e[s]))
        return !1;
    }
    return !0;
  }
  return t !== t && e !== e;
}
function xt(t) {
  return typeof window > "u" ? 1 : (t.ownerDocument.defaultView || window).devicePixelRatio || 1;
}
function Xe(t, e) {
  const n = xt(t);
  return Math.round(e * n) / n;
}
function Ce(t) {
  const e = m.useRef(t);
  return me(() => {
    e.current = t;
  }), e;
}
function Fn(t) {
  t === void 0 && (t = {});
  const {
    placement: e = "bottom",
    strategy: n = "absolute",
    middleware: r = [],
    platform: o,
    elements: {
      reference: s,
      floating: i
    } = {},
    transform: l = !0,
    whileElementsMounted: c,
    open: a
  } = t, [f, d] = m.useState({
    x: 0,
    y: 0,
    strategy: n,
    placement: e,
    middlewareData: {},
    isPositioned: !1
  }), [v, u] = m.useState(r);
  we(v, r) || u(r);
  const [y, g] = m.useState(null), [p, b] = m.useState(null), x = m.useCallback((R) => {
    R !== L.current && (L.current = R, g(R));
  }, []), w = m.useCallback((R) => {
    R !== M.current && (M.current = R, b(R));
  }, []), E = s || y, C = i || p, L = m.useRef(null), M = m.useRef(null), q = m.useRef(f), $ = c != null, A = Ce(c), N = Ce(o), W = Ce(a), S = m.useCallback(() => {
    if (!L.current || !M.current)
      return;
    const R = {
      placement: e,
      strategy: n,
      middleware: v
    };
    N.current && (R.platform = N.current), Ln(L.current, M.current, R).then((O) => {
      const P = {
        ...O,
        // 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
      };
      h.current && !we(q.current, P) && (q.current = P, at.flushSync(() => {
        d(P);
      }));
    });
  }, [v, e, n, N, W]);
  me(() => {
    a === !1 && q.current.isPositioned && (q.current.isPositioned = !1, d((R) => ({
      ...R,
      isPositioned: !1
    })));
  }, [a]);
  const h = m.useRef(!1);
  me(() => (h.current = !0, () => {
    h.current = !1;
  }), []), me(() => {
    if (E && (L.current = E), C && (M.current = C), E && C) {
      if (A.current)
        return A.current(E, C, S);
      S();
    }
  }, [E, C, S, A, $]);
  const j = m.useMemo(() => ({
    reference: L,
    floating: M,
    setReference: x,
    setFloating: w
  }), [x, w]), D = m.useMemo(() => ({
    reference: E,
    floating: C
  }), [E, C]), T = m.useMemo(() => {
    const R = {
      position: n,
      left: 0,
      top: 0
    };
    if (!D.floating)
      return R;
    const O = Xe(D.floating, f.x), P = Xe(D.floating, f.y);
    return l ? {
      ...R,
      transform: "translate(" + O + "px, " + P + "px)",
      ...xt(D.floating) >= 1.5 && {
        willChange: "transform"
      }
    } : {
      position: n,
      left: O,
      top: P
    };
  }, [n, l, D.floating, f.x, f.y]);
  return m.useMemo(() => ({
    ...f,
    update: S,
    refs: j,
    elements: D,
    floatingStyles: T
  }), [f, S, j, D, T]);
}
const nr = (t, e) => ({
  ...An(t),
  options: [t, e]
}), rr = (t, e) => ({
  ...Mn(t),
  options: [t, e]
});
function or(t) {
  const e = m.useRef(void 0), n = m.useCallback((r) => {
    const o = t.map((s) => {
      if (s != null) {
        if (typeof s == "function") {
          const i = s, l = i(r);
          return typeof l == "function" ? l : () => {
            i(null);
          };
        }
        return s.current = r, () => {
          s.current = null;
        };
      }
    });
    return () => {
      o.forEach((s) => s == null ? void 0 : s());
    };
  }, t);
  return m.useMemo(() => t.every((r) => r == null) ? null : (r) => {
    e.current && (e.current(), e.current = void 0), r != null && (e.current = n(r));
  }, t);
}
const Rt = {
  ...m
}, Dn = Rt.useInsertionEffect, Nn = Dn || ((t) => t());
function ge(t) {
  const e = m.useRef(() => {
    if (process.env.NODE_ENV !== "production")
      throw new Error("Cannot call an event handler while rendering.");
  });
  return Nn(() => {
    e.current = t;
  }), m.useCallback(function() {
    for (var n = arguments.length, r = new Array(n), o = 0; o < n; o++)
      r[o] = arguments[o];
    return e.current == null ? void 0 : e.current(...r);
  }, []);
}
var H = typeof document < "u" ? ot : it;
let Ge = !1, kn = 0;
const Ze = () => (
  // Ensure the id is unique with multiple independent versions of Floating UI
  // on <React 18
  "floating-ui-" + Math.random().toString(36).slice(2, 6) + kn++
);
function Bn() {
  const [t, e] = m.useState(() => Ge ? Ze() : void 0);
  return H(() => {
    t == null && e(Ze());
  }, []), m.useEffect(() => {
    Ge = !0;
  }, []), t;
}
const Vn = Rt.useId, Et = Vn || Bn;
let Fe;
process.env.NODE_ENV !== "production" && (Fe = /* @__PURE__ */ new Set());
function Wn() {
  for (var t, e = arguments.length, n = new Array(e), r = 0; r < e; r++)
    n[r] = arguments[r];
  const o = "Floating UI: " + n.join(" ");
  if (!((t = Fe) != null && t.has(o))) {
    var s;
    (s = Fe) == null || s.add(o), console.error(o);
  }
}
function $n() {
  const t = /* @__PURE__ */ new Map();
  return {
    emit(e, n) {
      var r;
      (r = t.get(e)) == null || r.forEach((o) => o(n));
    },
    on(e, n) {
      t.set(e, [...t.get(e) || [], n]);
    },
    off(e, n) {
      var r;
      t.set(e, ((r = t.get(e)) == null ? void 0 : r.filter((o) => o !== n)) || []);
    }
  };
}
const jn = /* @__PURE__ */ m.createContext(null), qn = /* @__PURE__ */ m.createContext(null), Ct = () => {
  var t;
  return ((t = m.useContext(jn)) == null ? void 0 : t.id) || null;
}, Tt = () => m.useContext(qn);
function $e(t) {
  return "data-floating-ui-" + t;
}
function Y(t) {
  t.current !== -1 && (clearTimeout(t.current), t.current = -1);
}
function Te(t) {
  const e = Mt(t);
  return H(() => {
    e.current = t;
  }), e;
}
const Ke = /* @__PURE__ */ $e("safe-polygon");
function Se(t, e, n) {
  return n && !Me(n) ? 0 : typeof t == "number" ? t : t == null ? void 0 : t[e];
}
function ir(t, e) {
  e === void 0 && (e = {});
  const {
    open: n,
    onOpenChange: r,
    dataRef: o,
    events: s,
    elements: i
  } = t, {
    enabled: l = !0,
    delay: c = 0,
    handleClose: a = null,
    mouseOnly: f = !1,
    restMs: d = 0,
    move: v = !0
  } = e, u = Tt(), y = Ct(), g = Te(a), p = Te(c), b = Te(n), x = m.useRef(), w = m.useRef(-1), E = m.useRef(), C = m.useRef(-1), L = m.useRef(!0), M = m.useRef(!1), q = m.useRef(() => {
  }), $ = m.useRef(!1), A = m.useCallback(() => {
    var T;
    const R = (T = o.current.openEvent) == null ? void 0 : T.type;
    return (R == null ? void 0 : R.includes("mouse")) && R !== "mousedown";
  }, [o]);
  m.useEffect(() => {
    if (!l) return;
    function T(R) {
      let {
        open: O
      } = R;
      O || (Y(w), Y(C), L.current = !0, $.current = !1);
    }
    return s.on("openchange", T), () => {
      s.off("openchange", T);
    };
  }, [l, s]), m.useEffect(() => {
    if (!l || !g.current || !n) return;
    function T(O) {
      A() && r(!1, O, "hover");
    }
    const R = le(i.floating).documentElement;
    return R.addEventListener("mouseleave", T), () => {
      R.removeEventListener("mouseleave", T);
    };
  }, [i.floating, n, r, l, g, A]);
  const N = m.useCallback(function(T, R, O) {
    R === void 0 && (R = !0), O === void 0 && (O = "hover");
    const P = Se(p.current, "close", x.current);
    P && !E.current ? (Y(w), w.current = window.setTimeout(() => r(!1, T, O), P)) : R && (Y(w), r(!1, T, O));
  }, [p, r]), W = ge(() => {
    q.current(), E.current = void 0;
  }), S = ge(() => {
    if (M.current) {
      const T = le(i.floating).body;
      T.style.pointerEvents = "", T.removeAttribute(Ke), M.current = !1;
    }
  }), h = ge(() => o.current.openEvent ? ["click", "mousedown"].includes(o.current.openEvent.type) : !1);
  m.useEffect(() => {
    if (!l) return;
    function T(I) {
      if (Y(w), L.current = !1, f && !Me(x.current) || d > 0 && !Se(p.current, "open"))
        return;
      const B = Se(p.current, "open", x.current);
      B ? w.current = window.setTimeout(() => {
        b.current || r(!0, I, "hover");
      }, B) : n || r(!0, I, "hover");
    }
    function R(I) {
      if (h()) return;
      q.current();
      const B = le(i.floating);
      if (Y(C), $.current = !1, g.current && o.current.floatingContext) {
        n || Y(w), E.current = g.current({
          ...o.current.floatingContext,
          tree: u,
          x: I.clientX,
          y: I.clientY,
          onClose() {
            S(), W(), h() || N(I, !0, "safe-polygon");
          }
        });
        const Z = E.current;
        B.addEventListener("mousemove", Z), q.current = () => {
          B.removeEventListener("mousemove", Z);
        };
        return;
      }
      (x.current === "touch" ? !ce(i.floating, I.relatedTarget) : !0) && N(I);
    }
    function O(I) {
      h() || o.current.floatingContext && (g.current == null || g.current({
        ...o.current.floatingContext,
        tree: u,
        x: I.clientX,
        y: I.clientY,
        onClose() {
          S(), W(), h() || N(I);
        }
      })(I));
    }
    if (k(i.domReference)) {
      var P;
      const I = i.domReference;
      return n && I.addEventListener("mouseleave", O), (P = i.floating) == null || P.addEventListener("mouseleave", O), v && I.addEventListener("mousemove", T, {
        once: !0
      }), I.addEventListener("mouseenter", T), I.addEventListener("mouseleave", R), () => {
        var B;
        n && I.removeEventListener("mouseleave", O), (B = i.floating) == null || B.removeEventListener("mouseleave", O), v && I.removeEventListener("mousemove", T), I.removeEventListener("mouseenter", T), I.removeEventListener("mouseleave", R);
      };
    }
  }, [i, l, t, f, d, v, N, W, S, r, n, b, u, p, g, o, h]), H(() => {
    var T;
    if (l && n && (T = g.current) != null && T.__options.blockPointerEvents && A()) {
      M.current = !0;
      const O = i.floating;
      if (k(i.domReference) && O) {
        var R;
        const P = le(i.floating).body;
        P.setAttribute(Ke, "");
        const I = i.domReference, B = u == null || (R = u.nodesRef.current.find((G) => G.id === y)) == null || (R = R.context) == null ? void 0 : R.elements.floating;
        return B && (B.style.pointerEvents = ""), P.style.pointerEvents = "none", I.style.pointerEvents = "auto", O.style.pointerEvents = "auto", () => {
          P.style.pointerEvents = "", I.style.pointerEvents = "", O.style.pointerEvents = "";
        };
      }
    }
  }, [l, n, y, i, u, g, A]), H(() => {
    n || (x.current = void 0, $.current = !1, W(), S());
  }, [n, W, S]), m.useEffect(() => () => {
    W(), Y(w), Y(C), S();
  }, [l, i.domReference, W, S]);
  const j = m.useMemo(() => {
    function T(R) {
      x.current = R.pointerType;
    }
    return {
      onPointerDown: T,
      onPointerEnter: T,
      onMouseMove(R) {
        const {
          nativeEvent: O
        } = R;
        function P() {
          !L.current && !b.current && r(!0, O, "hover");
        }
        f && !Me(x.current) || n || d === 0 || $.current && R.movementX ** 2 + R.movementY ** 2 < 2 || (Y(C), x.current === "touch" ? P() : ($.current = !0, C.current = window.setTimeout(P, d)));
      }
    };
  }, [f, r, n, b, d]), D = m.useMemo(() => ({
    onMouseEnter() {
      Y(w);
    },
    onMouseLeave(T) {
      h() || N(T.nativeEvent, !1);
    }
  }), [N, h]);
  return m.useMemo(() => l ? {
    reference: j,
    floating: D
  } : {}, [l, j, D]);
}
function Yn(t, e) {
  let n = t.filter((o) => {
    var s;
    return o.parentId === e && ((s = o.context) == null ? void 0 : s.open);
  }), r = n;
  for (; r.length; )
    r = t.filter((o) => {
      var s;
      return (s = r) == null ? void 0 : s.some((i) => {
        var l;
        return o.parentId === i.id && ((l = o.context) == null ? void 0 : l.open);
      });
    }), n = n.concat(r);
  return n;
}
const St = () => ({
  getShadowRoot: !0,
  displayCheck: (
    // JSDOM does not support the `tabbable` library. To solve this we can
    // check if `ResizeObserver` is a real function (not polyfilled), which
    // determines if the current environment is JSDOM-like.
    typeof ResizeObserver == "function" && ResizeObserver.toString().includes("[native code]") ? "full" : "none"
  )
});
function Ot(t, e) {
  const n = gt(t, St());
  e === "prev" && n.reverse();
  const r = n.indexOf(jt(le(t)));
  return n.slice(r + 1)[0];
}
function zn() {
  return Ot(document.body, "next");
}
function Hn() {
  return Ot(document.body, "prev");
}
function Oe(t, e) {
  const n = e || t.currentTarget, r = t.relatedTarget;
  return !r || !ce(n, r);
}
function Un(t) {
  gt(t, St()).forEach((n) => {
    n.dataset.tabindex = n.getAttribute("tabindex") || "", n.setAttribute("tabindex", "-1");
  });
}
function Je(t) {
  t.querySelectorAll("[data-tabindex]").forEach((n) => {
    const r = n.dataset.tabindex;
    delete n.dataset.tabindex, r ? n.setAttribute("tabindex", r) : n.removeAttribute("tabindex");
  });
}
const Pt = {
  border: 0,
  clip: "rect(0 0 0 0)",
  height: "1px",
  margin: "-1px",
  overflow: "hidden",
  padding: 0,
  position: "fixed",
  whiteSpace: "nowrap",
  width: "1px",
  top: 0,
  left: 0
}, Qe = /* @__PURE__ */ m.forwardRef(function(e, n) {
  const [r, o] = m.useState();
  H(() => {
    qt() && o("button");
  }, []);
  const s = {
    ref: n,
    tabIndex: 0,
    // Role is only for VoiceOver
    role: r,
    "aria-hidden": r ? void 0 : !0,
    [$e("focus-guard")]: "",
    style: Pt
  };
  return /* @__PURE__ */ de("span", {
    ...e,
    ...s
  });
}), It = /* @__PURE__ */ m.createContext(null), et = /* @__PURE__ */ $e("portal");
function _n(t) {
  t === void 0 && (t = {});
  const {
    id: e,
    root: n
  } = t, r = Et(), o = Xn(), [s, i] = m.useState(null), l = m.useRef(null);
  return H(() => () => {
    s == null || s.remove(), queueMicrotask(() => {
      l.current = null;
    });
  }, [s]), H(() => {
    if (!r || l.current) return;
    const c = e ? document.getElementById(e) : null;
    if (!c) return;
    const a = document.createElement("div");
    a.id = r, a.setAttribute(et, ""), c.appendChild(a), l.current = a, i(a);
  }, [e, r]), H(() => {
    if (n === null || !r || l.current) return;
    let c = n || (o == null ? void 0 : o.portalNode);
    c && !k(c) && (c = c.current), c = c || document.body;
    let a = null;
    e && (a = document.createElement("div"), a.id = e, c.appendChild(a));
    const f = document.createElement("div");
    f.id = r, f.setAttribute(et, ""), c = a || c, c.appendChild(f), l.current = f, i(f);
  }, [e, n, r, o]), s;
}
function sr(t) {
  const {
    children: e,
    id: n,
    root: r,
    preserveTabOrder: o = !0
  } = t, s = _n({
    id: n,
    root: r
  }), [i, l] = m.useState(null), c = m.useRef(null), a = m.useRef(null), f = m.useRef(null), d = m.useRef(null), v = i == null ? void 0 : i.modal, u = i == null ? void 0 : i.open, y = (
    // The FocusManager and therefore floating element are currently open/
    // rendered.
    !!i && // Guards are only for non-modal focus management.
    !i.modal && // Don't render if unmount is transitioning.
    i.open && o && !!(r || s)
  );
  return m.useEffect(() => {
    if (!s || !o || v)
      return;
    function g(p) {
      s && Oe(p) && (p.type === "focusin" ? Je : Un)(s);
    }
    return s.addEventListener("focusin", g, !0), s.addEventListener("focusout", g, !0), () => {
      s.removeEventListener("focusin", g, !0), s.removeEventListener("focusout", g, !0);
    };
  }, [s, o, v]), m.useEffect(() => {
    s && (u || Je(s));
  }, [u, s]), /* @__PURE__ */ $t(It.Provider, {
    value: m.useMemo(() => ({
      preserveTabOrder: o,
      beforeOutsideRef: c,
      afterOutsideRef: a,
      beforeInsideRef: f,
      afterInsideRef: d,
      portalNode: s,
      setFocusManagerState: l
    }), [o, s]),
    children: [y && s && /* @__PURE__ */ de(Qe, {
      "data-type": "outside",
      ref: c,
      onFocus: (g) => {
        if (Oe(g, s)) {
          var p;
          (p = f.current) == null || p.focus();
        } else {
          const b = Hn() || (i == null ? void 0 : i.domReference);
          b == null || b.focus();
        }
      }
    }), y && s && /* @__PURE__ */ de("span", {
      "aria-owns": s.id,
      style: Pt
    }), s && /* @__PURE__ */ at.createPortal(e, s), y && s && /* @__PURE__ */ de(Qe, {
      "data-type": "outside",
      ref: a,
      onFocus: (g) => {
        if (Oe(g, s)) {
          var p;
          (p = d.current) == null || p.focus();
        } else {
          const b = zn() || (i == null ? void 0 : i.domReference);
          b == null || b.focus(), i != null && i.closeOnFocusOut && (i == null || i.onOpenChange(!1, g.nativeEvent, "focus-out"));
        }
      }
    })]
  });
}
const Xn = () => m.useContext(It), Gn = "data-floating-ui-focusable";
function Zn(t) {
  const {
    open: e = !1,
    onOpenChange: n,
    elements: r
  } = t, o = Et(), s = m.useRef({}), [i] = m.useState(() => $n()), l = Ct() != null;
  if (process.env.NODE_ENV !== "production") {
    const u = r.reference;
    u && !k(u) && Wn("Cannot pass a virtual element to the `elements.reference` option,", "as it must be a real DOM element. Use `refs.setPositionReference()`", "instead.");
  }
  const [c, a] = m.useState(r.reference), f = ge((u, y, g) => {
    s.current.openEvent = u ? y : void 0, i.emit("openchange", {
      open: u,
      event: y,
      reason: g,
      nested: l
    }), n == null || n(u, y, g);
  }), d = m.useMemo(() => ({
    setPositionReference: a
  }), []), v = m.useMemo(() => ({
    reference: c || r.reference || null,
    floating: r.floating || null,
    domReference: r.reference
  }), [c, r.reference, r.floating]);
  return m.useMemo(() => ({
    dataRef: s,
    open: e,
    onOpenChange: f,
    elements: v,
    events: i,
    floatingId: o,
    refs: d
  }), [e, f, v, i, o, d]);
}
function lr(t) {
  t === void 0 && (t = {});
  const {
    nodeId: e
  } = t, n = Zn({
    ...t,
    elements: {
      reference: null,
      floating: null,
      ...t.elements
    }
  }), r = t.rootContext || n, o = r.elements, [s, i] = m.useState(null), [l, c] = m.useState(null), f = (o == null ? void 0 : o.domReference) || s, d = m.useRef(null), v = Tt();
  H(() => {
    f && (d.current = f);
  }, [f]);
  const u = Fn({
    ...t,
    elements: {
      ...o,
      ...l && {
        reference: l
      }
    }
  }), y = m.useCallback((w) => {
    const E = k(w) ? {
      getBoundingClientRect: () => w.getBoundingClientRect(),
      contextElement: w
    } : w;
    c(E), u.refs.setReference(E);
  }, [u.refs]), g = m.useCallback((w) => {
    (k(w) || w === null) && (d.current = w, i(w)), (k(u.refs.reference.current) || u.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.
    w !== null && !k(w)) && u.refs.setReference(w);
  }, [u.refs]), p = m.useMemo(() => ({
    ...u.refs,
    setReference: g,
    setPositionReference: y,
    domReference: d
  }), [u.refs, g, y]), b = m.useMemo(() => ({
    ...u.elements,
    domReference: f
  }), [u.elements, f]), x = m.useMemo(() => ({
    ...u,
    ...r,
    refs: p,
    elements: b,
    nodeId: e
  }), [u, p, b, e, r]);
  return H(() => {
    r.dataRef.current.floatingContext = x;
    const w = v == null ? void 0 : v.nodesRef.current.find((E) => E.id === e);
    w && (w.context = x);
  }), m.useMemo(() => ({
    ...u,
    context: x,
    refs: p,
    elements: b
  }), [u, p, b, x]);
}
const tt = "active", nt = "selected";
function Pe(t, e, n) {
  const r = /* @__PURE__ */ new Map(), o = n === "item";
  let s = t;
  if (o && t) {
    const {
      [tt]: i,
      [nt]: l,
      ...c
    } = t;
    s = c;
  }
  return {
    ...n === "floating" && {
      tabIndex: -1,
      [Gn]: ""
    },
    ...s,
    ...e.map((i) => {
      const l = i ? i[n] : null;
      return typeof l == "function" ? t ? l(t) : null : l;
    }).concat(t).reduce((i, l) => (l && Object.entries(l).forEach((c) => {
      let [a, f] = c;
      if (!(o && [tt, nt].includes(a)))
        if (a.indexOf("on") === 0) {
          if (r.has(a) || r.set(a, []), typeof f == "function") {
            var d;
            (d = r.get(a)) == null || d.push(f), i[a] = function() {
              for (var v, u = arguments.length, y = new Array(u), g = 0; g < u; g++)
                y[g] = arguments[g];
              return (v = r.get(a)) == null ? void 0 : v.map((p) => p(...y)).find((p) => p !== void 0);
            };
          }
        } else
          i[a] = f;
    }), i), {})
  };
}
function cr(t) {
  t === void 0 && (t = []);
  const e = t.map((l) => l == null ? void 0 : l.reference), n = t.map((l) => l == null ? void 0 : l.floating), r = t.map((l) => l == null ? void 0 : l.item), o = m.useCallback(
    (l) => Pe(l, t, "reference"),
    // eslint-disable-next-line react-hooks/exhaustive-deps
    e
  ), s = m.useCallback(
    (l) => Pe(l, t, "floating"),
    // eslint-disable-next-line react-hooks/exhaustive-deps
    n
  ), i = m.useCallback(
    (l) => Pe(l, t, "item"),
    // eslint-disable-next-line react-hooks/exhaustive-deps
    r
  );
  return m.useMemo(() => ({
    getReferenceProps: o,
    getFloatingProps: s,
    getItemProps: i
  }), [o, s, i]);
}
function rt(t, e) {
  const [n, r] = t;
  let o = !1;
  const s = e.length;
  for (let i = 0, l = s - 1; i < s; l = i++) {
    const [c, a] = e[i] || [0, 0], [f, d] = e[l] || [0, 0];
    a >= r != d >= r && n <= (f - c) * (r - a) / (d - a) + c && (o = !o);
  }
  return o;
}
function Kn(t, e) {
  return t[0] >= e.x && t[0] <= e.x + e.width && t[1] >= e.y && t[1] <= e.y + e.height;
}
function ar(t) {
  t === void 0 && (t = {});
  const {
    buffer: e = 0.5,
    blockPointerEvents: n = !1,
    requireIntent: r = !0
  } = t;
  let o, s = !1, i = null, l = null, c = performance.now();
  function a(d, v) {
    const u = performance.now(), y = u - c;
    if (i === null || l === null || y === 0)
      return i = d, l = v, c = u, null;
    const g = d - i, p = v - l, x = Math.sqrt(g * g + p * p) / y;
    return i = d, l = v, c = u, x;
  }
  const f = (d) => {
    let {
      x: v,
      y: u,
      placement: y,
      elements: g,
      onClose: p,
      nodeId: b,
      tree: x
    } = d;
    return function(E) {
      function C() {
        clearTimeout(o), p();
      }
      if (clearTimeout(o), !g.domReference || !g.floating || y == null || v == null || u == null)
        return;
      const {
        clientX: L,
        clientY: M
      } = E, q = [L, M], $ = Yt(E), A = E.type === "mouseleave", N = ce(g.floating, $), W = ce(g.domReference, $), S = g.domReference.getBoundingClientRect(), h = g.floating.getBoundingClientRect(), j = y.split("-")[0], D = v > h.right - h.width / 2, T = u > h.bottom - h.height / 2, R = Kn(q, S), O = h.width > S.width, P = h.height > S.height, I = (O ? S : h).left, B = (O ? S : h).right, G = (P ? S : h).top, Z = (P ? S : h).bottom;
      if (N && (s = !0, !A))
        return;
      if (W && (s = !1), W && !A) {
        s = !0;
        return;
      }
      if (A && k(E.relatedTarget) && ce(g.floating, E.relatedTarget) || x && Yn(x.nodesRef.current, b).some((ne) => {
        let {
          context: F
        } = ne;
        return F == null ? void 0 : F.open;
      }))
        return;
      if (j === "top" && u >= S.bottom - 1 || j === "bottom" && u <= S.top + 1 || j === "left" && v >= S.right - 1 || j === "right" && v <= S.left + 1)
        return C();
      let se = [];
      switch (j) {
        case "top":
          se = [[I, S.top + 1], [I, h.bottom - 1], [B, h.bottom - 1], [B, S.top + 1]];
          break;
        case "bottom":
          se = [[I, h.top + 1], [I, S.bottom - 1], [B, S.bottom - 1], [B, h.top + 1]];
          break;
        case "left":
          se = [[h.right - 1, Z], [h.right - 1, G], [S.left + 1, G], [S.left + 1, Z]];
          break;
        case "right":
          se = [[S.right - 1, Z], [S.right - 1, G], [h.left + 1, G], [h.left + 1, Z]];
          break;
      }
      function At(ne) {
        let [F, V] = ne;
        switch (j) {
          case "top": {
            const K = [O ? F + e / 2 : D ? F + e * 4 : F - e * 4, V + e + 1], J = [O ? F - e / 2 : D ? F + e * 4 : F - e * 4, V + e + 1], re = [[h.left, D || O ? h.bottom - e : h.top], [h.right, D ? O ? h.bottom - e : h.top : h.bottom - e]];
            return [K, J, ...re];
          }
          case "bottom": {
            const K = [O ? F + e / 2 : D ? F + e * 4 : F - e * 4, V - e], J = [O ? F - e / 2 : D ? F + e * 4 : F - e * 4, V - e], re = [[h.left, D || O ? h.top + e : h.bottom], [h.right, D ? O ? h.top + e : h.bottom : h.top + e]];
            return [K, J, ...re];
          }
          case "left": {
            const K = [F + e + 1, P ? V + e / 2 : T ? V + e * 4 : V - e * 4], J = [F + e + 1, P ? V - e / 2 : T ? V + e * 4 : V - e * 4];
            return [...[[T || P ? h.right - e : h.left, h.top], [T ? P ? h.right - e : h.left : h.right - e, h.bottom]], K, J];
          }
          case "right": {
            const K = [F - e, P ? V + e / 2 : T ? V + e * 4 : V - e * 4], J = [F - e, P ? V - e / 2 : T ? V + e * 4 : V - e * 4], re = [[T || P ? h.left + e : h.right, h.top], [T ? P ? h.left + e : h.right : h.left + e, h.bottom]];
            return [K, J, ...re];
          }
        }
      }
      if (!rt([L, M], se)) {
        if (s && !R)
          return C();
        if (!A && r) {
          const ne = a(E.clientX, E.clientY);
          if (ne !== null && ne < 0.1)
            return C();
        }
        rt([L, M], At([v, u])) ? !s && r && (o = window.setTimeout(C, 40)) : C();
      }
    };
  };
  return f.__options = {
    blockPointerEvents: n
  }, f;
}
export {
  sr as F,
  lr as a,
  rr as b,
  ir as c,
  cr as d,
  tr as e,
  nr as o,
  ar as s,
  or as u
};
//# sourceMappingURL=floating-ui.react.CZVVTXoO.js.map
