import { jsx as O, jsxs as mt } from "react/jsx-runtime";
import { cn as Le } from "./utils/functions.js";
import { useMemo as H, createContext as re, useState as $, useRef as x, useCallback as oe, useLayoutEffect as Kt, useEffect as V, useReducer as Vt, useContext as G, forwardRef as He, useImperativeHandle as Xt, Fragment as qt, cloneElement as Wt, memo as Gt } from "react";
import { p as s } from "./index-XF2mSoW7.js";
import { unstable_batchedUpdates as Yt, flushSync as Jt, createPortal as it } from "react-dom";
const ht = (e) => !!e && e[0] === "o", ct = Yt || ((e) => e()), Qt = Object.values || ((e) => Object.keys(e).map((t) => e[t])), ne = (e, t, n = 1e-4) => Math.abs(e - t) < n, le = (e, t) => e === !0 || !!(e && e[t]), k = (e, t) => typeof e == "function" ? e(t) : e, Zt = "_szhsinMenu", en = (e) => e[Zt], Te = (e, t) => (t && Object.keys(t).forEach((n) => {
  const i = e[n], l = t[n];
  typeof l == "function" && i ? e[n] = (...r) => {
    l(...r), i(...r);
  } : e[n] = l;
}), e), tn = (e) => {
  if (typeof e != "string")
    return {
      top: 0,
      right: 0,
      bottom: 0,
      left: 0
    };
  const t = e.trim().split(/\s+/, 4).map(parseFloat), n = isNaN(t[0]) ? 0 : t[0], i = isNaN(t[1]) ? n : t[1];
  return {
    top: n,
    right: i,
    bottom: isNaN(t[2]) ? n : t[2],
    left: isNaN(t[3]) ? i : t[3]
  };
}, Ie = (e) => {
  for (; e; ) {
    if (e = e.parentNode, !e || e === document.body || !e.parentNode)
      return;
    const {
      overflow: t,
      overflowX: n,
      overflowY: i
    } = getComputedStyle(e);
    if (/auto|scroll|overlay|hidden/.test(t + i + n))
      return e;
  }
};
function bt(e, t) {
  return {
    "aria-disabled": e || void 0,
    tabIndex: t ? 0 : -1
  };
}
function ut(e, t) {
  for (let n = 0; n < e.length; n++)
    if (e[n] === t)
      return n;
  return -1;
}
const gt = (e) => ({
  [e ? `${e}ClassName` : "className"]: s.oneOfType([s.string, s.func])
}), nn = {
  className: s.string,
  ...gt("menu"),
  arrowProps: s.object,
  focusProps: s.object,
  menuStyle: s.object,
  arrow: s.bool,
  setDownOverflow: s.bool,
  gap: s.number,
  shift: s.number,
  align: /* @__PURE__ */ s.oneOf(["start", "center", "end"]),
  direction: /* @__PURE__ */ s.oneOf(["left", "right", "top", "bottom"]),
  position: /* @__PURE__ */ s.oneOf(["auto", "anchor", "initial"]),
  overflow: /* @__PURE__ */ s.oneOf(["auto", "visible", "hidden"])
}, Et = {
  ...nn,
  containerProps: s.object,
  initialMounted: s.bool,
  unmountOnClose: s.bool,
  transition: /* @__PURE__ */ s.oneOfType([s.bool, /* @__PURE__ */ s.exact({
    open: s.bool,
    close: s.bool,
    item: s.bool
  })]),
  transitionTimeout: s.number,
  boundingBoxRef: s.object,
  boundingBoxPadding: s.string,
  reposition: /* @__PURE__ */ s.oneOf(["auto", "initial"]),
  repositionFlag: /* @__PURE__ */ s.oneOfType([s.string, s.number]),
  viewScroll: /* @__PURE__ */ s.oneOf(["auto", "close", "initial"]),
  submenuOpenDelay: s.number,
  submenuCloseDelay: s.number,
  portal: /* @__PURE__ */ s.oneOfType([s.bool, /* @__PURE__ */ s.exact({
    target: s.object,
    stablePosition: s.bool
  })]),
  theming: s.string,
  onItemClick: s.func
}, on = {
  instanceRef: /* @__PURE__ */ s.oneOfType([s.object, s.func]),
  onMenuChange: s.func
}, Ee = ({
  block: e,
  element: t,
  modifiers: n,
  className: i
}) => H(() => {
  const l = t ? `${e}__${t}` : e;
  let r = l;
  n && Object.keys(n).forEach((p) => {
    const b = n[p];
    b && (r += ` ${l}--${b === !0 ? p : `${p}-${b}`}`);
  });
  let c = typeof i == "function" ? i(n) : i;
  return typeof c == "string" && (c = c.trim(), c && (r += ` ${c}`)), r;
}, [e, t, n, i]), rn = "szh-menu-container", be = "szh-menu", sn = "arrow", cn = "item", vt = /* @__PURE__ */ re(), wt = /* @__PURE__ */ re({}), lt = /* @__PURE__ */ re({}), yt = /* @__PURE__ */ re({}), un = /* @__PURE__ */ re({}), ze = /* @__PURE__ */ re({}), L = /* @__PURE__ */ Object.freeze({
  ENTER: "Enter",
  ESC: "Escape",
  SPACE: " ",
  HOME: "Home",
  END: "End",
  LEFT: "ArrowLeft",
  RIGHT: "ArrowRight",
  UP: "ArrowUp",
  DOWN: "ArrowDown"
}), S = /* @__PURE__ */ Object.freeze({
  RESET: 0,
  SET: 1,
  UNSET: 2,
  INCREASE: 3,
  DECREASE: 4,
  FIRST: 5,
  LAST: 6,
  SET_INDEX: 7
}), ae = /* @__PURE__ */ Object.freeze({
  CLICK: "click",
  CANCEL: "cancel",
  BLUR: "blur",
  SCROLL: "scroll"
}), ue = /* @__PURE__ */ Object.freeze({
  FIRST: "first",
  LAST: "last"
}), Tt = /* @__PURE__ */ Object.freeze({
  entering: "opening",
  entered: "open",
  exiting: "closing",
  exited: "closed"
}), Pe = "absolute", ln = "presentation", St = "menuitem", at = {
  "aria-hidden": !0,
  role: St
}, an = ({
  className: e,
  containerRef: t,
  containerProps: n,
  children: i,
  isOpen: l,
  theming: r,
  transition: c,
  onClose: p
}) => {
  const b = le(c, "item");
  return /* @__PURE__ */ O("div", {
    ...Te({
      onKeyDown: ({
        key: a
      }) => {
        switch (a) {
          case L.ESC:
            k(p, {
              key: a,
              reason: ae.CANCEL
            });
            break;
        }
      },
      onBlur: (a) => {
        l && !a.currentTarget.contains(a.relatedTarget) && k(p, {
          reason: ae.BLUR
        });
      }
    }, n),
    className: Ee({
      block: rn,
      modifiers: H(() => ({
        theme: r,
        itemTransition: b
      }), [r, b]),
      className: e
    }),
    style: {
      position: "absolute",
      ...n == null ? void 0 : n.style
    },
    ref: t,
    children: i
  });
}, fn = () => {
  let e, t = 0;
  return {
    toggle: (n) => {
      n ? t++ : t--, t = Math.max(t, 0);
    },
    on: (n, i, l) => {
      t ? e || (e = setTimeout(() => {
        e = 0, i();
      }, n)) : l == null || l();
    },
    off: () => {
      e && (clearTimeout(e), e = 0);
    }
  };
}, dn = (e, t) => {
  const [n, i] = $(), r = x({
    items: [],
    hoverIndex: -1,
    sorted: !1
  }).current, c = oe((b, g) => {
    const {
      items: h
    } = r;
    if (!b)
      r.items = [];
    else if (g)
      h.push(b);
    else {
      const a = h.indexOf(b);
      a > -1 && (h.splice(a, 1), b.contains(document.activeElement) && (t.current.focus(), i()));
    }
    r.hoverIndex = -1, r.sorted = !1;
  }, [r, t]), p = oe((b, g, h) => {
    const {
      items: a,
      hoverIndex: w
    } = r, f = () => {
      if (r.sorted)
        return;
      const m = e.current.querySelectorAll(".szh-menu__item");
      a.sort((E, d) => ut(m, E) - ut(m, d)), r.sorted = !0;
    };
    let o = -1, u;
    switch (b) {
      case S.RESET:
        break;
      case S.SET:
        u = g;
        break;
      case S.UNSET:
        u = (m) => m === g ? void 0 : m;
        break;
      case S.FIRST:
        f(), o = 0, u = a[o];
        break;
      case S.LAST:
        f(), o = a.length - 1, u = a[o];
        break;
      case S.SET_INDEX:
        f(), o = h, u = a[o];
        break;
      case S.INCREASE:
        f(), o = w, o < 0 && (o = a.indexOf(g)), o++, o >= a.length && (o = 0), u = a[o];
        break;
      case S.DECREASE:
        f(), o = w, o < 0 && (o = a.indexOf(g)), o--, o < 0 && (o = a.length - 1), u = a[o];
        break;
      default:
        if (process.env.NODE_ENV !== "production")
          throw new Error(`[React-Menu] Unknown hover action type: ${b}`);
    }
    u || (o = -1), i(u), r.hoverIndex = o;
  }, [e, r]);
  return {
    hoverItem: n,
    dispatch: p,
    updateItems: c
  };
}, pn = (e, t, n, i) => {
  const l = t.current.getBoundingClientRect(), r = e.current.getBoundingClientRect(), c = n === window ? {
    left: 0,
    top: 0,
    right: document.documentElement.clientWidth,
    bottom: window.innerHeight
  } : n.getBoundingClientRect(), p = tn(i), b = (o) => o + r.left - c.left - p.left, g = (o) => o + r.left + l.width - c.right + p.right, h = (o) => o + r.top - c.top - p.top, a = (o) => o + r.top + l.height - c.bottom + p.bottom;
  return {
    menuRect: l,
    containerRect: r,
    getLeftOverflow: b,
    getRightOverflow: g,
    getTopOverflow: h,
    getBottomOverflow: a,
    confineHorizontally: (o) => {
      let u = b(o);
      if (u < 0)
        o -= u;
      else {
        const m = g(o);
        m > 0 && (o -= m, u = b(o), u < 0 && (o -= u));
      }
      return o;
    },
    confineVertically: (o) => {
      let u = h(o);
      if (u < 0)
        o -= u;
      else {
        const m = a(o);
        m > 0 && (o -= m, u = h(o), u < 0 && (o -= u));
      }
      return o;
    }
  };
}, mn = ({
  arrowRef: e,
  menuY: t,
  anchorRect: n,
  containerRect: i,
  menuRect: l
}) => {
  let r = n.top - i.top - t + n.height / 2;
  const c = e.current.offsetHeight * 1.25;
  return r = Math.max(c, r), r = Math.min(r, l.height - c), r;
}, hn = ({
  anchorRect: e,
  containerRect: t,
  menuRect: n,
  placeLeftorRightY: i,
  placeLeftX: l,
  placeRightX: r,
  getLeftOverflow: c,
  getRightOverflow: p,
  confineHorizontally: b,
  confineVertically: g,
  arrowRef: h,
  arrow: a,
  direction: w,
  position: f
}) => {
  let o = w, u = i;
  f !== "initial" && (u = g(u), f === "anchor" && (u = Math.min(u, e.bottom - t.top), u = Math.max(u, e.top - t.top - n.height)));
  let m, E, d;
  return o === "left" ? (m = l, f !== "initial" && (E = c(m), E < 0 && (d = p(r), (d <= 0 || -E > d) && (m = r, o = "right")))) : (m = r, f !== "initial" && (d = p(m), d > 0 && (E = c(l), (E >= 0 || -E < d) && (m = l, o = "left")))), f === "auto" && (m = b(m)), {
    arrowY: a ? mn({
      menuY: u,
      arrowRef: h,
      anchorRect: e,
      containerRect: t,
      menuRect: n
    }) : void 0,
    x: m,
    y: u,
    computedDirection: o
  };
}, bn = ({
  arrowRef: e,
  menuX: t,
  anchorRect: n,
  containerRect: i,
  menuRect: l
}) => {
  let r = n.left - i.left - t + n.width / 2;
  const c = e.current.offsetWidth * 1.25;
  return r = Math.max(c, r), r = Math.min(r, l.width - c), r;
}, gn = ({
  anchorRect: e,
  containerRect: t,
  menuRect: n,
  placeToporBottomX: i,
  placeTopY: l,
  placeBottomY: r,
  getTopOverflow: c,
  getBottomOverflow: p,
  confineHorizontally: b,
  confineVertically: g,
  arrowRef: h,
  arrow: a,
  direction: w,
  position: f
}) => {
  let o = w === "top" ? "top" : "bottom", u = i;
  f !== "initial" && (u = b(u), f === "anchor" && (u = Math.min(u, e.right - t.left), u = Math.max(u, e.left - t.left - n.width)));
  let m, E, d;
  return o === "top" ? (m = l, f !== "initial" && (E = c(m), E < 0 && (d = p(r), (d <= 0 || -E > d) && (m = r, o = "bottom")))) : (m = r, f !== "initial" && (d = p(m), d > 0 && (E = c(l), (E >= 0 || -E < d) && (m = l, o = "top")))), f === "auto" && (m = g(m)), {
    arrowX: a ? bn({
      menuX: u,
      arrowRef: h,
      anchorRect: e,
      containerRect: t,
      menuRect: n
    }) : void 0,
    x: u,
    y: m,
    computedDirection: o
  };
}, En = ({
  arrow: e,
  align: t,
  direction: n,
  gap: i,
  shift: l,
  position: r,
  anchorRect: c,
  arrowRef: p,
  positionHelpers: b
}) => {
  const {
    menuRect: g,
    containerRect: h
  } = b, a = n === "left" || n === "right";
  let w = a ? i : l, f = a ? l : i;
  if (e) {
    const C = p.current;
    a ? w += C.offsetWidth : f += C.offsetHeight;
  }
  const o = c.left - h.left - g.width - w, u = c.right - h.left + w, m = c.top - h.top - g.height - f, E = c.bottom - h.top + f;
  let d, y;
  t === "end" ? (d = c.right - h.left - g.width, y = c.bottom - h.top - g.height) : t === "center" ? (d = c.left - h.left - (g.width - c.width) / 2, y = c.top - h.top - (g.height - c.height) / 2) : (d = c.left - h.left, y = c.top - h.top), d += w, y += f;
  const _ = {
    ...b,
    anchorRect: c,
    placeLeftX: o,
    placeRightX: u,
    placeLeftorRightY: y,
    placeTopY: m,
    placeBottomY: E,
    placeToporBottomX: d,
    arrowRef: p,
    arrow: e,
    direction: n,
    position: r
  };
  switch (n) {
    case "left":
    case "right":
      return hn(_);
    case "top":
    case "bottom":
    default:
      return gn(_);
  }
}, ge = typeof window < "u" && typeof window.document < "u" && typeof window.document.createElement < "u" ? Kt : V;
function ft(e, t) {
  typeof e == "function" ? e(t) : e.current = t;
}
const je = (e, t) => H(() => e ? t ? (n) => {
  ft(e, n), ft(t, n);
} : e : t, [e, t]), dt = -9999, vn = ({
  ariaLabel: e,
  menuClassName: t,
  menuStyle: n,
  arrow: i,
  arrowProps: l = {},
  anchorPoint: r,
  anchorRef: c,
  containerRef: p,
  containerProps: b,
  focusProps: g,
  externalRef: h,
  parentScrollingRef: a,
  align: w = "start",
  direction: f = "bottom",
  position: o = "auto",
  overflow: u = "visible",
  setDownOverflow: m,
  repositionFlag: E,
  captureFocus: d = !0,
  state: y,
  endTransition: _,
  isDisabled: C,
  menuItemFocus: F,
  gap: B = 0,
  shift: K = 0,
  children: se,
  onClose: z,
  ...T
}) => {
  const [D, ie] = $({
    x: dt,
    y: dt
  }), [Ue, Mt] = $({}), [X, fe] = $(), [Y, xt] = $(f), [J] = $(fn), [$e, Ke] = Vt((v) => v + 1, 1), {
    transition: Ve,
    boundingBoxRef: Se,
    boundingBoxPadding: Xe,
    rootMenuRef: qe,
    rootAnchorRef: Ce,
    scrollNodesRef: kt,
    reposition: We,
    viewScroll: Oe,
    submenuCloseDelay: It
  } = G(ze), {
    submenuCtx: Ge,
    reposSubmenu: Pt = E
  } = G(lt), q = x(null), de = x(), Ye = x(), Je = x(!1), pe = x({
    width: 0,
    height: 0
  }), Qe = x(() => {
  }), {
    hoverItem: _e,
    dispatch: I,
    updateItems: me
  } = dn(q, de), P = ht(y), Ze = le(Ve, "open"), et = le(Ve, "close"), A = kt.current, Rt = (v) => {
    switch (v.key) {
      case L.HOME:
        I(S.FIRST);
        break;
      case L.END:
        I(S.LAST);
        break;
      case L.UP:
        I(S.DECREASE, _e);
        break;
      case L.DOWN:
        I(S.INCREASE, _e);
        break;
      case L.SPACE:
        v.target && v.target.className.indexOf(be) !== -1 && v.preventDefault();
        return;
      default:
        return;
    }
    v.preventDefault(), v.stopPropagation();
  }, Dt = () => {
    y === "closing" && fe(), k(_);
  }, At = (v) => {
    v.stopPropagation(), J.on(It, () => {
      I(S.RESET), de.current.focus();
    });
  }, Lt = (v) => {
    v.target === v.currentTarget && J.off();
  }, W = oe((v) => {
    var M;
    const j = c ? (M = c.current) == null ? void 0 : M.getBoundingClientRect() : r ? {
      left: r.x,
      right: r.x,
      top: r.y,
      bottom: r.y,
      width: 0,
      height: 0
    } : null;
    if (!j) {
      process.env.NODE_ENV !== "production" && console.warn("[React-Menu] Menu might not be positioned properly as one of the anchorRef or anchorPoint prop should be provided. If `anchorRef` is provided, the anchor must be mounted before menu is open.");
      return;
    }
    A.menu || (A.menu = (Se ? Se.current : Ie(qe.current)) || window);
    const R = pn(p, q, A.menu, Xe);
    let {
      arrowX: N,
      arrowY: Q,
      x: Z,
      y: U,
      computedDirection: xe
    } = En({
      arrow: i,
      align: w,
      direction: f,
      gap: B,
      shift: K,
      position: o,
      anchorRect: j,
      arrowRef: Ye,
      positionHelpers: R
    });
    const {
      menuRect: rt
    } = R;
    let ee = rt.height;
    if (!v && u !== "visible") {
      const {
        getTopOverflow: Ut,
        getBottomOverflow: $t
      } = R;
      let te, ke;
      const st = pe.current.height, he = $t(U);
      if (he > 0 || ne(he, 0) && ne(ee, st))
        te = ee - he, ke = he;
      else {
        const ce = Ut(U);
        (ce < 0 || ne(ce, 0) && ne(ee, st)) && (te = ee + ce, ke = 0 - ce, te >= 0 && (U -= ce));
      }
      te >= 0 ? (ee = te, fe({
        height: te,
        overflowAmt: ke
      })) : fe();
    }
    i && Mt({
      x: N,
      y: Q
    }), ie({
      x: Z,
      y: U
    }), xt(xe), pe.current = {
      width: rt.width,
      height: ee
    };
  }, [i, w, Xe, f, B, K, o, u, r, c, p, Se, qe, A]);
  ge(() => {
    P && (W(), Je.current && Ke()), Je.current = P, Qe.current = W;
  }, [P, W, Pt]), ge(() => {
    X && !m && (q.current.scrollTop = 0);
  }, [X, m]), ge(() => me, [me]), V(() => {
    let {
      menu: v
    } = A;
    if (!P || !v)
      return;
    if (v = v.addEventListener ? v : window, !A.anchors) {
      A.anchors = [];
      let N = Ie(Ce && Ce.current);
      for (; N && N !== v; )
        A.anchors.push(N), N = Ie(N);
    }
    let M = Oe;
    if (A.anchors.length && M === "initial" && (M = "auto"), M === "initial")
      return;
    const j = () => {
      M === "auto" ? ct(() => W(!0)) : k(z, {
        reason: ae.SCROLL
      });
    }, R = A.anchors.concat(Oe !== "initial" ? v : []);
    return R.forEach((N) => N.addEventListener("scroll", j)), () => R.forEach((N) => N.removeEventListener("scroll", j));
  }, [Ce, A, P, z, Oe, W]);
  const tt = !!X && X.overflowAmt > 0;
  V(() => {
    if (tt || !P || !a)
      return;
    const v = () => ct(W), M = a.current;
    return M.addEventListener("scroll", v), () => M.removeEventListener("scroll", v);
  }, [P, tt, a, W]), V(() => {
    if (typeof ResizeObserver != "function" || We === "initial")
      return;
    const v = new ResizeObserver(([j]) => {
      const {
        borderBoxSize: R,
        target: N
      } = j;
      let Q, Z;
      if (R) {
        const {
          inlineSize: U,
          blockSize: xe
        } = R[0] || R;
        Q = U, Z = xe;
      } else {
        const U = N.getBoundingClientRect();
        Q = U.width, Z = U.height;
      }
      Q === 0 || Z === 0 || ne(Q, pe.current.width, 1) && ne(Z, pe.current.height, 1) || Jt(() => {
        Qe.current(), Ke();
      });
    }), M = q.current;
    return v.observe(M, {
      box: "border-box"
    }), () => v.unobserve(M);
  }, [We]), V(() => {
    if (!P) {
      I(S.RESET), et || fe();
      return;
    }
    const {
      position: v,
      alwaysUpdate: M
    } = F || {}, j = () => {
      v === ue.FIRST ? I(S.FIRST) : v === ue.LAST ? I(S.LAST) : v >= -1 && I(S.SET_INDEX, void 0, v);
    };
    if (M)
      j();
    else if (d) {
      const R = setTimeout(() => {
        const N = q.current;
        N && !N.contains(document.activeElement) && (de.current.focus(), j());
      }, Ze ? 170 : 100);
      return () => clearTimeout(R);
    }
  }, [P, Ze, et, d, F, I]);
  const Ht = H(() => ({
    isParentOpen: P,
    submenuCtx: J,
    dispatch: I,
    updateItems: me
  }), [P, J, I, me]);
  let Ne, Me;
  X && (m ? Me = X.overflowAmt : Ne = X.height);
  const zt = H(() => ({
    reposSubmenu: $e,
    submenuCtx: J,
    overflow: u,
    overflowAmt: Me,
    parentMenuRef: q,
    parentDir: Y
  }), [$e, J, u, Me, Y]), jt = Ne >= 0 ? {
    maxHeight: Ne,
    overflow: u
  } : void 0, nt = H(() => ({
    state: y,
    dir: Y
  }), [y, Y]), Ft = H(() => ({
    dir: Y
  }), [Y]), Bt = Ee({
    block: be,
    element: sn,
    modifiers: Ft,
    className: l.className
  }), ot = /* @__PURE__ */ mt("ul", {
    role: "menu",
    "aria-label": e,
    ...bt(C),
    ...Te({
      onPointerEnter: Ge == null ? void 0 : Ge.off,
      onPointerMove: At,
      onPointerLeave: Lt,
      onKeyDown: Rt,
      onAnimationEnd: Dt
    }, T),
    ref: je(h, q),
    className: Ee({
      block: be,
      modifiers: nt,
      className: t
    }),
    style: {
      ...n,
      ...jt,
      margin: 0,
      display: y === "closed" ? "none" : void 0,
      position: Pe,
      left: D.x,
      top: D.y
    },
    children: [/* @__PURE__ */ O("li", {
      tabIndex: -1,
      style: {
        position: Pe,
        left: 0,
        top: 0,
        display: "block",
        outline: "none"
      },
      ref: de,
      ...at,
      ...g
    }), i && /* @__PURE__ */ O("li", {
      ...at,
      ...l,
      className: Bt,
      style: {
        display: "block",
        position: Pe,
        left: Ue.x,
        top: Ue.y,
        ...l.style
      },
      ref: Ye
    }), /* @__PURE__ */ O(lt.Provider, {
      value: zt,
      children: /* @__PURE__ */ O(wt.Provider, {
        value: Ht,
        children: /* @__PURE__ */ O(vt.Provider, {
          value: _e,
          children: k(se, nt)
        })
      })
    })]
  });
  return b ? /* @__PURE__ */ O(an, {
    ...b,
    isOpen: P,
    children: ot
  }) : ot;
}, Ct = /* @__PURE__ */ He(function({
  "aria-label": t,
  className: n,
  containerProps: i,
  initialMounted: l,
  unmountOnClose: r,
  transition: c,
  transitionTimeout: p,
  boundingBoxRef: b,
  boundingBoxPadding: g,
  reposition: h = "auto",
  submenuOpenDelay: a = 300,
  submenuCloseDelay: w = 150,
  viewScroll: f = "initial",
  portal: o,
  theming: u,
  onItemClick: m,
  ...E
}, d) {
  const y = x(null), _ = x({}), {
    anchorRef: C,
    state: F,
    onClose: B
  } = E, K = H(() => ({
    initialMounted: l,
    unmountOnClose: r,
    transition: c,
    transitionTimeout: p,
    boundingBoxRef: b,
    boundingBoxPadding: g,
    rootMenuRef: y,
    rootAnchorRef: C,
    scrollNodesRef: _,
    reposition: h,
    viewScroll: f,
    submenuOpenDelay: a,
    submenuCloseDelay: w
  }), [l, r, c, p, C, b, g, h, f, a, w]), se = H(() => ({
    handleClick(T, D) {
      T.stopPropagation || k(m, T);
      let ie = T.keepOpen;
      ie === void 0 && (ie = D && T.key === L.SPACE), ie || k(B, {
        value: T.value,
        key: T.key,
        reason: ae.CLICK
      });
    },
    handleClose(T) {
      k(B, {
        key: T,
        reason: ae.CLICK
      });
    }
  }), [m, B]);
  if (!F)
    return null;
  const z = /* @__PURE__ */ O(ze.Provider, {
    value: K,
    children: /* @__PURE__ */ O(yt.Provider, {
      value: se,
      children: /* @__PURE__ */ O(vn, {
        ...E,
        ariaLabel: t || "Menu",
        externalRef: d,
        containerRef: y,
        containerProps: {
          className: n,
          containerRef: y,
          containerProps: i,
          theming: u,
          transition: c,
          onClose: B
        }
      })
    })
  });
  return o === !0 && typeof document < "u" ? /* @__PURE__ */ it(z, document.body) : o ? o.target ? /* @__PURE__ */ it(z, o.target) : o.stablePosition ? null : z : z;
});
process.env.NODE_ENV !== "production" && (Ct.propTypes = {
  ...Et,
  state: /* @__PURE__ */ s.oneOf(/* @__PURE__ */ Qt(Tt)),
  anchorPoint: /* @__PURE__ */ s.exact({
    x: s.number,
    y: s.number
  }),
  anchorRef: s.object,
  captureFocus: s.bool,
  menuItemFocus: /* @__PURE__ */ s.exact({
    position: /* @__PURE__ */ s.oneOfType([s.string, s.number]),
    alwaysUpdate: s.bool
  }),
  onClose: s.func
});
const Re = 0, De = 1, ve = 2, we = 3, ye = 4, wn = 5, Ot = 6, yn = ["preEnter", "entering", "entered", "preExit", "exiting", "exited", "unmounted"], _t = (e) => ({
  _s: e,
  status: yn[e],
  isEnter: e < we,
  isMounted: e !== Ot,
  isResolved: e === ve || e > ye
}), Ae = (e) => e ? Ot : wn, Tn = (e, t) => {
  switch (e) {
    case De:
    case Re:
      return ve;
    case ye:
    case we:
      return Ae(t);
  }
}, Sn = (e) => typeof e == "object" ? [e.enter, e.exit] : [e, e], Cn = (e, t) => setTimeout(() => {
  isNaN(document.body.offsetTop) || e(t + 1);
}, 0), pt = (e, t, n, i, l) => {
  clearTimeout(i.current);
  const r = _t(e);
  t(r), n.current = r, l && l({
    current: r
  });
}, On = ({
  enter: e = !0,
  exit: t = !0,
  preEnter: n,
  preExit: i,
  timeout: l,
  initialEntered: r,
  mountOnEnter: c,
  unmountOnExit: p,
  onStateChange: b
} = {}) => {
  const [g, h] = $(() => _t(r ? ve : Ae(c))), a = x(g), w = x(), [f, o] = Sn(l), u = oe(() => {
    const E = Tn(a.current._s, p);
    E && pt(E, h, a, w, b);
  }, [b, p]), m = oe((E) => {
    const d = (_) => {
      switch (pt(_, h, a, w, b), _) {
        case De:
          f >= 0 && (w.current = setTimeout(u, f));
          break;
        case ye:
          o >= 0 && (w.current = setTimeout(u, o));
          break;
        case Re:
        case we:
          w.current = Cn(d, _);
          break;
      }
    }, y = a.current.isEnter;
    typeof E != "boolean" && (E = !y), E ? !y && d(e ? n ? Re : De : ve) : y && d(t ? i ? we : ye : Ae(p));
  }, [u, b, e, t, n, i, f, o, p]);
  return V(() => () => clearTimeout(w.current), []), [g, m, u];
}, _n = ({
  initialOpen: e,
  initialMounted: t,
  unmountOnClose: n,
  transition: i,
  transitionTimeout: l = 500
} = {}) => {
  const [{
    status: r
  }, c, p] = On({
    initialEntered: e,
    mountOnEnter: !t,
    unmountOnExit: n,
    timeout: l,
    enter: le(i, "open"),
    exit: le(i, "close")
  });
  return [{
    state: Tt[r],
    endTransition: p
  }, c];
}, Nn = (e) => {
  const [t, n] = _n(e), [i, l] = $(), r = (c, p) => {
    l({
      position: c,
      alwaysUpdate: p
    }), n(!0);
  };
  return [{
    menuItemFocus: i,
    ...t
  }, n, r];
}, Mn = (e, t) => {
  if (process.env.NODE_ENV !== "production" && typeof t != "function")
    throw new Error("[React-Menu] useClick/useHover requires a function in the second parameter.");
  const [n] = $({});
  return {
    onMouseDown: () => {
      n.v = e && e !== "closed";
    },
    onClick: (i) => n.v ? n.v = !1 : t(!0, i)
  };
}, xn = (e, t) => {
  const n = x(t);
  V(() => {
    n.current !== t && k(e, {
      open: t
    }), n.current = t;
  }, [e, t]);
}, Fe = /* @__PURE__ */ He(function({
  "aria-label": t,
  captureFocus: n,
  initialOpen: i,
  menuButton: l,
  instanceRef: r,
  onMenuChange: c,
  ...p
}, b) {
  const [g, h, a] = Nn(p), {
    state: w
  } = g, f = ht(w), o = x(null), u = Mn(w, (C, F) => a(F.detail ? void 0 : ue.FIRST)), m = oe((C) => {
    h(!1), C.key && o.current.focus();
  }, [h]), E = (C) => {
    switch (C.key) {
      case L.UP:
        a(ue.LAST);
        break;
      case L.DOWN:
        a(ue.FIRST);
        break;
      default:
        return;
    }
    C.preventDefault();
  }, d = k(l, {
    open: f
  });
  if (!d || !d.type)
    throw new Error("Menu requires a menuButton prop.");
  const y = {
    ref: je(d.ref, o),
    ...Te({
      onKeyDown: E,
      ...u
    }, d.props)
  };
  en(d.type) === "MenuButton" && (y.isOpen = f);
  const _ = /* @__PURE__ */ Wt(d, y);
  return xn(c, f), Xt(r, () => ({
    openMenu: a,
    closeMenu: () => h(!1)
  })), /* @__PURE__ */ mt(qt, {
    children: [_, /* @__PURE__ */ O(Ct, {
      ...p,
      ...g,
      "aria-label": t || (typeof d.props.children == "string" ? d.props.children : "Menu"),
      anchorRef: o,
      ref: b,
      onClose: m
    })]
  });
});
process.env.NODE_ENV !== "production" && (Fe.propTypes = {
  ...Et,
  ...on,
  menuButton: s.oneOfType([s.element, s.func]).isRequired
});
const kn = (e, t) => {
  const n = /* @__PURE__ */ Gt(t), i = /* @__PURE__ */ He((l, r) => {
    const c = x(null);
    return /* @__PURE__ */ O(n, {
      ...l,
      itemRef: c,
      externalRef: r,
      isHovering: G(vt) === c.current
    });
  });
  return i.displayName = `WithHovering(${e})`, i;
}, In = (e, t, n) => {
  ge(() => {
    if (process.env.NODE_ENV !== "production" && !n)
      throw new Error(`[React-Menu] This menu item or submenu should be rendered under a menu: ${t.current.outerHTML}`);
    if (e)
      return;
    const i = t.current;
    return n(i, !0), () => {
      n(i);
    };
  }, [e, t, n]);
}, Pn = (e, t, n, i) => {
  const {
    submenuCloseDelay: l
  } = G(ze), {
    isParentOpen: r,
    submenuCtx: c,
    dispatch: p,
    updateItems: b
  } = G(wt), g = () => {
    !n && !i && p(S.SET, e.current);
  }, h = () => {
    !i && p(S.UNSET, e.current);
  }, a = (o) => {
    n && !o.currentTarget.contains(o.relatedTarget) && h();
  }, w = (o) => {
    i || (o.stopPropagation(), c.on(l, g, g));
  }, f = (o, u) => {
    c.off(), !u && h();
  };
  return In(i, e, b), V(() => {
    n && r && t.current && t.current.focus();
  }, [t, n, r]), {
    setHover: g,
    onBlur: a,
    onPointerMove: w,
    onPointerLeave: f
  };
}, Nt = /* @__PURE__ */ kn("MenuItem", function({
  className: t,
  value: n,
  href: i,
  type: l,
  checked: r,
  disabled: c,
  children: p,
  onClick: b,
  isHovering: g,
  itemRef: h,
  externalRef: a,
  ...w
}) {
  const f = !!c, {
    setHover: o,
    ...u
  } = Pn(h, h, g, f), m = G(yt), E = G(un), d = l === "radio", y = l === "checkbox", _ = !!i && !f && !d && !y, C = d ? E.value === n : y ? !!r : !1, F = (T) => {
    if (f) {
      T.stopPropagation(), T.preventDefault();
      return;
    }
    const D = {
      value: n,
      syntheticEvent: T
    };
    T.key !== void 0 && (D.key = T.key), y && (D.checked = !C), d && (D.name = E.name), k(b, D), d && k(E.onRadioChange, D), m.handleClick(D, y || d);
  }, B = (T) => {
    if (g)
      switch (T.key) {
        case L.ENTER:
          T.preventDefault();
        case L.SPACE:
          _ ? h.current.click() : F(T);
      }
  }, K = H(() => ({
    type: l,
    disabled: f,
    hover: g,
    checked: C,
    anchor: _
  }), [l, f, g, C, _]), se = Te({
    ...u,
    onPointerDown: o,
    onKeyDown: B,
    onClick: F
  }, w), z = {
    role: d ? "menuitemradio" : y ? "menuitemcheckbox" : St,
    "aria-checked": d || y ? C : void 0,
    ...bt(f, g),
    ...se,
    ref: je(a, h),
    className: Ee({
      block: be,
      element: cn,
      modifiers: K,
      className: t
    }),
    children: H(() => k(p, K), [p, K])
  };
  return _ ? /* @__PURE__ */ O("li", {
    role: ln,
    children: /* @__PURE__ */ O("a", {
      href: i,
      ...z
    })
  }) : /* @__PURE__ */ O("li", {
    ...z
  });
});
process.env.NODE_ENV !== "production" && (Nt.propTypes = {
  ...gt(),
  value: s.any,
  href: s.string,
  type: /* @__PURE__ */ s.oneOf(["checkbox", "radio"]),
  checked: s.bool,
  disabled: s.bool,
  children: /* @__PURE__ */ s.oneOfType([s.node, s.func]),
  onClick: s.func
});
const Rn = "_menu__inner_1y02q_1", Dn = "_menu__item_1y02q_11", An = "_menu__action__list_1y02q_19", Be = {
  menu__inner: Rn,
  menu__item: Dn,
  menu__action__list: An
}, Ln = ({ menuClassName: e, ...t }) => /* @__PURE__ */ O(Fe, { menuClassName: Le(Be.menu__inner, e), ...t }), Hn = ({ className: e, ...t }) => /* @__PURE__ */ O(
  Nt,
  {
    className: ({ disabled: n, hover: i }) => Le(Be.menu__item, e, { "!_text-disabled": n, "!_bg-primary/20": i }),
    ...t
  }
), zn = ({ menuClassName: e, transition: t = !0, ...n }) => /* @__PURE__ */ O(Fe, { transition: t, menuClassName: Le(Be.menu__action__list, e), ...n }), Kn = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
  __proto__: null,
  MenuActionList: zn,
  MenuItem: Hn,
  MenuList: Ln
}, Symbol.toStringTag, { value: "Module" }));
export {
  Ln as M,
  Hn as a,
  zn as b,
  Kn as i
};
