"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.default = exports.DefaultGlobalHeaderProps = void 0;

var _vue = require("vue");

var _settings = require("../settings");

var _proLayout = require("@antd-vue/pro-layout");

var _antDesignVue = require("ant-design-vue");

var _utils = require("../utils");

var _AppMenu = require("../AppMenu");

var _RightContent = require("../RightContent");

function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; }

function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }

function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }

function _isSlot(s) {
  return typeof s === 'function' || Object.prototype.toString.call(s) === '[object Object]' && !(0, _vue.isVNode)(s);
}

var DefaultGlobalHeaderProps = _objectSpread(_objectSpread(_objectSpread(_objectSpread({}, _settings.DefaultPureSettings), _RightContent.DefaultRightContentProps), _AppMenu.DefaultAppMenuProps), {}, {
  sideWidth: _utils.PropTypes.number.def(210),
  collapsedWidth: _utils.PropTypes.number.def(48),
  prefixCls: _utils.PropTypes.string,

  /* 自定义头部左侧区域渲染 */
  leftContentRender: _utils.PropRenderType,

  /* 折叠按钮渲染 */
  collapsedButtonRender: _utils.PropRenderType,

  /* 自定义头部右侧区域渲染 */
  rightContentRender: _utils.PropRenderType
});

exports.DefaultGlobalHeaderProps = DefaultGlobalHeaderProps;
var GlobalHeader = (0, _vue.defineComponent)({
  name: 'GlobalHeader',
  props: _objectSpread({}, DefaultGlobalHeaderProps),
  inheritAttrs: false,
  emits: ['collapse', 'menuClick'],
  setup: function setup(props, _ref) {
    var slots = _ref.slots,
        attrs = _ref.attrs,
        emit = _ref.emit;
    var headerTheme = (0, _vue.computed)(function () {
      switch (props.layout) {
        case 'mix':
          return 'dark';

        case 'side':
          return 'light';

        case 'top':
        default:
          return props.theme;
      }
    });
    var headerStyle = (0, _vue.computed)(function () {
      var styles = {
        padding: 0,
        background: headerTheme.value == 'light' ? '#ffffff' : undefined,
        height: "".concat(props.headerHeight, "px"),
        lineHeight: "".concat(props.headerHeight, "px"),
        zIndex: props.layout === 'mix' ? 100 : 19,
        width: '100%'
      };

      if (props.layout === 'side' && props.fixedHeader) {
        styles.left = props.collapsed ? "".concat(props.collapsedWidth, "px") : "".concat(props.sideWidth, "px");
        styles.width = props.collapsed ? "calc(100% - ".concat(props.collapsedWidth, "px)") : "calc(100% - ".concat(props.sideWidth, "px)");
      }

      return styles;
    });
    var calcMenus = (0, _vue.computed)(function () {
      return {
        renderMenus: props.layout === 'top' || props.layout === 'mix' && props.splitMenus,
        headerMenus: props.menus
      };
    });
    var proHeaderClassNames = (0, _vue.computed)(function () {
      return ["".concat(props.prefixCls, "-header"), _defineProperty({
        dark: headerTheme.value === 'dark'
      }, "".concat(props.prefixCls, "-header-sider"), false)];
    });
    return function () {
      var _slot;

      var layout = props.layout,
          fixedHeader = props.fixedHeader;
      var defLeftContent = (0, _vue.createVNode)(_proLayout.LeftContent, _objectSpread(_objectSpread({}, props), {}, {
        "onCollapse": function onCollapse(collapsed) {
          emit('collapse', collapsed);
        }
      }), null);
      var leftContent = (0, _utils.getRenderComponent)('leftContentRender', props, slots, defLeftContent, {
        propsArgs: [props],
        slotArg: props
      });
      var defRightContent = (0, _vue.createVNode)(_proLayout.RightContent, _objectSpread(_objectSpread({}, props), {}, {
        "onMenuClick": function onMenuClick(menu) {
          emit('menuClick', menu);
        }
      }), null);
      var rightContent = (0, _utils.getRenderComponent)('rightContentRender', props, slots, defRightContent, {
        propsArgs: [props],
        slotArg: props
      });
      return (0, _vue.createVNode)(_antDesignVue.Layout.Header, {
        "style": (0, _vue.unref)(headerStyle)
      }, _isSlot(_slot = (0, _vue.createVNode)("div", {
        "class": (0, _vue.unref)(proHeaderClassNames)
      }, [(0, _vue.createVNode)("div", {
        "class": 'left'
      }, _isSlot(leftContent) ? leftContent : {
        default: function _default() {
          return [leftContent];
        }
      }), (0, _vue.createVNode)("div", {
        "class": 'main'
      }, [calcMenus.value.renderMenus && (0, _vue.createVNode)(_proLayout.AppMenu, {
        "class": 'menu',
        "menus": calcMenus.value.headerMenus,
        "mode": 'horizontal',
        "theme": (0, _vue.unref)(headerTheme),
        "onClick": function onClick(menu) {
          emit('menuClick', menu);
        }
      }, null)]), (0, _vue.createVNode)("div", {
        "class": 'right'
      }, _isSlot(rightContent) ? rightContent : {
        default: function _default() {
          return [rightContent];
        }
      })])) ? _slot : {
        default: function _default() {
          return [_slot];
        }
      });
    };
  }
});

GlobalHeader.install = function (app) {
  app.use(_proLayout.LeftContent);
  app.use(_proLayout.AppMenu);
  app.use(_proLayout.RightContent);
  app.component(GlobalHeader.displayName, GlobalHeader);
};

var _default2 = GlobalHeader;
exports.default = _default2;