"use strict";

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

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.hasSuperior = exports.OAuth = exports.MyRole = exports.KRAuth = exports.EAuth = exports.DynamicManagerAuth = exports.ChildAuth = exports.BaseAuth = void 0;

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

function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); Object.defineProperty(subClass, "prototype", { writable: false }); if (superClass) _setPrototypeOf(subClass, superClass); }

function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }

function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }

function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } else if (call !== void 0) { throw new TypeError("Derived constructors may only return object or undefined"); } return _assertThisInitialized(self); }

function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }

function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }

function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }

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 BaseAuth = /*#__PURE__*/function () {
  function BaseAuth() {
    _classCallCheck(this, BaseAuth);

    this.loginUserInfor = (0, _bsGlobal.getBSGlobal)('loginUserInfo') || {};
  } // 老板


  _createClass(BaseAuth, [{
    key: "isBoss",
    value: function isBoss() {
      // console.log('isboss', this.loginUserInfor.IsBoss)
      return this.loginUserInfor.IsBoss;
    } // 超管

  }, {
    key: "isSuperManager",
    value: function isSuperManager() {
      return this.loginUserInfor.Role === 2;
    } // 超管、助理、目标管理员

  }, {
    key: "isManager",
    value: function isManager() {
      // console.log('ismanager', this.loginUserInfor.IsOkrManager)
      return this.loginUserInfor.IsOkrManager;
    } // 助理或者说动态管理员

  }, {
    key: "isAssistant",
    value: function isAssistant() {
      return this.loginUserInfor.Role === 1;
    } // 项目管理员

  }, {
    key: "isWorkManager",
    value: function isWorkManager() {
      return this.loginUserInfor.IsWorkManager;
    }
  }, {
    key: "isDepartmentLeader",
    value: function isDepartmentLeader() {
      return !this.loginUserInfor.IsBoss && this.loginUserInfor.IsLeader;
    }
  }, {
    key: "isHrbp",
    value: function isHrbp() {
      return !this.loginUserInfor.IsBoss && this.loginUserInfor.IsHrbp;
    }
  }, {
    key: "isPlanDailyManager",
    value: function isPlanDailyManager() {
      return this.loginUserInfor.IsPlanDailyManager;
    }
  }, {
    key: "isSurveyManager",
    value: function isSurveyManager() {
      var _this$loginUserInfor;

      return (_this$loginUserInfor = this.loginUserInfor) === null || _this$loginUserInfor === void 0 ? void 0 : _this$loginUserInfor.IsSuveryManager;
    }
  }]);

  return BaseAuth;
}();

exports.BaseAuth = BaseAuth;

var OAuth = /*#__PURE__*/function (_BaseAuth) {
  _inherits(OAuth, _BaseAuth);

  var _super = _createSuper(OAuth);

  function OAuth(props) {
    var _this;

    _classCallCheck(this, OAuth);

    _this = _super.call(this, props);
    var principalUser = props.principalUser,
        createUserId = props.createUserId;
    _this.userId = _this.loginUserInfor.Id;
    _this.principalUser = principalUser;
    _this.createUserId = createUserId;
    return _this;
  } // 創建人、發起人


  _createClass(OAuth, [{
    key: "isCreater",
    value: function isCreater() {
      // console.log('o iscreater', this.userId, this.createUserId)
      return this.userId == this.createUserId;
    } // 負責人

  }, {
    key: "isPrincipalUser",
    value: function isPrincipalUser() {
      var _this$principalUser;

      // console.log('o isp', this.userId, this.principalUser.userId)
      return this.userId == ((_this$principalUser = this.principalUser) === null || _this$principalUser === void 0 ? void 0 : _this$principalUser.userId);
    } // 有操作OKR的權限

  }, {
    key: "hasAuth",
    value: function hasAuth() {
      return this.isBoss() || this.isManager() || this.isCreater() || this.isPrincipalUser();
    }
  }]);

  return OAuth;
}(BaseAuth);

exports.OAuth = OAuth;

var KRAuth = /*#__PURE__*/function (_BaseAuth2) {
  _inherits(KRAuth, _BaseAuth2);

  var _super2 = _createSuper(KRAuth);

  function KRAuth(props) {
    var _this2;

    _classCallCheck(this, KRAuth);

    _this2 = _super2.call(this, props);
    var user = props.user,
        createUserId = props.createUserId;
    _this2.loginUserInfor = (0, _bsGlobal.getBSGlobal)('loginUserInfo') || {};
    _this2.userId = _this2.loginUserInfor.Id;
    _this2.user = user;
    _this2.createUserId = createUserId;
    return _this2;
  } // 創建人、發起人


  _createClass(KRAuth, [{
    key: "isCreater",
    value: function isCreater() {
      // console.log('kr iscreater', this.userId, this.createUserId)
      return this.userId == this.createUserId;
    } // 負責人

  }, {
    key: "isPrincipalUser",
    value: function isPrincipalUser() {
      var _this$user;

      // console.log('kr isp', this.userId, this.user.userId)
      return this.userId == ((_this$user = this.user) === null || _this$user === void 0 ? void 0 : _this$user.userId);
    } // 有操作KR的權限

  }, {
    key: "hasAuth",
    value: function hasAuth() {
      return this.isBoss() || this.isManager() || this.isCreater() || this.isPrincipalUser();
    }
  }]);

  return KRAuth;
}(BaseAuth);

exports.KRAuth = KRAuth;

var EAuth = /*#__PURE__*/function (_BaseAuth3) {
  _inherits(EAuth, _BaseAuth3);

  var _super3 = _createSuper(EAuth);

  function EAuth(props) {
    var _this3;

    _classCallCheck(this, EAuth);

    _this3 = _super3.call(this, props);
    var principalUser = props.principalUser,
        user = props.user;
    _this3.userId = _this3.loginUserInfor.Id;
    _this3.principalUser = principalUser;
    _this3.user = user;
    return _this3;
  } // 創建人、發起人


  _createClass(EAuth, [{
    key: "isCreater",
    value: function isCreater() {
      var _this$user2;

      // console.log('e iscreater', this.userId, this.user.userId)
      return this.userId == ((_this$user2 = this.user) === null || _this$user2 === void 0 ? void 0 : _this$user2.userId);
    } // 負責人

  }, {
    key: "isPrincipalUser",
    value: function isPrincipalUser() {
      var _this$principalUser2;

      // console.log('e isp', this.userId, this.principalUser.userId)
      return this.userId == ((_this$principalUser2 = this.principalUser) === null || _this$principalUser2 === void 0 ? void 0 : _this$principalUser2.userId);
    } // 有操作KR的權限

  }, {
    key: "hasAuth",
    value: function hasAuth() {
      return this.isBoss() || this.isManager() || this.isCreater() || this.isPrincipalUser();
    }
  }]);

  return EAuth;
}(BaseAuth); // 是否有上级


exports.EAuth = EAuth;

var hasSuperior = function hasSuperior() {
  var _getBSGlobal;

  return !!((_getBSGlobal = (0, _bsGlobal.getBSGlobal)('loginUserInfo')) !== null && _getBSGlobal !== void 0 && _getBSGlobal.ManagerId);
}; // 动态和项目文件管理权限


exports.hasSuperior = hasSuperior;

var DynamicManagerAuth = /*#__PURE__*/function (_BaseAuth4) {
  _inherits(DynamicManagerAuth, _BaseAuth4);

  var _super4 = _createSuper(DynamicManagerAuth);

  function DynamicManagerAuth(props) {
    var _getBSGlobal2, _getBSGlobal3;

    var _this4;

    _classCallCheck(this, DynamicManagerAuth);

    _this4 = _super4.call(this, props);
    _this4.isDynamicManager = (_getBSGlobal2 = (0, _bsGlobal.getBSGlobal)('loginUserInfo')) === null || _getBSGlobal2 === void 0 ? void 0 : _getBSGlobal2.IsFeedAndFileManager;
    _this4.isLeader = (_getBSGlobal3 = (0, _bsGlobal.getBSGlobal)('loginUserInfo')) === null || _getBSGlobal3 === void 0 ? void 0 : _getBSGlobal3.IsLeader;
    return _this4;
  }

  _createClass(DynamicManagerAuth, [{
    key: "hasAuth",
    value: function hasAuth() {
      return this.isBoss() || this.isManager() || this.isDynamicManager;
    } // 部门负责人、超管、助理、老板及动态管理员：有进入详情页的入口

  }, {
    key: "hasPraiseAuth",
    value: function hasPraiseAuth() {
      return this.isBoss() || this.isManager() || this.isDynamicManager || this.isLeader;
    }
  }, {
    key: "isOnlyLeader",
    value: function isOnlyLeader() {
      return !this.isBoss() && !this.isManager() && !this.isDynamicManager && this.isLeader;
    }
  }]);

  return DynamicManagerAuth;
}(BaseAuth);

exports.DynamicManagerAuth = DynamicManagerAuth;

var ChildAuth = /*#__PURE__*/function (_BaseAuth5) {
  _inherits(ChildAuth, _BaseAuth5);

  var _super5 = _createSuper(ChildAuth);

  function ChildAuth(props) {
    var _this5;

    _classCallCheck(this, ChildAuth);

    _this5 = _super5.call(this, props);
    var principalUser = props.principalUser;
    _this5.userId = _this5.loginUserInfor.Id;
    _this5.principalUser = principalUser;
    return _this5;
  }

  _createClass(ChildAuth, [{
    key: "isPrincipalUser",
    value: function isPrincipalUser() {
      var _this$principalUser3;

      return this.userId == ((_this$principalUser3 = this.principalUser) === null || _this$principalUser3 === void 0 ? void 0 : _this$principalUser3.userId);
    } // 超管、助理、目标管理员以及目标负责人可以修改此目标下对齐子目标的权重；

  }, {
    key: "hasAuth",
    value: function hasAuth() {
      return this.isManager() || this.isPrincipalUser();
    }
  }]);

  return ChildAuth;
}(BaseAuth); // 上面的权限我没动，但我这个应该是全的


exports.ChildAuth = ChildAuth;

var MyRole = /*#__PURE__*/function () {
  function MyRole() {
    var _this$loginUserInfo, _this$loginUserInfo2, _this$loginUserInfo3, _this$loginUserInfo4, _this$loginUserInfo5, _this$loginUserInfo6, _this$loginUserInfo7;

    _classCallCheck(this, MyRole);

    this.loginUserInfo = (0, _bsGlobal.getBSGlobal)('loginUserInfo') || {};
    this.role_label = {
      1: 'assistant',
      // 助理或者说动态管理员
      2: 'supreManager',
      // 超管
      3: 'manage',
      // 普通管理员，比如okr管理员，项目管理员，这时候就要去判断别的字段
      4: 'adminManager' // 后台管理员

    };
    this.isLeader = (_this$loginUserInfo = this.loginUserInfo) === null || _this$loginUserInfo === void 0 ? void 0 : _this$loginUserInfo.IsLeader;
    this.isBoss = (_this$loginUserInfo2 = this.loginUserInfo) === null || _this$loginUserInfo2 === void 0 ? void 0 : _this$loginUserInfo2.IsBoss;
    this.isSuperManager = ((_this$loginUserInfo3 = this.loginUserInfo) === null || _this$loginUserInfo3 === void 0 ? void 0 : _this$loginUserInfo3.Role) === 2; // 超管

    this.isAssistant = ((_this$loginUserInfo4 = this.loginUserInfo) === null || _this$loginUserInfo4 === void 0 ? void 0 : _this$loginUserInfo4.Role) === 1; // 助理或者说动态管理员

    this.isOkrManager = (_this$loginUserInfo5 = this.loginUserInfo) === null || _this$loginUserInfo5 === void 0 ? void 0 : _this$loginUserInfo5.IsOkrManager; // 目标管理员

    this.isWorkManager = (_this$loginUserInfo6 = this.loginUserInfo) === null || _this$loginUserInfo6 === void 0 ? void 0 : _this$loginUserInfo6.IsWorkManager; // 项目管理员

    this.isAdminManager = ((_this$loginUserInfo7 = this.loginUserInfo) === null || _this$loginUserInfo7 === void 0 ? void 0 : _this$loginUserInfo7.Role) === 4; // 后台管理员
  }

  _createClass(MyRole, [{
    key: "getRole",
    value: function getRole() {
      if (this.isBoss) {
        return '老板';
      } else if (this.isSuperManager) {
        return '超管';
      } else if (this.isAssistant) {
        return '助理';
      } else if (this.isOkrManager) {
        return '目标管理员';
      } else if (this.isWorkManager) {
        return '项目管理员';
      } else if (this.isAdminManager) {
        return '后台管理员';
      } else if (this.isLeader) {
        return '部门领导';
      } else {
        return '员工';
      }
    }
  }]);

  return MyRole;
}();

exports.MyRole = MyRole;