import I from "../../../@babel/runtime/helpers/esm/defineProperty.mjs";
import W from "../../../@babel/runtime/helpers/esm/extends.mjs";
import q from "../../../@babel/runtime/helpers/esm/objectSpread2.mjs";
import ke from "../../../@babel/runtime/helpers/esm/slicedToArray.mjs";
import B from "../../../@babel/runtime/helpers/esm/objectWithoutProperties.mjs";
import * as n from "react";
import Ke from "../../../classnames/index.mjs";
import Ne from "../../../rc-overflow/es/Overflow.mjs";
import { warningOnce as _e } from "../../../rc-util/es/warning.mjs";
import Re from "./SubMenuList.mjs";
import { parseChildren as Te } from "../utils/commonUtil.mjs";
import G, { MenuContext as Le } from "../context/MenuContext.mjs";
import Oe from "../hooks/useMemoCallback.mjs";
import we from "./PopupTrigger.mjs";
import Ae from "../Icon.mjs";
import De from "../hooks/useActive.mjs";
import { warnItemProp as Fe } from "../utils/warnUtil.mjs";
import $e from "../hooks/useDirectionStyle.mjs";
import Ve from "./InlineSubMenuList.mjs";
import { useFullPath as H, useMeasure as ze, PathTrackerContext as je, PathUserContext as Ue } from "../context/PathContext.mjs";
import { useMenuId as We } from "../context/IdContext.mjs";
import qe from "../context/PrivateContext.mjs";
var Be = ["style", "className", "title", "eventKey", "warnKey", "disabled", "internalPopupClose", "children", "itemIcon", "expandIcon", "popupClassName", "popupOffset", "popupStyle", "onClick", "onMouseEnter", "onMouseLeave", "onTitleClick", "onTitleMouseEnter", "onTitleMouseLeave"], Ge = ["active"], He = function(e) {
  var l, m = e.style, f = e.className, c = e.title, t = e.eventKey, J = e.warnKey, Q = e.disabled, X = e.internalPopupClose, T = e.children, h = e.itemIcon, y = e.expandIcon, Y = e.popupClassName, Z = e.popupOffset, ee = e.popupStyle, b = e.onClick, M = e.onMouseEnter, x = e.onMouseLeave, E = e.onTitleClick, ne = e.onTitleMouseEnter, te = e.onTitleMouseLeave, oe = B(e, Be), p = We(t), o = n.useContext(Le), re = o.prefixCls, r = o.mode, ae = o.openKeys, ie = o.disabled, C = o.overflowDisabled, L = o.activeKey, le = o.selectedKeys, ce = o.itemIcon, ue = o.expandIcon, se = o.onItemClick, O = o.onOpenChange, me = o.onActive, de = n.useContext(qe), w = de._internalRenderSubMenuItem, ve = n.useContext(Ue), P = ve.isSubPathKey, S = H(), a = "".concat(re, "-submenu"), u = ie || Q, fe = n.useRef(), pe = n.useRef();
  process.env.NODE_ENV !== "production" && J && _e(!1, "SubMenu should not leave undefined `key`.");
  var Ce = h ?? ce, A = y ?? ue, D = ae.includes(t), d = !C && D, F = P(le, t), $ = De(t, u, ne, te), g = $.active, Ie = B($, Ge), he = n.useState(!1), V = ke(he, 2), z = V[0], ye = V[1], j = function(i) {
    u || ye(i);
  }, be = function(i) {
    j(!0), M == null || M({
      key: t,
      domEvent: i
    });
  }, Me = function(i) {
    j(!1), x == null || x({
      key: t,
      domEvent: i
    });
  }, U = n.useMemo(function() {
    return g || (r !== "inline" ? z || P([L], t) : !1);
  }, [r, g, L, z, t, P]), xe = $e(S.length), Ee = function(i) {
    u || (E == null || E({
      key: t,
      domEvent: i
    }), r === "inline" && O(t, !D));
  }, Pe = Oe(function(s) {
    b == null || b(Fe(s)), se(s);
  }), Se = function(i) {
    r !== "inline" && O(t, i);
  }, ge = function() {
    me(t);
  }, k = p && "".concat(p, "-popup"), K = /* @__PURE__ */ n.createElement("div", W({
    role: "menuitem",
    style: xe,
    className: "".concat(a, "-title"),
    tabIndex: u ? null : -1,
    ref: fe,
    title: typeof c == "string" ? c : null,
    "data-menu-id": C && p ? null : p,
    "aria-expanded": d,
    "aria-haspopup": !0,
    "aria-controls": k,
    "aria-disabled": u,
    onClick: Ee,
    onFocus: ge
  }, Ie), c, /* @__PURE__ */ n.createElement(Ae, {
    icon: r !== "horizontal" ? A : void 0,
    props: q(q({}, e), {}, {
      isOpen: d,
      // [Legacy] Not sure why need this mark
      isSubMenu: !0
    })
  }, /* @__PURE__ */ n.createElement("i", {
    className: "".concat(a, "-arrow")
  }))), N = n.useRef(r);
  if (r !== "inline" && S.length > 1 ? N.current = "vertical" : N.current = r, !C) {
    var _ = N.current;
    K = /* @__PURE__ */ n.createElement(we, {
      mode: _,
      prefixCls: a,
      visible: !X && d && r !== "inline",
      popupClassName: Y,
      popupOffset: Z,
      popupStyle: ee,
      popup: /* @__PURE__ */ n.createElement(
        G,
        {
          mode: _ === "horizontal" ? "vertical" : _
        },
        /* @__PURE__ */ n.createElement(Re, {
          id: k,
          ref: pe
        }, T)
      ),
      disabled: u,
      onVisibleChange: Se
    }, K);
  }
  var R = /* @__PURE__ */ n.createElement(Ne.Item, W({
    role: "none"
  }, oe, {
    component: "li",
    style: m,
    className: Ke(a, "".concat(a, "-").concat(r), f, (l = {}, I(l, "".concat(a, "-open"), d), I(l, "".concat(a, "-active"), U), I(l, "".concat(a, "-selected"), F), I(l, "".concat(a, "-disabled"), u), l)),
    onMouseEnter: be,
    onMouseLeave: Me
  }), K, !C && /* @__PURE__ */ n.createElement(Ve, {
    id: k,
    open: d,
    keyPath: S
  }, T));
  return w && (R = w(R, e, {
    selected: F,
    active: U,
    open: d,
    disabled: u
  })), /* @__PURE__ */ n.createElement(G, {
    onItemClick: Pe,
    mode: r === "horizontal" ? "vertical" : r,
    itemIcon: Ce,
    expandIcon: A
  }, R);
};
function In(v) {
  var e = v.eventKey, l = v.children, m = H(e), f = Te(l, m), c = ze();
  n.useEffect(function() {
    if (c)
      return c.registerPath(e, m), function() {
        c.unregisterPath(e, m);
      };
  }, [m]);
  var t;
  return c ? t = f : t = /* @__PURE__ */ n.createElement(He, v, f), /* @__PURE__ */ n.createElement(je.Provider, {
    value: m
  }, t);
}
export {
  In as default
};
