"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.lableTypeMap = exports.isOpenWorkManage = exports.isOpenOkrManage = exports.isOpenLabel = exports.getCycleDate = exports.formatDateStr = void 0;
exports.momentDate = momentDate;
exports.workStatus = exports.timeFormat = exports.preCls = exports.okrStatus = void 0;

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

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

function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }

function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure 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 _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 _iterableToArrayLimit(arr, i) { var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"]; if (_i == null) return; var _arr = []; var _n = true; var _d = false; var _s, _e; try { for (_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; }

function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }

var preCls = 'titaui-task-import';
exports.preCls = preCls;
var isOpenOkrManage = (0, _bsGlobal.getAppHead)('113'); // 开通OKR

exports.isOpenOkrManage = isOpenOkrManage;
var isOpenWorkManage = (0, _bsGlobal.getAppHead)('112'); // 开通项目

exports.isOpenWorkManage = isOpenWorkManage;
var TaskAdvancedSetting = (0, _bsGlobal.getBSGlobal)('TaskAdvancedSetting');
var isOpenLabel = TaskAdvancedSetting === null || TaskAdvancedSetting === void 0 ? void 0 : TaskAdvancedSetting.TaskPlanSetting.TaskLabel; // 开启分类

exports.isOpenLabel = isOpenLabel;
var lableTypeMap = {
  // 分类的类型（4：项目 17：普通分类 62:目标
  okr: 62,
  kr: 62,
  work: 4,
  milestone: 4,
  lable: 17
};
exports.lableTypeMap = lableTypeMap;

var strFormat = function strFormat(num) {
  if (num < 10) {
    return '0' + num;
  }

  return num;
};

var timeFormat = function timeFormat(NowDate) {
  var date = new Date(NowDate);
  var y = date.getFullYear(); // 年

  var m = date.getMonth() + 1; // 月

  var d = date.getDate(); // 日

  return "".concat(y, "/").concat(strFormat(m), "/").concat(strFormat(d));
};

exports.timeFormat = timeFormat;

var formatDateStr = function formatDateStr(str) {
  str = timeFormat(str);
  var currentYear = new Date().getFullYear();

  if (str.indexOf(currentYear) !== -1) {
    return str.substr(5);
  }

  return str;
};

exports.formatDateStr = formatDateStr;

var okrStatus = function okrStatus(key) {
  // 分类的类型（4：项目 17：普通分类 62:目标
  var label = (0, _getLocale.getLocale)('OKR_MyO_E_From_AllStates');

  switch (Number(key)) {
    case 1:
      label = (0, _getLocale.getLocale)('Per_MyRe_text_Inprogress');
      break;

    case 2:
      label = (0, _getLocale.getLocale)('Pro_page_Sta_Completed');
      break;

    case 3:
      label = (0, _getLocale.getLocale)('OKR_MyO_E_From_Delayed');
      break;

    case 4:
      label = (0, _getLocale.getLocale)('OKR_MyO_E_From_Cancelled');
      break;

    case 5:
      label = (0, _getLocale.getLocale)('OKR_MyO_E_From_Notaccepted');
      break;

    case 6:
      label = (0, _getLocale.getLocale)('OKR_MyO_E_From_Suspended');
      break;

    case 0:
      label = (0, _getLocale.getLocale)('OKR_MyO_E_From_NotStarted');
      break;

    default:
      break;
  }

  return label;
};

exports.okrStatus = okrStatus;

var workStatus = function workStatus() {
  return {
    1: (0, _getLocale.getLocale)('Per_MyRe_text_Inprogress'),
    2: (0, _getLocale.getLocale)('OKR_MyO_E_From_Completed')
  };
};

exports.workStatus = workStatus;

function momentDate(date) {
  var reg = new RegExp('年|月|日', 'g');
  return date.replace(reg, '/').slice(0, -1);
}

var getCycleDate = function getCycleDate(date) {
  if (date) {
    var _date$split = date.split('/'),
        _date$split2 = _slicedToArray(_date$split, 2),
        year = _date$split2[0],
        month = _date$split2[1];

    var startDate = new Date();
    var endDate = new Date();
    startDate.setFullYear(Number(year));
    startDate.setMonth(Number(month) - 1);
    startDate.setDate(1);
    endDate.setFullYear(Number(year));
    endDate.setMonth(Number(month));
    endDate.setDate(0);
    return {
      start: "".concat(startDate.getFullYear(), "/").concat(startDate.getMonth() + 1, "/").concat(startDate.getDate()),
      end: "".concat(endDate.getFullYear(), "/").concat(endDate.getMonth() + 1, "/").concat(endDate.getDate())
    };
  }

  var newStartDate = new Date();
  var newEndDate = new Date();
  newStartDate.setDate(1);
  newEndDate.setMonth(newEndDate.getMonth() + 1);
  newEndDate.setDate(0);
  return {
    start: "".concat(newStartDate.getFullYear(), "/").concat(newStartDate.getMonth() + 1, "/").concat(newStartDate.getDate()),
    end: "".concat(newEndDate.getFullYear(), "/").concat(newEndDate.getMonth() + 1, "/").concat(newEndDate.getDate())
  };
};

exports.getCycleDate = getCycleDate;