"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.getApprovalOpenItem = exports.getApprovalOkr = exports.getApprovalKr = exports.getApprovalIsShow = exports.getApproval = exports.EApproveStatus = exports.EApprovalTypes = exports.EApprovalKrTypes = void 0;
var EApprovalTypes;
exports.EApprovalTypes = EApprovalTypes;

(function (EApprovalTypes) {
  EApprovalTypes[EApprovalTypes["CreateOkr"] = 53] = "CreateOkr";
  EApprovalTypes[EApprovalTypes["ChangeOkrName"] = 54] = "ChangeOkrName";
  EApprovalTypes[EApprovalTypes["ChangeOkrTime"] = 56] = "ChangeOkrTime";
  EApprovalTypes[EApprovalTypes["DeleteOkr"] = 55] = "DeleteOkr";
})(EApprovalTypes || (exports.EApprovalTypes = EApprovalTypes = {}));

var EApprovalKrTypes;
exports.EApprovalKrTypes = EApprovalKrTypes;

(function (EApprovalKrTypes) {
  EApprovalKrTypes[EApprovalKrTypes["Createkr"] = 57] = "Createkr";
  EApprovalKrTypes[EApprovalKrTypes["ChangekrName"] = 58] = "ChangekrName";
  EApprovalKrTypes[EApprovalKrTypes["ChangekrTime"] = 60] = "ChangekrTime";
  EApprovalKrTypes[EApprovalKrTypes["Deletekr"] = 59] = "Deletekr";
})(EApprovalKrTypes || (exports.EApprovalKrTypes = EApprovalKrTypes = {}));

var EApproveStatus;
exports.EApproveStatus = EApproveStatus;

(function (EApproveStatus) {
  EApproveStatus[EApproveStatus["None"] = 0] = "None";
  EApproveStatus[EApproveStatus["WaitCommit"] = 6] = "WaitCommit";
  EApproveStatus[EApproveStatus["Rejected"] = 3] = "Rejected";
  EApproveStatus[EApproveStatus["UnderApproval"] = 1] = "UnderApproval";
  EApproveStatus[EApproveStatus["ApproveAgree"] = 2] = "ApproveAgree";
  EApproveStatus[EApproveStatus["WithDraw"] = 4] = "WithDraw";
  EApproveStatus[EApproveStatus["Done"] = 5] = "Done";
})(EApproveStatus || (exports.EApproveStatus = EApproveStatus = {}));

var getApprovalOpenItem = function getApprovalOpenItem(setting) {
  var result = {
    isOpen: setting.isOpened === 1,
    changeOkrName: false,
    changeOkrTime: false,
    deleteOkr: false,
    createOkr: false
  };

  if (setting !== null && setting !== void 0 && setting.okrApprovalSettings) {
    setting.okrApprovalSettings.forEach(function (item) {
      if (item.approvalType === EApprovalTypes.ChangeOkrName) {
        result.changeOkrName = true;
      } else if (item.approvalType === EApprovalTypes.ChangeOkrTime) {
        result.changeOkrTime = true;
      } else if (item.approvalType === EApprovalTypes.CreateOkr) {
        result.createOkr = true;
      } else if (item.approvalType === EApprovalTypes.DeleteOkr) {
        result.deleteOkr = true;
      }
    });
  }

  return result;
};

exports.getApprovalOpenItem = getApprovalOpenItem;

var getApprovalIsShow = function getApprovalIsShow(approvalSetting, type, applyState) {
  var okrType = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : [];
  var krType = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : [];
  {
    /* 有编辑权限，
      且审批开关没有开启
      或者审批开关开启但是没开修改okr名字审批 且(状态不是审批中或者状态审批中且不为新建)
      或者开启okr审批开关 且开启okr名字审批 且当前状态不是审批中的时候是可编辑的 */
  }
  var okrCreate = okrType === null || okrType === void 0 ? void 0 : okrType.includes(EApprovalTypes.CreateOkr);
  var krCreate = krType === null || krType === void 0 ? void 0 : krType.includes(EApprovalKrTypes.Createkr);
  var isCreate = okrCreate || krCreate;
  return !approvalSetting.isOpen || approvalSetting.isOpen && !(approvalSetting !== null && approvalSetting !== void 0 && approvalSetting[type]) && (applyState !== EApproveStatus.UnderApproval || applyState === EApproveStatus.UnderApproval && !isCreate) || approvalSetting.isOpen && (approvalSetting === null || approvalSetting === void 0 ? void 0 : approvalSetting[type]) && applyState !== EApproveStatus.UnderApproval;
};

exports.getApprovalIsShow = getApprovalIsShow;

var getApproval = function getApproval(approvalSetting, type, applyState, isCreate) {
  return !(!(approvalSetting !== null && approvalSetting !== void 0 && approvalSetting[type]) && applyState === EApproveStatus.UnderApproval && isCreate || approvalSetting !== null && approvalSetting !== void 0 && approvalSetting[type] && applyState === EApproveStatus.UnderApproval);
};

exports.getApproval = getApproval;

var getApprovalOkr = function getApprovalOkr(approvalSetting, type, applyState) {
  var okrType = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : [];
  var okrCreate = okrType === null || okrType === void 0 ? void 0 : okrType.includes(EApprovalTypes.CreateOkr);
  return getApproval(approvalSetting, type, applyState, okrCreate);
};

exports.getApprovalOkr = getApprovalOkr;

var getApprovalKr = function getApprovalKr(approvalSetting, type, applyState) {
  var okrType = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : [];
  var krType = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : [];
  var okrCreate = okrType === null || okrType === void 0 ? void 0 : okrType.includes(EApprovalTypes.CreateOkr);
  var krCreate = krType === null || krType === void 0 ? void 0 : krType.includes(EApprovalKrTypes.Createkr);
  var isCreate = okrCreate || krCreate;
  return getApproval(approvalSetting, type, applyState, isCreate);
};

exports.getApprovalKr = getApprovalKr;