import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
import React, { useRef } from 'react';
import classNames from 'classnames';
import { Menu as RcMenu } from '../components';
import { ConfigContext } from '../config-provider/context';
import { cloneElement } from '../utils/ReactNodeValidate';
import MenuContext from './MenuContext';
import Item from './MenuItem';
import { SubMenu } from './SubMenuItem';
var MenuRC = RcMenu.default;
var ItemGroup = RcMenu.ItemGroup;
var Menu = /*#__PURE__*/React.forwardRef(function (props, ref) {
  var theme = props.theme,
      prefixCls = props.prefixCls,
      className = props.className,
      expandIcon = props.expandIcon,
      restProps = _objectWithoutProperties(props, ["theme", "prefixCls", "className", "expandIcon"]);

  var _React$useContext = React.useContext(ConfigContext),
      getPrefixClassName = _React$useContext.getPrefixClassName;

  var menuRef = ref || useRef(null);
  var menuCls = getPrefixClassName('menu', prefixCls);

  var getInlineCollapsed = function getInlineCollapsed() {
    var inlineCollapsed = props.inlineCollapsed,
        siderCollapsed = props.siderCollapsed;

    if (siderCollapsed !== undefined) {
      return siderCollapsed;
    }

    return inlineCollapsed;
  };

  var endCls = classNames("".concat(menuCls, "-").concat(theme), _defineProperty({}, "".concat(prefixCls, "-inline-collapsed"), getInlineCollapsed()), className);

  var comProps = _objectSpread({
    ref: menuRef,
    className: endCls
  }, restProps);

  return /*#__PURE__*/React.createElement(MenuContext.Provider, {
    value: {
      kleinMenuTheme: theme,
      inlineCollapsed: getInlineCollapsed() || false
    }
  }, /*#__PURE__*/React.createElement(MenuRC, Object.assign({
    prefixCls: menuCls
  }, comProps, {
    expandIcon: cloneElement(expandIcon, {
      className: "".concat(prefixCls, "-submenu-expand-icon")
    })
  })));
});
Menu.displayName = 'Menu';
Menu.defaultProps = {
  theme: 'light',
  mode: 'vertical',
  inlineIndent: 26,
  multiple: false
};
export { Item, SubMenu, ItemGroup };
export default Menu;