"use strict";

function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }

Object.defineProperty(exports, "__esModule", {
  value: true
});
var _exportNames = {
  CONSTANT: true,
  DefaultRightContentProps: true
};
exports.default = exports.DefaultRightContentProps = exports.CONSTANT = void 0;

var _vue = require("vue");

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

var _iconsVue = require("@ant-design/icons-vue");

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

var _AvatarDropdown = _interopRequireWildcard(require("./AvatarDropdown"));

Object.keys(_AvatarDropdown).forEach(function (key) {
  if (key === "default" || key === "__esModule") return;
  if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
  if (key in exports && exports[key] === _AvatarDropdown[key]) return;
  Object.defineProperty(exports, key, {
    enumerable: true,
    get: function get() {
      return _AvatarDropdown[key];
    }
  });
});

var _Action = _interopRequireWildcard(require("./Action"));

Object.keys(_Action).forEach(function (key) {
  if (key === "default" || key === "__esModule") return;
  if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
  if (key in exports && exports[key] === _Action[key]) return;
  Object.defineProperty(exports, key, {
    enumerable: true,
    get: function get() {
      return _Action[key];
    }
  });
});

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

var _vueRouter = require("vue-router");

var _hooks = require("@antd-vue/hooks");

function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function _getRequireWildcardCache() { return cache; }; return cache; }

function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (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; }

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 _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }

function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }

function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }

function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }

function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }

function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && Symbol.iterator in Object(iter)) return Array.from(iter); }

function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }

function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }

var appEnvName = APP_ENV ? APP_ENV : false;
var defEnv = {
  name: appEnvName,
  tips: '当前应用环境'
};
/**
 * 头部右侧区域默认组件常量id值
 */

var CONSTANT = {
  /**
   * @description 帮助
   */
  help: 'help',

  /**
   * @description 头像
   */
  avatar: 'avatar',

  /**
   * @description 系统设置
   */
  settings: 'settings',

  /**
   * @description 头像下拉菜单默认id
   */
  presonal: {
    /**
     * @description 个人中心
     */
    center: 'personal-center',

    /**
     * @description 个人设置
     */
    settings: 'personal-settings',

    /**
     * @description 退出系统
     */
    exit: 'exit-system'
  }
};
exports.CONSTANT = CONSTANT;
var DefaultRightContentProps = {
  className: [String, Array, Object],
  style: _utils.PropTypes.object,
  help: {
    type: [String, Boolean],
    default: 'https://pro.ant.design/docs/getting-started'
  },
  settings: _utils.PropTypes.bool.def(true),
  env: _utils.PropTypes.object.def(defEnv),
  actions: {
    type: [Array, Boolean]
  },
  actionsEvent: _utils.PropTypes.object,
  userInfo: _utils.PropTypes.object.def({
    name: '吴玉杰',
    avatar: 'https://static-legacy.dingtalk.com/media/lADPACOG8zwMjFDNAn3NAn0_637_637.jpg'
  }),
  avatarMenus: _utils.PropTypes.array.def([{
    id: CONSTANT.presonal.center,
    name: '个人中心',
    icon: 'icon-personal-center'
  }, {
    id: CONSTANT.presonal.settings,
    name: '个人设置',
    icon: 'icon-personal-settings'
  }]),
  custom: {}
};
exports.DefaultRightContentProps = DefaultRightContentProps;

var RightContent = function RightContent(props, _ref) {
  var slots = _ref.slots,
      emit = _ref.emit;
  var finalActions = [];
  var help = props.help,
      className = props.className,
      settings = props.settings,
      env = props.env,
      style = props.style,
      _props$actions = props.actions,
      actions = _props$actions === void 0 ? [] : _props$actions,
      _props$actionsEvent = props.actionsEvent,
      actionsEvent = _props$actionsEvent === void 0 ? {} : _props$actionsEvent,
      userInfo = props.userInfo,
      avatarMenus = props.avatarMenus;
  var customDom = (0, _utils.getRenderComponent)('custom', props, slots);
  var router = (0, _vueRouter.useRouter)();

  var _useToken = (0, _hooks.useToken)(),
      clearToken = _useToken.actions.clearToken;

  var exit = {
    id: CONSTANT.presonal.exit,
    name: '退出系统',
    icon: 'icon-quit',
    divider: (avatarMenus === null || avatarMenus === void 0 ? void 0 : avatarMenus.length) > 0 ? 'before' : false,
    onClick: function onClick(param) {
      clearToken();
      router.push('/login');
    }
  };
  var avatarTitle = (0, _vue.createVNode)(_AvatarDropdown.default, {
    "user": userInfo,
    "menus": avatarMenus === null || avatarMenus === void 0 ? void 0 : avatarMenus.concat(exit),
    "onMenuClick": function onMenuClick(menu) {
      emit('menuClick', menu);
    }
  }, null);
  /**
   * 默认配置
   */

  finalActions.push({
    id: CONSTANT.help,
    className: className,
    style: style,
    sort: 1,
    show: !!help,
    tips: '使用文档',
    title: (0, _vue.createVNode)(_iconsVue.QuestionCircleOutlined, null, null),
    onClick: function onClick() {
      if (typeof help === 'string' && help) {
        window.open(help, '_blank');
      }
    }
  }, {
    id: CONSTANT.avatar,
    className: 'account',
    style: style,
    sort: Number.MAX_VALUE - 1,
    show: !!userInfo,
    title: avatarTitle
  }, {
    id: CONSTANT.settings,
    className: className,
    style: style,
    sort: Number.MAX_VALUE,
    show: settings,
    tips: '系统设置',
    title: (0, _vue.createVNode)(_iconsVue.SettingOutlined, null, null)
  });

  if (Array.isArray(actions)) {
    finalActions = actions.concat.apply(actions, _toConsumableArray(finalActions));
  }

  var defDom = (0, _vue.createVNode)(_antDesignVue.Space, null, {
    default: function _default() {
      return [customDom, env && (0, _vue.createVNode)(_proLayout.AppEnv, Object.assign({}, defEnv, env), null), finalActions
      /* 过滤只显示的数据项 */
      .filter(function (item) {
        return item.show || item.show === undefined;
      })
      /* 升序排列 */
      .sort(function (a, b) {
        return a.sort - b.sort;
      }).map(function (props) {
        var onClick = props.onClick,
            rest = _objectWithoutProperties(props, ["onClick"]);
        /* 优先使用 actionsEvent 中定义的事件 */


        return (0, _vue.createVNode)(_Action.default, _objectSpread(_objectSpread({}, rest), {}, {
          "onClick": actionsEvent[props.id] || onClick
        }), null);
      })];
    }
  });
  return (0, _utils.getRenderComponent)('default', props, slots, defDom, {
    propsArgs: [props, defDom],
    slotArg: props
  });
};

RightContent.displayName = 'RightContent';
RightContent.props = DefaultRightContentProps;
RightContent.emits = ['menuClick'];
RightContent.inheritAttrs = false;

RightContent.install = function (app) {
  app.use(_proLayout.AppEnv);
  app.component(RightContent.displayName, RightContent);
  return app;
};

var _default2 = RightContent;
exports.default = _default2;