"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.getTimeString = exports.getProgressState = void 0;

var _constant = require("../../utils/constant");

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

var _constant2 = require("./constant");

var getTimeString = function getTimeString(time, nowTime) {
  if (!time) {
    return (0, _getLocale.getLocale)("OKR_MyO_KRP_Notupdated");
  }

  var months = (0, _constant.getMonth)();
  var timeDateObj = new Date(time);
  var timeMilliSecond = timeDateObj.getTime();
  var timeYear = timeDateObj.getFullYear();
  var timeMonth = timeDateObj.getMonth() + 1;
  var timeDate = timeDateObj.getDate();
  var timeHours = timeDateObj.getHours() < 10 ? "0".concat(timeDateObj.getHours()) : timeDateObj.getHours();
  var timeMinutes = timeDateObj.getMinutes() < 10 ? "0".concat(timeDateObj.getMinutes()) : timeDateObj.getMinutes();
  var nowMilliSecond = nowTime.getTime();
  var nowYear = nowTime.getFullYear();
  var nowDate = nowTime.getDate();
  var secondDiff = Math.floor((nowMilliSecond - timeMilliSecond) / 1000);

  if (secondDiff <= 3) {
    return (0, _getLocale.getLocale)("Pro_page_Int_Justnow");
  }

  if (secondDiff < 60) {
    return "".concat(secondDiff).concat((0, _getLocale.getLocale)("Mood_secago"));
  }

  if (secondDiff < 60 * 60) {
    return "".concat(Math.floor(secondDiff / 60)).concat((0, _getLocale.getLocale)("Tasks_Tab_MyS_minuteago"));
  }

  if (secondDiff < 60 * 60 * 24) {
    return "".concat(Math.floor(secondDiff / (60 * 60))).concat((0, _getLocale.getLocale)("Mood_hoursago"));
  }

  if (secondDiff < 60 * 60 * 24 * 2 && nowDate - 1 === timeDate) {
    return "".concat((0, _getLocale.getLocale)("OKR_MyO_Pr_Text_Yesterday"), " ", "".concat(timeHours, ":").concat(timeMinutes));
  }

  if (secondDiff < 60 * 60 * 24 * 3 && nowDate - 2 === timeDate) {
    return "".concat((0, _getLocale.getLocale)("Mood_2daysago"), " ", "".concat(timeHours, ":").concat(timeMinutes));
  }

  if (timeYear === nowYear) {
    var _dateStr = months[timeMonth - 1] + (_getLocale.isEn ? " ".concat(timeDate, " ") : "".concat(timeDate, "\u65E5"));

    return "".concat(_dateStr, " ", "".concat(timeHours, ":").concat(timeMinutes));
  }

  var dateStr = (_getLocale.isEn ? "" : "".concat(timeYear, "\u5E74")) + months[timeMonth - 1] + (_getLocale.isEn ? " ".concat(timeDate, " ") : "".concat(timeDate, "\u65E5")) + (_getLocale.isEn ? ",".concat(timeYear) : "");
  return "".concat(dateStr, " ", "".concat(timeHours, ":").concat(timeMinutes));
};

exports.getTimeString = getTimeString;

var getProgressState = function getProgressState(oStatus, riskLevel) {
  // 2代表已结束
  if (oStatus === 2) {
    return "end";
  }

  return _constant2.OkrRiskMapping[riskLevel] ? _constant2.OkrRiskMapping[riskLevel] : "normal";
};

exports.getProgressState = getProgressState;