"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.default = void 0;
require("core-js/modules/es.array.iterator.js");
require("core-js/modules/web.dom-collections.iterator.js");
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
var _react = _interopRequireWildcard(require("react"));
var _classnames = _interopRequireDefault(require("classnames"));
var _layout = _interopRequireDefault(require("../layout"));
var _GlobalHeader = _interopRequireDefault(require("./components/GlobalHeader"));
var _TopNavHeader = _interopRequireDefault(require("./components/TopNavHeader"));
var _utils = require("./utils/utils");
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 {
  Header
} = _layout.default;
class HeaderView extends _react.Component {
  constructor(...args) {
    super(...args);
    (0, _defineProperty2.default)(this, "renderContent", () => {
      const {
        isMobile,
        onCollapse,
        navTheme,
        layout,
        headerRender,
        headerContentRender
      } = this.props;
      const isTop = layout === 'top';
      const clearMenuData = (0, _utils.clearMenuItem)(this.props.menuData || []);
      let defaultDom = /*#__PURE__*/(0, _jsxRuntime.jsx)(_GlobalHeader.default, {
        onCollapse: onCollapse,
        ...this.props,
        menuData: clearMenuData,
        children: headerContentRender && headerContentRender(this.props)
      });
      if (isTop && !isMobile) {
        defaultDom = /*#__PURE__*/(0, _jsxRuntime.jsx)(_TopNavHeader.default, {
          theme: navTheme,
          mode: "horizontal",
          onCollapse: onCollapse,
          ...this.props,
          menuData: clearMenuData
        });
      }
      if (headerRender && typeof headerRender === 'function') {
        return headerRender(this.props, defaultDom);
      }
      return defaultDom;
    });
  }
  render() {
    const {
      fixedHeader,
      layout,
      className: propsClassName,
      style,
      navTheme,
      collapsed,
      siderWidth,
      hasSiderMenu,
      isMobile,
      prefixCls,
      headerHeight
    } = this.props;
    const needFixedHeader = fixedHeader || layout === 'mix';
    const isTop = layout === 'top';
    const needSettingWidth = needFixedHeader && hasSiderMenu && !isTop && !isMobile;
    const className = (0, _classnames.default)(propsClassName, {
      [`${prefixCls}-fixed-header`]: needFixedHeader,
      [`${prefixCls}-fixed-header-action`]: !collapsed,
      [`${prefixCls}-top-menu`]: isTop,
      [`${prefixCls}-header-${navTheme}`]: navTheme && layout !== 'mix'
    });

    /** 计算侧边栏的宽度，不然导致左边的样式会出问题 */
    const width = layout !== 'mix' && needSettingWidth ? `calc(100% - ${collapsed ? 48 : siderWidth}px)` : '100%';
    const right = needFixedHeader ? 0 : undefined;
    return /*#__PURE__*/(0, _jsxRuntime.jsxs)(_jsxRuntime.Fragment, {
      children: [needFixedHeader && /*#__PURE__*/(0, _jsxRuntime.jsx)(Header, {
        style: {
          height: headerHeight,
          lineHeight: `${headerHeight}px`,
          background: 'transparent'
        }
      }), /*#__PURE__*/(0, _jsxRuntime.jsx)(Header, {
        style: {
          padding: 0,
          height: headerHeight,
          lineHeight: `${headerHeight}px`,
          width,
          zIndex: layout === 'mix' ? 100 : 19,
          right,
          ...style
        },
        className: className,
        children: this.renderContent()
      })]
    });
  }
}
var _default = HeaderView;
exports.default = _default;