"use strict";
const React = require("react");
const classNames = require("../../_util/classNames.js");
const index$4 = require("../../../icon/react-icon/IconRight/index.js");
const index$3 = require("../../../icon/react-icon/IconLeft/index.js");
const index$5 = require("../../../icon/react-icon/IconDown/index.js");
const util = require("../util.js");
const omit = require("../../_util/omit.js");
const index$2 = require("../../Dropdown/index.js");
const index$1 = require("../index.js");
const indent = require("../indent.js");
const context = require("../context.js");
const index = require("../../ConfigProvider/index.js");
const keycode = require("../../_util/keycode.js");
const useId = require("../../_util/hooks/useId.js");
const emotionReactJsxRuntime_browser_esm = require("../../../../../../../@emotion_react@11.10.4_3toe27fv7etiytxb5kxc7fxaw4/node_modules/@emotion/react/jsx-runtime/dist/emotion-react-jsx-runtime.browser.esm.js");
var __assign = globalThis && globalThis.__assign || function() {
  __assign = Object.assign || function(t) {
    for (var s, i = 1, n = arguments.length; i < n; i++) {
      s = arguments[i];
      for (var p in s)
        if (Object.prototype.hasOwnProperty.call(s, p))
          t[p] = s[p];
    }
    return t;
  };
  return __assign.apply(this, arguments);
};
var __read = globalThis && globalThis.__read || function(o, n) {
  var m = typeof Symbol === "function" && o[Symbol.iterator];
  if (!m)
    return o;
  var i = m.call(o), r, ar = [], e;
  try {
    while ((n === void 0 || n-- > 0) && !(r = i.next()).done)
      ar.push(r.value);
  } catch (error) {
    e = {
      error
    };
  } finally {
    try {
      if (r && !r.done && (m = i["return"]))
        m.call(i);
    } finally {
      if (e)
        throw e.error;
    }
  }
  return ar;
};
var SubMenuPop = function(props) {
  var _a;
  var _key = props._key, children = props.children, style = props.style, className = props.className, title = props.title, level = props.level, selectable = props.selectable, forwardedRef = props.forwardedRef, propTriggerProps = props.triggerProps;
  var _b = React.useContext(context), menuId = _b.id, prefixCls = _b.prefixCls, mode = _b.mode, inDropdown = _b.inDropdown, levelIndent = _b.levelIndent, _c = _b.selectedKeys, selectedKeys = _c === void 0 ? [] : _c, icons = _b.icons, contextTriggerProps = _b.triggerProps, onClickSubMenu = _b.onClickSubMenu, onClickMenuItem = _b.onClickMenuItem;
  var rtl = React.useContext(index.ConfigContext).rtl;
  var triggerProps = __assign(__assign({}, contextTriggerProps), propTriggerProps);
  var _d = __read(React.useState(false), 2), popupVisible = _d[0], setPopupVisible = _d[1];
  var baseClassName = prefixCls + "-pop";
  var isSelected = selectable && selectedKeys.indexOf(props._key) > -1;
  var needPopOnBottom = mode === "horizontal" && !inDropdown;
  var instanceId = useId(menuId + "-submenu-pop-");
  var renderSuffix = function() {
    var MergedIconRight = icons && icons.popArrowRight ? icons.popArrowRight : rtl ? /* @__PURE__ */ emotionReactJsxRuntime_browser_esm.jsx(index$3, {}) : /* @__PURE__ */ emotionReactJsxRuntime_browser_esm.jsx(index$4, {});
    var MergedIconDown = icons && icons.horizontalArrowDown ? icons.horizontalArrowDown : /* @__PURE__ */ emotionReactJsxRuntime_browser_esm.jsx(index$5, {});
    return /* @__PURE__ */ emotionReactJsxRuntime_browser_esm.jsx("span", {
      className: prefixCls + "-icon-suffix",
      children: needPopOnBottom ? MergedIconDown : MergedIconRight
    });
  };
  var hasSelectedStatus = util.isChildrenSelected(children, selectedKeys) || isSelected;
  var popPosition = rtl ? ["br", "lt"] : ["bl", "rt"];
  var subMenuClickHandler = function(event) {
    onClickSubMenu(_key, level, "pop");
    selectable && onClickMenuItem(_key, event);
  };
  return /* @__PURE__ */ emotionReactJsxRuntime_browser_esm.jsx(index$2, {
    trigger: "hover",
    popupVisible,
    onVisibleChange: setPopupVisible,
    droplist: /* @__PURE__ */ emotionReactJsxRuntime_browser_esm.jsx(index$1, {
      id: instanceId,
      selectedKeys,
      onClickMenuItem: function(key, event) {
        onClickMenuItem(key, event);
        setPopupVisible(false);
      },
      children
    }),
    triggerProps: __assign({
      position: needPopOnBottom ? popPosition[0] : popPosition[1],
      showArrow: true,
      autoAlignPopupMinWidth: true,
      classNames: "fadeIn",
      duration: 100,
      mouseEnterDelay: 50,
      mouseLeaveDelay: 50,
      className: classNames(baseClassName + "-trigger", triggerProps && triggerProps.className)
    }, omit(triggerProps, ["className"])),
    children: /* @__PURE__ */ emotionReactJsxRuntime_browser_esm.jsxs("div", {
      tabIndex: 0,
      "aria-haspopup": true,
      "aria-expanded": popupVisible,
      "aria-controls": instanceId,
      ref: forwardedRef,
      style,
      className: classNames(baseClassName, baseClassName + "-header", (_a = {}, _a[prefixCls + "-selected"] = hasSelectedStatus, _a), className),
      onClick: subMenuClickHandler,
      onKeyDown: function(event) {
        var keyCode = event.keyCode || event.which;
        if (keyCode === keycode.Enter.code) {
          subMenuClickHandler(event);
        } else if (keyCode === keycode.ArrowLeft.code) {
          setPopupVisible(false);
        } else if (keyCode === keycode.ArrowRight.code) {
          setPopupVisible(true);
        }
      },
      children: [/* @__PURE__ */ emotionReactJsxRuntime_browser_esm.jsx(indent, {
        prefixCls,
        levelIndent,
        level
      }), title, renderSuffix(), hasSelectedStatus && mode === "horizontal" ? /* @__PURE__ */ emotionReactJsxRuntime_browser_esm.jsx("div", {
        className: prefixCls + "-selected-label"
      }) : null]
    })
  });
};
const SubMenuPop$1 = SubMenuPop;
module.exports = SubMenuPop$1;
//# sourceMappingURL=pop.js.map
