"use strict";

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

var _vue = require("vue");

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

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

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

var _GlobalHeader = require("../GlobalHeader");

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; }

var DefaultProLayoutProps = _objectSpread(_objectSpread({}, _GlobalHeader.DefaultGlobalHeaderProps), {}, {
  prefixCls: _utils.PropTypes.string.def('ant-pro-layout'),
  menus: _utils.PropTypes.array.def([]),
  loading: _utils.PropTypes.bool.def(false),

  /* 自定义头部渲染 */
  headerRender: _utils.PropRenderType,

  /* 自定义页脚的 render 方法 (props: any) => VNode */
  footerRender: _utils.PropRenderType,
  // collapsedButtonRender: {
  //   type: PropRenderType.type,
  //   default: (collapsed: boolean) => {
  //     return collapsed ? <MenuUnfoldOutlined/> : <MenuFoldOutlined/>;
  //   }
  // },
  layout: _utils.PropTypes.string.def('side'),
  theme: _utils.PropTypes.string.def('dark'),
  fixedHeader: _utils.PropTypes.bool.def(false),
  fixedSidebar: _utils.PropTypes.bool.def(false),
  headerHeight: _utils.PropTypes.number.def(48),
  disableContentMargin: _utils.PropTypes.bool.def(false),
  collapse: _utils.PropTypes.func.def(function () {})
});

exports.DefaultProLayoutProps = DefaultProLayoutProps;
var ProLayout = (0, _vue.defineComponent)({
  name: 'ProLayout',
  props: _objectSpread({}, DefaultProLayoutProps),
  emits: ['collapse', 'menuClick', 'logout', 'onOpenKeys', 'OnSelectedKeys'],
  setup: function setup(props, _ref) {
    var attrs = _ref.attrs,
        slots = _ref.slots,
        emit = _ref.emit;
    var state = (0, _vue.reactive)(props);

    var handleCollapsed = function handleCollapsed(collapsed) {
      emit('collapse', collapsed);
    };

    var handleMenuClick = function handleMenuClick(menu) {
      emit('menuClick', menu);
      /* 用户退出系统事件 */

      if (_RightContent.CONSTANT.presonal.exit === menu.id) {
        emit('logout', menu);
      }
    };
    /* 侧边菜单渲染 */


    var sideMenuDom = (0, _vue.computed)(function () {
      return (0, _vue.createVNode)(_proLayout.SideMenu, _objectSpread(_objectSpread({}, props), {}, {
        "onCollapse": handleCollapsed,
        "onMenuClick": handleMenuClick
      }), null);
    });
    var className = (0, _vue.computed)(function () {
      var _ref2;

      return _ref2 = {}, _defineProperty(_ref2, props.prefixCls, true), _defineProperty(_ref2, "".concat(props.prefixCls, "-fixed-header"), props.fixedHeader), _defineProperty(_ref2, "".concat(props.prefixCls, "-fixed-sidebar"), props.fixedSidebar), _defineProperty(_ref2, "".concat(props.prefixCls, "-").concat(props.layout), props.layout), _ref2;
    });
    var styles = (0, _vue.computed)(function () {
      var s = {};

      if (props.fixedHeader || props.layout === 'mix') {
        s.paddingTop = "".concat(props.headerHeight, "px");
      }

      if (props['headerRender'] || slots['headerRender']) {
        s.paddingTop = undefined;
      }

      return s;
    });
    var builtInContentStyle = (0, _vue.computed)(function () {
      var styles = {
        flex: '1 0 auto',
        margin: props.disableContentMargin ? 0 : "".concat(16, "px"),
        width: props.collapsed ? "calc(100vw - ".concat(props.collapsedWidth + (props.disableContentMargin ? 0 : 16 * 2) + 8, "px)") : "calc(100vw - ".concat(props.sideWidth + (props.disableContentMargin ? 0 : 16 * 2) + 8, "px)")
      };

      if (props.layout === 'top') {
        styles.width = "calc(100vw - ".concat(8, "px)");
      }

      return styles;
    });
    /* 计算内容区域样式 */

    var contentClassName = (0, _vue.computed)(function () {
      return ["".concat(props.prefixCls, "-content")];
    });
    return function () {
      var _slots$default;

      /* 注意：渲染函数内的所有逻辑代码每次都会执行，函数式组件一样（优化代码 => 将非必需重复执行的代码提升到渲染函数外部） */
      var contentStyle = props.contentStyle,
          loading = props.loading;
      /* 头部左侧区域渲染 */

      var leftContentDom = (0, _utils.getRenderComponent)('leftContentRender', props, slots, undefined, {
        propsArgs: [props],
        slotArg: props
      });
      /* 头部右侧区域渲染 */

      var rightContentDom = (0, _utils.getRenderComponent)('rightContentRender', props, slots, (0, _vue.createVNode)(_proLayout.RightContent, _objectSpread(_objectSpread({}, props), {}, {
        "onMenuClick": handleMenuClick
      }), null), {
        propsArgs: [props],
        slotArg: props
      });
      var defHeader = (0, _vue.computed)(function () {
        return (0, _vue.createVNode)(_proLayout.GlobalHeader, _objectSpread(_objectSpread({}, props), {}, {
          "leftContentRender": leftContentDom,
          "rightContentRender": rightContentDom,
          "onCollapse": handleCollapsed,
          "onMenuClick": handleMenuClick
        }), null);
      });
      /* 布局头部渲染 */

      var headerDom = (0, _utils.getRenderComponent)('headerRender', props, slots, defHeader, {
        propsArgs: [props, defHeader],
        slotArg: props
      });
      var defFooter = (0, _vue.createVNode)(_proLayout.GlobalFooter, null, null);
      /* 布局底部渲染 */

      var footerDom = (0, _utils.getRenderComponent)('footerRender', props, slots, defFooter, {
        propsArgs: [props, defFooter],
        slotArg: props
      });
      return (0, _vue.createVNode)(_vue.Fragment, null, [(0, _vue.createVNode)("div", {
        "class": (0, _vue.unref)(className)
      }, [(0, _vue.createVNode)(_antDesignVue.Layout, {
        "id": 'layout-pos'
      }, {
        default: function _default() {
          return [(0, _vue.unref)(sideMenuDom), (0, _vue.createVNode)("div", {
            "class": 'ant-layout',
            "style": _objectSpread({
              position: 'relative'
            }, (0, _vue.unref)(styles))
          }, [(0, _vue.unref)(headerDom), (0, _vue.createVNode)(_antDesignVue.Layout.Content, {
            "class": (0, _vue.unref)(contentClassName),
            "style": _objectSpread(_objectSpread({}, contentStyle), (0, _vue.unref)(builtInContentStyle))
          }, {
            default: function _default() {
              return [loading ? (0, _vue.createVNode)(_proLayout.PageLoading, null, null) : (_slots$default = slots.default) === null || _slots$default === void 0 ? void 0 : _slots$default.call(slots)];
            }
          }), (0, _vue.unref)(footerDom)])];
        }
      })])]);
    };
  }
});

ProLayout.install = function (app) {
  app.use(_proLayout.GlobalHeader);
  app.use(_proLayout.PageLoading);
  app.use(_proLayout.GlobalFooter);
  app.component('ProLayout', ProLayout);
};

var _default2 = ProLayout;
exports.default = _default2;