"use strict";

require("core-js/modules/es.array.iterator.js");
require("core-js/modules/web.dom-collections.iterator.js");
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.default = void 0;
var _react = _interopRequireWildcard(require("react"));
var _classnames = _interopRequireDefault(require("classnames"));
var _omit = _interopRequireDefault(require("omit.js"));
var _routeUtils = require("@umijs/route-utils");
var _drawer = _interopRequireDefault(require("../../../drawer"));
var _SiderMenu = _interopRequireDefault(require("./SiderMenu"));
var _Counter = _interopRequireDefault(require("./Counter"));
var _jsxRuntime = require("react/jsx-runtime");
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (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; }
const SiderMenuWrapper = props => {
  const {
    isMobile,
    menuData,
    siderWidth,
    collapsed,
    onCollapse,
    style,
    className,
    hide,
    getContainer,
    prefixCls,
    matchMenuKeys
  } = props;
  const {
    setFlatMenuKeys
  } = _Counter.default.useContainer();
  (0, _react.useEffect)(() => {
    if (!menuData || menuData.length < 1) {
      return () => null;
    }
    // 当 menu data 改变的时候重新计算这两个参数
    const newFlatMenus = (0, _routeUtils.getFlatMenus)(menuData);
    const animationFrameId = requestAnimationFrame(() => {
      setFlatMenuKeys(Object.keys(newFlatMenus));
    });
    return () => window.cancelAnimationFrame && window.cancelAnimationFrame(animationFrameId);
  }, [matchMenuKeys.join('-')]);
  (0, _react.useEffect)(() => {
    if (isMobile === true) {
      if (onCollapse) {
        onCollapse(true);
      }
    }
  }, [isMobile]);
  const omitProps = (0, _omit.default)(props, ['className', 'style']);
  if (hide) {
    return null;
  }
  return isMobile ? /*#__PURE__*/(0, _jsxRuntime.jsx)(_drawer.default, {
    visible: !collapsed,
    placement: "left",
    className: (0, _classnames.default)(`${prefixCls}-drawer-sider`, className),
    onClose: () => onCollapse && onCollapse(true),
    style: {
      padding: 0,
      height: '100vh',
      ...style
    },
    getContainer: getContainer,
    width: siderWidth,
    bodyStyle: {
      height: '100vh',
      padding: 0,
      display: 'flex',
      flexDirection: 'row'
    },
    children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_SiderMenu.default, {
      ...omitProps,
      className: (0, _classnames.default)(`${prefixCls}-sider`, className),
      collapsed: isMobile ? false : collapsed,
      splitMenus: false
    })
  }) : /*#__PURE__*/(0, _jsxRuntime.jsx)(_SiderMenu.default, {
    className: (0, _classnames.default)(`${prefixCls}-sider`, className),
    ...omitProps,
    style: style
  });
};
SiderMenuWrapper.defaultProps = {
  onCollapse: () => undefined
};
var _default = SiderMenuWrapper;
exports.default = _default;