"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.default = void 0;
var _react = _interopRequireDefault(require("react"));
var _classnames = _interopRequireDefault(require("classnames"));
var _SiderMenu = require("../SiderMenu/SiderMenu");
var _TopNavHeader = _interopRequireDefault(require("../TopNavHeader"));
var _utils = require("../../utils/utils");
var _jsxRuntime = require("react/jsx-runtime");
const renderLogo = (menuHeaderRender, logoDom) => {
  if (menuHeaderRender === false) {
    return null;
  }
  if (menuHeaderRender) {
    return menuHeaderRender(logoDom, null);
  }
  return logoDom;
};
const GlobalHeader = props => {
  const {
    isMobile,
    logo,
    collapsed,
    onCollapse,
    collapsedButtonRender = _SiderMenu.defaultRenderCollapsedButton,
    rightContentRender,
    menuHeaderRender,
    onMenuHeaderClick,
    className: propClassName,
    style,
    layout,
    children,
    headerTheme = 'dark',
    splitMenus,
    menuData,
    prefixCls
  } = props;
  const baseClassName = `${prefixCls}-global-header`;
  const className = (0, _classnames.default)(propClassName, baseClassName, {
    [`${baseClassName}-layout-${layout}`]: layout && headerTheme === 'dark'
  });
  if (layout === 'mix' && !isMobile && splitMenus) {
    const noChildrenMenuData = (menuData || []).map(item => ({
      ...item,
      children: undefined
    }));
    const clearMenuData = (0, _utils.clearMenuItem)(noChildrenMenuData);
    return /*#__PURE__*/(0, _jsxRuntime.jsx)(_TopNavHeader.default, {
      mode: "horizontal",
      ...props,
      splitMenus: false,
      menuData: clearMenuData,
      theme: headerTheme
    });
  }
  const logoDom = /*#__PURE__*/(0, _jsxRuntime.jsx)("span", {
    className: `${baseClassName}-logo`,
    children: /*#__PURE__*/(0, _jsxRuntime.jsx)("a", {
      children: (0, _SiderMenu.defaultRenderLogo)(logo)
    })
  }, "logo");
  return /*#__PURE__*/(0, _jsxRuntime.jsxs)("div", {
    className: className,
    style: {
      ...style
    },
    children: [isMobile && renderLogo(menuHeaderRender, logoDom), isMobile && collapsedButtonRender && /*#__PURE__*/(0, _jsxRuntime.jsx)("span", {
      className: `${baseClassName}-collapsed-button`,
      onClick: () => {
        if (onCollapse) {
          onCollapse(!collapsed);
        }
      },
      children: collapsedButtonRender(collapsed)
    }), layout === 'mix' && !isMobile && /*#__PURE__*/(0, _jsxRuntime.jsx)(_jsxRuntime.Fragment, {
      children: /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
        className: `${baseClassName}-logo`,
        onClick: onMenuHeaderClick,
        children: (0, _SiderMenu.defaultRenderLogoAndTitle)({
          ...props,
          collapsed: false
        }, 'headerTitleRender')
      })
    }), /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
      style: {
        flex: 1
      },
      children: children
    }), rightContentRender && rightContentRender(props)]
  });
};
var _default = GlobalHeader;
exports.default = _default;