"use strict";

exports.__esModule = true;
exports.default = void 0;
var _babelRuntimeJsxStyleTransform = require("babel-runtime-jsx-style-transform");
var _tslib = require("tslib");
var _react = _interopRequireWildcard(require("react"));
var _classnames3 = _interopRequireDefault(require("classnames"));
var _list = _interopRequireDefault(require("../list"));
var _view = _interopRequireDefault(require("../view"));
var _menuContext = _interopRequireDefault(require("./menu-context"));
var _constant = require("./constant");
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
function _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
var SubMenu = function (props, ref) {
  var _classnames, _classnames2;
  var context = (0, _react.useContext)(_menuContext.default);
  var className = props.className,
    containerClassName = props.containerClassName,
    containerStyle = props.containerStyle,
    children = props.children,
    label = props.label,
    loading = props.loading,
    keyPath = props.keyPath,
    _props$depth = props.depth,
    depth = _props$depth === void 0 ? 1 : _props$depth,
    others = (0, _tslib.__rest)(props, ["className", "containerClassName", "containerStyle", "children", "label", "loading", "keyPath", "depth"]);
  var prefix = context.prefix,
    _context$inlineIndent = context.inlineIndent,
    inlineIndent = _context$inlineIndent === void 0 ? _constant.DEFAULT_INLINE_INDENT : _context$inlineIndent,
    openKeys = context.openKeys,
    onOpen = context.onOpen;
  var open = keyPath && openKeys.includes(keyPath);
  return /*#__PURE__*/(0, _react.createElement)(_view.default, _extends({}, others, {
    ref: ref,
    className: containerClassName,
    style: (0, _babelRuntimeJsxStyleTransform.rpx2vw4style)(containerStyle)
  }), /*#__PURE__*/(0, _react.createElement)(_list.default.Item, {
    className: (0, _classnames3.default)(prefix + "menu-sub-menu", className, (_classnames = {}, _classnames[prefix + "menu-sub-menu--loading"] = loading, _classnames)),
    title: label,
    arrow: loading ? 'loading' : open ? 'up' : 'down',
    onClick: function handleOpen() {
      if (!loading) {
        onOpen({
          key: keyPath,
          open: !open
        });
      }
    }
  }), /*#__PURE__*/(0, _react.createElement)(_view.default, {
    className: (0, _classnames3.default)(prefix + "menu-sub-menu-list", (_classnames2 = {}, _classnames2[prefix + "menu-sub-menu-list--open"] = open, _classnames2)),
    style: (0, _babelRuntimeJsxStyleTransform.rpx2vw4style)({
      textIndent: inlineIndent * 2 * depth + "rpx"
    })
  }, children));
};
var _default = /*#__PURE__*/(0, _react.forwardRef)(SubMenu);
exports.default = _default;