"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 _react = _interopRequireWildcard(require("react"));
var _classnames = _interopRequireDefault(require("classnames"));
var _rcResizeObserver = _interopRequireDefault(require("rc-resize-observer"));
var _SiderMenu = require("../SiderMenu/SiderMenu");
var _BaseMenu = _interopRequireDefault(require("../SiderMenu/BaseMenu"));
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; }
/**
 * 抽离出来是为了防止 rightSize 经常改变导致菜单 render
 *
 * @param param0
 */
const RightContent = ({
  rightContentRender,
  ...props
}) => {
  const [rightSize, setRightSize] = (0, _react.useState)('auto');
  return /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
    style: {
      minWidth: rightSize
    },
    children: /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
      style: {
        paddingRight: 8
      },
      children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_rcResizeObserver.default, {
        onResize: ({
          width
        }) => {
          setRightSize(width);
        },
        children: rightContentRender && /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
          children: rightContentRender({
            ...props
          })
        })
      })
    })
  });
};
const TopNavHeader = props => {
  const ref = (0, _react.useRef)(null);
  const {
    theme,
    onMenuHeaderClick,
    contentWidth,
    rightContentRender,
    className: propsClassName,
    style,
    layout
  } = props;
  const prefixCls = `${props.prefixCls || 'ant-pro'}-top-nav-header`;
  const headerDom = (0, _SiderMenu.defaultRenderLogoAndTitle)({
    ...props,
    collapsed: false
  }, layout === 'mix' ? 'headerTitleRender' : undefined);
  const className = (0, _classnames.default)(prefixCls, propsClassName, {
    light: theme === 'light'
  });
  return /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
    className: className,
    style: style,
    children: /*#__PURE__*/(0, _jsxRuntime.jsxs)("div", {
      ref: ref,
      className: `${prefixCls}-main ${contentWidth === 'Fixed' ? 'wide' : ''}`,
      children: [headerDom && /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
        className: `${prefixCls}-main-left`,
        onClick: onMenuHeaderClick,
        children: /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
          className: `${prefixCls}-logo`,
          id: "logo",
          children: headerDom
        }, "logo")
      }), /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
        style: {
          flex: 1
        },
        className: `${prefixCls}-menu`,
        children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_BaseMenu.default, {
          ...props,
          ...props.menuProps
        })
      }), rightContentRender && /*#__PURE__*/(0, _jsxRuntime.jsx)(RightContent, {
        rightContentRender: rightContentRender,
        ...props
      })]
    })
  });
};
var _default = TopNavHeader;
exports.default = _default;