"use strict";

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

var _bsGlobal = require("../../../../utils/bs-global");

var _getLocale = require("../../../../utils/getLocale");

var _treeNode = require("../../components/menu-tree/tree-node");

var _index = require("../../components/menu-tree/tree-node/index");

function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }

function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }

function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }

var defaultRefObject = {
  menus: [],
  getMenus: function getMenus() {}
};
exports.defaultRefObject = defaultRefObject;

var _getUserInfo = (0, _bsGlobal.getUserInfo)(),
    IsLeader = _getUserInfo.IsLeader,
    IsBoss = _getUserInfo.IsBoss,
    IsRoot = _getUserInfo.IsRoot,
    Role = _getUserInfo.Role,
    IsHrbp = _getUserInfo.IsHrbp;

var mamagementAuthority = IsBoss || IsRoot && Role !== 4 || IsLeader || IsHrbp;

var InterviewMenus = /*#__PURE__*/function () {
  function InterviewMenus() {
    _classCallCheck(this, InterviewMenus);

    this.menus = [{
      icon: 'my-interview',
      label: (0, _getLocale.getLocale)('Ooo_Mo_My1on1'),
      key: 'myInterview',
      href: '#/interview?reactRouterName=myInterview'
    }, {
      icon: 'todo',
      label: (0, _getLocale.getLocale)('Ooo_Tas_ActionPlans'),
      key: 'todos',
      href: '#/interview?reactRouterName=todos'
    }, {
      icon: 'template',
      label: (0, _getLocale.getLocale)('Ooo_Mo_Templates'),
      key: 'template',
      href: '#/interview?reactRouterName=template'
    }, {
      icon: '',
      label: (0, _getLocale.getLocale)('Ooo_Mo_Administ'),
      key: 'manage-interview-group',
      type: _treeNode.GROUP_NAME_NODE,
      href: '',
      isShow: mamagementAuthority
    }, {
      icon: 'setting',
      label: (0, _getLocale.getLocale)('Rep_NewS_onManage'),
      key: 'management',
      href: '#/interview?reactRouterName=management',
      isShow: mamagementAuthority
    }, {
      icon: 'yibiao',
      label: (0, _getLocale.getLocale)('Ooo_Ddb_Dashboard'),
      key: 'dashboard',
      href: '#/interview?reactRouterName=dashboard',
      isShow: mamagementAuthority
    }];
    this.newMenus = {
      myInterview: [{
        icon: 'my-interview',
        label: (0, _getLocale.getLocale)('Ooo_Mo_My1on1'),
        key: 'myInterview',
        href: '#/interview/my?reactRouterName=myInterview'
      }, {
        icon: 'todo',
        label: (0, _getLocale.getLocale)('Ooo_Tas_ActionPlans'),
        key: 'todos',
        href: '#/interview/my?reactRouterName=todos'
      }, {
        icon: 'template',
        label: (0, _getLocale.getLocale)('Ooo_Mo_Templates'),
        key: 'template',
        href: '#/interview/my?reactRouterName=template'
      }],
      interviewManagement: [{
        icon: 'setting',
        label: (0, _getLocale.getLocale)('Rep_NewS_onManage'),
        key: 'management',
        href: '#/interview/management?reactRouterName=management',
        isShow: mamagementAuthority
      }],
      interviewDashboard: [{
        icon: 'yibiao',
        label: (0, _getLocale.getLocale)('Ooo_Ddb_Dashboard'),
        key: 'dashboard',
        href: '#/interview/dashboard?reactRouterName=dashboard',
        isShow: mamagementAuthority
      }]
    };
  }

  _createClass(InterviewMenus, [{
    key: "getMenus",
    value: function getMenus() {
      var isUseNewMenu = window.BSGlobal.isUseNewMenu;
      var menus = this.menus;

      if (isUseNewMenu) {
        var hash = window.location.hash.split('?')[0] || '';

        if (hash) {
          if (hash.includes('interview/my')) {
            menus = this.newMenus.myInterview;
          } else if (hash.includes('interview/management')) {
            menus = this.newMenus.interviewManagement;
          } else if (hash.includes('interview/dashboard')) {
            menus = this.newMenus.interviewDashboard;
          }
        }
      }

      return this.formateToTreeNodeData(menus);
    }
  }, {
    key: "formateToTreeNodeData",
    value: function formateToTreeNodeData(menus) {
      var treeNodes = [];

      for (var i = 0; i < menus.length; i = i + 1) {
        var menu = menus[i];
        var hasChildren = !!(menu.children && menu.children.length);
        var isLeaf = menu.isLeaf !== undefined ? menu.isLeaf : !hasChildren;
        var nodeType = menu.type;
        if (!nodeType) nodeType = !isLeaf ? _index.PARENT_MENU_NODE : _index.SUB_MENU_ITEM_NOE;

        if (menu.isShow !== false) {
          treeNodes.push({
            key: "".concat(menu.key),
            title: (0, _getLocale.getLocale)(menu.label) ? (0, _getLocale.getLocale)(menu.label) : menu.label,
            data: menu.data || menu,
            isLeaf: isLeaf,
            children: this.formateToTreeNodeData(menu.children || []),
            nodeType: nodeType
          });
        }
      }

      return treeNodes;
    }
  }]);

  return InterviewMenus;
}();

var _default = InterviewMenus;
exports["default"] = _default;