"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.getKrItemData = exports.getIitData = exports.formatDataToOKRExcelTableData = exports.formatDataToOKRExcelData = void 0;

var _uuid = _interopRequireDefault(require("uuid"));

var _helpers = require("../../utils/helpers");

var _common = require("../period-selector/common");

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }

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 ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); 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 = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : 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; }

var loginUser = (0, _helpers.getLoginUserInfo)();

var getKrItemData = function getKrItemData() {
  return {
    uuid: (0, _uuid["default"])(),
    mileStoneId: 0,
    feedId: '',
    workId: 0,
    mileStoneName: '',
    mileStoneNameRichText: '',
    aiteUsers: [],
    mileStoneDescription: '',
    principalId: 0,
    createUserId: loginUser.Id,
    startDate: '',
    endDate: '',
    lastUpdatedDate: '',
    user: {
      userId: loginUser.Id,
      userType: loginUser.Type,
      name: loginUser.Name,
      email: loginUser.Email,
      managerId: loginUser.ManagerId,
      jobState: loginUser.JobState,
      departmentId: loginUser.DepartmentId,
      departmentName: loginUser.Department,
      postition: loginUser.Position,
      subType: 0,
      hasSubordinates: loginUser.HasSub,
      avatar: _objectSpread({}, loginUser.UserAvatar),
      staffCode: ''
    },
    counter: {
      taskTotal: 0,
      finishTaskTotal: 0,
      workTotal: 0,
      finishWrokTotal: 0,
      eTotal: 0,
      finishETotal: 0,
      subWorkTotal: 0
    },
    departments: '',
    status: 1,
    remainingDays: 0,
    progress: 0,
    progressGrow: 0,
    riskLevel: 0,
    remainingContent: '',
    progressDescription: '',
    editable: false,
    evaluateEditable: true,
    krWeightEditable: false,
    confidenceIndex: 5,
    evaluateValue: 0,
    remark: '',
    confidenceIndexGrow: 0,
    isEvaluate: false,
    krWeight: 100.0,
    okrInfo: '',
    tasks: null,
    mapkrVisible: true,
    CreateDate: '2022/3/14 16:16:36',
    SortNum: 0,
    UpdateProgressWay: 0,
    progressDescriptionDate: null,
    applyState: 0,
    krApprovalType: '',
    KrApprovalTypes: []
  };
};

exports.getKrItemData = getKrItemData;

var getIitData = function getIitData(_ref) {
  var annualNum = _ref.annualNum,
      cycleType = _ref.cycleType,
      yqmNum = _ref.yqmNum;
  return _objectSpread(_objectSpread({
    uuid: (0, _uuid["default"])(),
    workId: 0,
    workName: '',
    isSaved: false,
    workNameRichText: '',
    visibility: 2,
    visibilityScope: undefined,
    departmentId: loginUser.DepartmentId,
    departmentName: loginUser.Department,
    groupId: 0,
    groupName: '',
    krs: [_objectSpread({}, getKrItemData())],
    okrClassify: 0,
    cycleType: cycleType,
    yqmNum: yqmNum
  }, (0, _common.getDateRangeByCycle)({
    annualNum: annualNum,
    cycleType: cycleType,
    yqmNum: yqmNum
  }, 1) || {}), {}, {
    parentId: 0,
    parentKrId: 0,
    annualNum: annualNum,
    hasSub: false,
    okrType: 1,
    createUserId: loginUser.Id,
    principalUser: {
      userId: loginUser.Id,
      userType: loginUser.Type,
      name: loginUser.Name,
      email: loginUser.Email,
      managerId: loginUser.ManagerId,
      jobState: loginUser.JobState,
      departmentId: loginUser.DepartmentId,
      departmentName: loginUser.Department,
      postition: loginUser.Position,
      subType: 0,
      hasSubordinates: loginUser.HasSub,
      avatar: _objectSpread({}, loginUser.UserAvatar),
      staffCode: ''
    },
    parentPrincipal: null,
    isShowApprovalOpinion: false
  });
};

exports.getIitData = getIitData;

var formatDataToOKRExcelTableData = function formatDataToOKRExcelTableData(data) {
  return data.map(function (detail) {
    detail.childs = [].concat(_toConsumableArray(detail.krs), [{
      isAddKR: true
    }]);
    return detail;
  });
};

exports.formatDataToOKRExcelTableData = formatDataToOKRExcelTableData;

var formatDataToOKRExcelData = function formatDataToOKRExcelData(data) {
  var okrExcelData = [];
  data.forEach(function (detail) {
    var tempData = JSON.parse(JSON.stringify(detail));
    var krs = tempData.krs;
    krs.forEach(function (item, index) {
      okrExcelData.push(_objectSpread(_objectSpread({}, tempData), {}, {
        kr: _objectSpread(_objectSpread({}, item), {}, {
          mileStoneId: tempData.workId + '_' + (item.isAddKR ? 'addKR' : index)
        }),
        rowSpan: index === 0 ? krs.length : 0,
        colSpan: item.isAddKR ? 4 : 0
      }));
    });
  });
  console.log(okrExcelData);
  return okrExcelData;
};

exports.formatDataToOKRExcelData = formatDataToOKRExcelData;