"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.defaultRefObject = exports["default"] = exports.PAGE_SUMMARY_TONGJI = exports.PAGE_SUMMARY_TEMPLATE = exports.PAGE_SUMMARY_SUBORDINATE = exports.PAGE_SUMMARY_SHARE = exports.PAGE_SUMMARY_ROLE = exports.PAGE_SUMMARY_MY = exports.PAGE_SUMMARY_DEPART = exports.PAGE_SUMMARY_DASHBOARD = exports.PAGE_SUMMARY_CHART = exports.PAGE_SUMMARY_ALl = void 0;

var _i18n = require("../../i18n");

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

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

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

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" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) 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; }

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: [],
  insertSubordinates: function insertSubordinates() {},
  getMenus: function getMenus() {},
  setSubordinatesLoading: function setSubordinatesLoading() {},
  SUBORDINATES: ""
};
exports.defaultRefObject = defaultRefObject;
var PAGE_SUMMARY_ALl = "summaryall";
exports.PAGE_SUMMARY_ALl = PAGE_SUMMARY_ALl;
var PAGE_SUMMARY_MY = "summarymy";
exports.PAGE_SUMMARY_MY = PAGE_SUMMARY_MY;
var PAGE_SUMMARY_SUBORDINATE = "subordinates";
exports.PAGE_SUMMARY_SUBORDINATE = PAGE_SUMMARY_SUBORDINATE;
var PAGE_SUMMARY_SHARE = "share";
exports.PAGE_SUMMARY_SHARE = PAGE_SUMMARY_SHARE;
var PAGE_SUMMARY_DEPART = "depart";
exports.PAGE_SUMMARY_DEPART = PAGE_SUMMARY_DEPART;
var PAGE_SUMMARY_ROLE = "roles";
exports.PAGE_SUMMARY_ROLE = PAGE_SUMMARY_ROLE;
var PAGE_SUMMARY_CHART = "chart";
exports.PAGE_SUMMARY_CHART = PAGE_SUMMARY_CHART;
var PAGE_SUMMARY_DASHBOARD = 'dashboard';
exports.PAGE_SUMMARY_DASHBOARD = PAGE_SUMMARY_DASHBOARD;
var PAGE_SUMMARY_TONGJI = 'tongji';
exports.PAGE_SUMMARY_TONGJI = PAGE_SUMMARY_TONGJI;
var PAGE_SUMMARY_TEMPLATE = 'template';
exports.PAGE_SUMMARY_TEMPLATE = PAGE_SUMMARY_TEMPLATE;

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

var isShowManage = IsPlanDailyManager || IsBoss || HasSub || IsRoot && Role !== 4 || IsLeader;

var summaryMenus = /*#__PURE__*/function () {
  function summaryMenus(props) {
    var _window$BSGlobal$logi;

    _classCallCheck(this, summaryMenus);

    this.COMPANYALL = _index.COMPANY_ALL_NODE;
    this.USERCONCERN = _index.SUMMARY_USER_CONCERN_NODE;
    this.SHARE = _index.SHARE_NODE;
    this.TONGJI = _index.TONGJI_NODE;
    this.SUBORDINATES = _index.SUBORDINATES_NODE;
    this.menus = [{
      icon: "caidan-my",
      label: _i18n.locale.menu_my_summary,
      key: PAGE_SUMMARY_MY,
      type: _index.MENU_ITEM_NOE,
      href: "#/summary/my",
      isShow: true
    }, {
      icon: "all-zongjie",
      label: _i18n.locale.menu_all_summary,
      key: PAGE_SUMMARY_ALl,
      type: _index.MENU_ITEM_NOE,
      href: "#/summary/all",
      isShow: true
    }, {
      icon: "caidan-xiashu",
      label: _i18n.locale.menu_my_subordinates,
      key: this.SUBORDINATES,
      type: this.SUBORDINATES,
      isLeaf: false,
      children: [],
      href: "#/summary/subordinates",
      isShow: (_window$BSGlobal$logi = window.BSGlobal.loginUserInfo) === null || _window$BSGlobal$logi === void 0 ? void 0 : _window$BSGlobal$logi.HasSub
    }, {
      icon: "caidan-tongji",
      label: _i18n.locale.menu_summary_tongji,
      key: this.TONGJI,
      type: this.TONGJI,
      isLeaf: false,
      children: [],
      href: "#/summary/tongji",
      isShow: props.isShowTongji
    }, {
      icon: "caidan-enjoy",
      label: _i18n.locale.menu_my_share,
      key: this.SHARE,
      type: this.SHARE,
      isLeaf: false,
      children: [],
      href: "#/summary/share",
      isShow: props.isShowShare
    }, {
      icon: "guanzhu",
      label: _i18n.locale.menu_concerned_user,
      key: this.USERCONCERN,
      type: this.USERCONCERN,
      href: "#/summary/all",
      isShow: true
    }, {
      icon: "bumen",
      label: _i18n.locale.menu_department,
      key: this.COMPANYALL,
      type: this.COMPANYALL,
      href: "",
      isShow: props.isShowDept
    }, {
      icon: "",
      label: _i18n.locale.menu_summary,
      key: "other",
      type: _index.GROUP_NAME_NODE,
      href: "",
      isShow: isShowManage
    }, {
      icon: 'yibiao',
      label: _i18n.locale.menu_summary_dashboard,
      key: PAGE_SUMMARY_DASHBOARD,
      type: _index.MENU_ITEM_NOE,
      href: '#/summary/dashboard',
      isShow: props.isShowDashboard
    }, {
      icon: 'template',
      label: _i18n.locale.menu_summary_template,
      key: PAGE_SUMMARY_TEMPLATE,
      type: _index.MENU_ITEM_NOE,
      href: '#/summary/template/page',
      isShow: props.isShowTemplate
    }, {
      icon: "my-setup",
      label: _i18n.locale.menu_summary_role,
      key: PAGE_SUMMARY_ROLE,
      type: _index.MENU_ITEM_NOE,
      href: "#/enterprise/manage?reactRouterName=daily",
      isShow: isShowManage,
      openBlank: true
    }];
  }

  _createClass(summaryMenus, [{
    key: "setSubordinatesLoading",
    value: function setSubordinatesLoading(loading) {
      this.menus[2].children = [];

      if (loading) {
        this.menus[2].children.push({
          icon: "",
          label: "loading",
          key: "loading-subordinates",
          type: _index.LOADING_NODE,
          href: "",
          data: {}
        });
      }
    }
  }, {
    key: "insertSubordinates",
    value: function insertSubordinates(users) {
      if (!users || !users.length) {
        this.menus[2].children = [{
          icon: "",
          label: "empty-subordinates",
          key: "empty-subordinates",
          type: _index.NO_SUBORDINATES_NODE,
          href: "",
          data: {}
        }];
        return;
      }

      var treeNodeUsers = [];

      for (var i = 0; i < users.length; i++) {
        var user = users[i];
        treeNodeUsers.push({
          icon: "",
          label: user.name,
          key: "tongji-".concat(user.userId),
          type: _index.USER_NODE,
          href: "",
          data: user
        });
      }

      this.menus[2].children = treeNodeUsers;
    }
  }, {
    key: "setShareLoading",
    value: function setShareLoading(loading) {
      this.menus[4].children = [];

      if (loading) {
        this.menus[4].children.push({
          icon: "",
          label: "loading",
          key: "loading-subordinates",
          type: _index.LOADING_NODE,
          href: "",
          data: {}
        });
      }
    }
  }, {
    key: "setTongjiLoading",
    value: function setTongjiLoading(loading) {
      this.menus[3].children = [];

      if (loading) {
        this.menus[3].children.push({
          icon: "",
          label: "loading",
          key: "loading-subordinates",
          type: _index.LOADING_NODE,
          href: "",
          data: {}
        });
      }
    }
  }, {
    key: "insertShare",
    value: function insertShare(users) {
      if (!users || !users.length) {
        this.menus[4].children = [{
          icon: "",
          label: "empty-subordinates",
          key: "empty-subordinates",
          type: _index.NO_SUBORDINATES_NODE,
          href: "",
          data: {}
        }];
        return;
      }

      var treeNodeUsers = [];

      for (var i = 0; i < users.length; i++) {
        var user = users[i];

        if (user.jobState === 1) {
          treeNodeUsers.push({
            icon: "",
            label: user.name,
            key: "".concat(user.userId),
            type: _index.USER_NODE,
            href: "",
            data: user
          });
        }
      }

      this.menus[4].children = treeNodeUsers;
    }
  }, {
    key: "insertTongji",
    value: function insertTongji(users) {
      if (!users || !users.length) {
        this.menus[3].children = [{
          icon: "",
          label: "empty-subordinates",
          key: "empty-subordinates",
          type: _index.NO_SUBORDINATES_NODE,
          href: "",
          data: {}
        }];
        return;
      }

      var treeNodeUsers = [];

      for (var i = 0; i < users.length; i++) {
        var user = users[i];
        treeNodeUsers.push({
          icon: "",
          label: user.name,
          key: "tongji-".concat(user.userId),
          type: _index.SAME_LEVEL_USER_NODE,
          href: "",
          data: user
        });
      }

      this.menus[3].children = treeNodeUsers;
    }
  }, {
    key: "setConcernLoading",
    value: function setConcernLoading(loading) {
      this.menus[5].children = [];

      if (loading) {
        this.menus[5].children.push({
          icon: '',
          label: 'loading',
          key: 'loading-concern',
          type: _index.LOADING_NODE,
          href: '',
          data: {}
        });
      }
    }
  }, {
    key: "checkConcernExist",
    value: function checkConcernExist(user) {
      var concerns = this.menus[5].children;

      for (var i = 0; i < concerns.length; i++) {
        var it = concerns[i];

        if (it.key == "concern-".concat(user.userId)) {
          return true;
        }
      }

      return false;
    }
  }, {
    key: "insertConcern",
    value: function insertConcern(users) {
      var treeNodeUsers = []; // 如果没有关注者，显示空

      this.setEmptyConcerners(false);

      if (!users || !users.length) {
        this.setEmptyConcerners(true);
      }

      for (var i = 0; i < users.length; i++) {
        var user = users[i];
        if (this.checkConcernExist(user)) continue;
        treeNodeUsers.push({
          icon: '',
          label: user.name,
          key: "concern-".concat(user.userId),
          type: _index.SUMMARY_FOLLOWER_NODE,
          href: '',
          data: user
        });
      }

      this.menus[5].children = this.menus[5].children.concat(treeNodeUsers);
    }
  }, {
    key: "addConcerner",
    value: function addConcerner(user) {
      if (this.menus[5].children.length && this.menus[5].children[0].key == 'empty-concerners') {
        this.menus[5].children = [];
      }

      this.menus[5].children.push({
        icon: '',
        label: user.name,
        key: "concern-".concat(user.userId),
        type: _index.SUMMARY_FOLLOWER_NODE,
        href: '',
        data: user
      });
    }
  }, {
    key: "setEmptyConcerners",
    value: function setEmptyConcerners(empty) {
      this.menus[5].children = [];

      if (empty) {
        this.menus[5].children.push({
          icon: '',
          label: 'empty-concerners',
          key: 'empty-concerners',
          type: _index.NO_FOLLOWER_NODE,
          href: '',
          data: {}
        });
      }
    }
  }, {
    key: "removeConcerner",
    value: function removeConcerner(user) {
      var newChildren = _toConsumableArray(this.menus[5].children).filter(function (it) {
        return it.key != "concern-".concat(user.userId);
      });

      if (!newChildren.length) {
        this.setEmptyConcerners(true);
      } else {
        this.menus[5].children = newChildren;
      }
    }
  }, {
    key: "getMenus",
    value: function getMenus() {
      var menus = this.formateToTreeNodeData(this.menus.filter(function (it) {
        return it.isShow == true;
      }));
      return menus;
    }
  }, {
    key: "formateToTreeNodeData",
    value: function formateToTreeNodeData(menus) {
      var pid = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
      var level = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 0;
      var treeNodes = [];

      for (var i = 0; i < menus.length; i++) {
        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;
        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 || [], level + 1, menu.key),
          nodeType: nodeType
        });
      }

      return treeNodes;
    }
  }]);

  return summaryMenus;
}();

exports["default"] = summaryMenus;