"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");

var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard");

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.SubMenu = void 0;

var _react = _interopRequireWildcard(require("react"));

var _classnames = _interopRequireDefault(require("classnames"));

var _components = require("../components");

var _ReactNodeValidate = require("../utils/ReactNodeValidate");

var _MenuContext = _interopRequireDefault(require("./MenuContext"));

var _omit = _interopRequireDefault(require("../components/rc-util/omit"));

var _icon = _interopRequireDefault(require("../icon"));

var RcSubMenu = _components.Menu.SubMenu;
var DownLine = _icon.default.DownLine;

var SubMenu = /*#__PURE__*/_react.default.forwardRef(function (props, ref) {
  var renderTitle = function renderTitle(inlineCollapsed) {
    var icon = props.icon,
        title = props.title,
        level = props.level,
        rootPrefixCls = props.rootPrefixCls;

    if (!icon) {
      return inlineCollapsed && level === 1 && title && typeof title === 'string' ? /*#__PURE__*/_react.default.createElement("div", {
        className: "".concat(rootPrefixCls, "-inline-collapsed-noicon")
      }, title.charAt(0)) : /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, title, /*#__PURE__*/_react.default.createElement(DownLine, {
        className: "".concat(rootPrefixCls, "-submenu-arrowicon")
      }));
    }

    var titleIsSpan = (0, _ReactNodeValidate.isValidElement)(title) && title.type === 'span';
    return /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, icon, titleIsSpan ? title : /*#__PURE__*/_react.default.createElement("span", null, title), /*#__PURE__*/_react.default.createElement(DownLine, {
      className: "".concat(rootPrefixCls, "-submenu-arrowicon")
    }));
  };

  var subMenuRef = ref || (0, _react.useRef)(null);
  var rootPrefixCls = props.rootPrefixCls,
      popupClassName = props.popupClassName;
  return /*#__PURE__*/_react.default.createElement(_MenuContext.default.Consumer, null, function (_ref) {
    var kleinMenuTheme = _ref.kleinMenuTheme,
        inlineCollapsed = _ref.inlineCollapsed;
    return /*#__PURE__*/_react.default.createElement(RcSubMenu, Object.assign({
      ref: subMenuRef
    }, (0, _omit.default)(props, ['icon']), {
      title: renderTitle(inlineCollapsed),
      popupClassName: (0, _classnames.default)(rootPrefixCls, "".concat(rootPrefixCls, "-").concat(kleinMenuTheme), popupClassName)
    }));
  });
});

exports.SubMenu = SubMenu;