"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.visibilityRenderer = exports.userRenderer = exports.tooltipRenderer = exports.tooltipHtmlRenderer = exports.okrTypeRenderer = exports.krWeightRenderer = exports.krUserRenderer = exports.krNameRenderer = exports.getStatus = exports.TaskProgressRenderer = exports.OkrNameRenderer = exports.KrProgressRenderer = exports.EObjType = exports.ConfidenceRenderer = void 0;

var _react = _interopRequireDefault(require("react"));

var _okrTypeIcon = _interopRequireDefault(require("../okr-type-icon"));

var _okrProgress = _interopRequireDefault(require("../progress/okr-progress"));

var _newConfidence = _interopRequireDefault(require("../new-confidence"));

var _drawerManager = _interopRequireDefault(require("../drawer-manager"));

var _openData = require("../../utils/open-data");

var _tooltip = _interopRequireDefault(require("../tooltip"));

var _avatar = _interopRequireDefault(require("../avatar"));

var _periodSelector = _interopRequireDefault(require("../period-selector"));

var _tag = _interopRequireDefault(require("../tag"));

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

var _okrVisibility = require("../create-okr-modal/fields/okr-visibility");

var _openData2 = require("../okr-flow/open-data");

var _check = require("../../utils/check");

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

function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }

function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }

var preCls = 'tita-okr-excel';

function formatCycleData(periodParams, getCycleRange) {
  if (!periodParams) return '';
  var startDate = periodParams.startDate;
  var endDate = periodParams.endDate;

  if (new Date(periodParams.startDate).getFullYear() == new Date().getFullYear() && new Date(periodParams.startDate).getFullYear() == new Date(periodParams.endDate).getFullYear()) {
    startDate = periodParams.startDate.slice(5);
    endDate = periodParams.endDate.slice(5);
  }

  return "".concat(_periodSelector["default"].formatPeriod(periodParams)).concat(getCycleRange ? ",".concat(startDate, "~").concat(endDate) : '');
}

var OkrNameRenderer = function OkrNameRenderer(showCycle, onRefresh) {
  return function (params) {
    if (!params.data.workId) return /*#__PURE__*/_react["default"].createElement("div", {
      className: "excel-blank"
    });

    var onOpendrawer = /*#__PURE__*/function () {
      var _ref = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee() {
        return regeneratorRuntime.wrap(function _callee$(_context) {
          while (1) {
            switch (_context.prev = _context.next) {
              case 0:
                _context.next = 2;
                return _drawerManager["default"].open('okrDetail', {
                  okrId: params.data.workId
                });

              case 2:
                if (onRefresh) onRefresh();

              case 3:
              case "end":
                return _context.stop();
            }
          }
        }, _callee);
      }));

      return function onOpendrawer() {
        return _ref.apply(this, arguments);
      };
    }();

    var period = {
      cycleType: params.data.cycleType,
      yqmNum: params.data.yqmnum,
      annualNum: params.data.annualNum,
      startDate: params.data.startDate,
      endDate: params.data.endDate
    };
    return /*#__PURE__*/_react["default"].createElement("div", {
      className: "".concat(preCls, "__okr-name")
    }, /*#__PURE__*/_react["default"].createElement("p", {
      onClick: onOpendrawer
    }, /*#__PURE__*/_react["default"].createElement("span", {
      className: "".concat(preCls, "__okr-icon tu-icon-H5-O-s")
    }), (0, _openData.parseString)(params.value), showCycle && /*#__PURE__*/_react["default"].createElement(_tag["default"], {
      backgroundColor: "rgba(40,121,255,.16)",
      color: "#3f4755"
    }, formatCycleData(period, false)), /*#__PURE__*/_react["default"].createElement(_okrTypeIcon["default"], {
      okrClassify: params.data.okrClassify
    }), params.data.status === 2 && /*#__PURE__*/_react["default"].createElement(_tag["default"], null, (0, _getLocale.getLocale)('OKR_MyO_Butt_Hasended'))));
  };
};

exports.OkrNameRenderer = OkrNameRenderer;

var krNameRenderer = function krNameRenderer(onRefresh) {
  return function (params) {
    if (!params.data.Kr) return '';

    var onOpendrawer = /*#__PURE__*/function () {
      var _ref2 = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee2() {
        return regeneratorRuntime.wrap(function _callee2$(_context2) {
          while (1) {
            switch (_context2.prev = _context2.next) {
              case 0:
                _context2.next = 2;
                return _drawerManager["default"].open('krDetail', {
                  krId: params.data.Kr.mileStoneId
                });

              case 2:
                if (onRefresh) onRefresh();

              case 3:
              case "end":
                return _context2.stop();
            }
          }
        }, _callee2);
      }));

      return function onOpendrawer() {
        return _ref2.apply(this, arguments);
      };
    }();

    return /*#__PURE__*/_react["default"].createElement("p", {
      onClick: onOpendrawer,
      className: "".concat(preCls, "__kr-name")
    }, /*#__PURE__*/_react["default"].createElement("span", {
      className: "".concat(preCls, "__kr-name__index")
    }, "KR", params.data.Kr.index + 1), ' ', /*#__PURE__*/_react["default"].createElement(_tooltip["default"], {
      overlay: (0, _openData.parseString)(params.value),
      placement: "top"
    }, /*#__PURE__*/_react["default"].createElement("span", {
      className: "".concat(preCls, "__kr-name__title")
    }, (0, _openData.parseString)(params.value))));
  };
};

exports.krNameRenderer = krNameRenderer;

var getStatus = function getStatus(status) {
  var obj = {
    1: 'normal',
    2: 'delay',
    3: 'risk'
  };
  return obj[status] || 'normal';
};

exports.getStatus = getStatus;

var TaskProgressRenderer = function TaskProgressRenderer(_ref3) {
  var data = _ref3.data;
  if (!data.workId) return '';
  return /*#__PURE__*/_react["default"].createElement("div", {
    className: "".concat(preCls, "__okr-progress")
  }, /*#__PURE__*/_react["default"].createElement(_okrProgress["default"], {
    status: data.status === 2 ? 'normal' : getStatus(data.manualRiskLevel),
    value: data.progress
  }));
};

exports.TaskProgressRenderer = TaskProgressRenderer;
var EObjType;
exports.EObjType = EObjType;

(function (EObjType) {
  EObjType[EObjType["Project"] = 4] = "Project";
  EObjType[EObjType["Task"] = 7] = "Task";
  EObjType[EObjType["O"] = 62] = "O";
  EObjType[EObjType["Kr"] = 65] = "Kr";
  EObjType[EObjType["Assess"] = 23] = "Assess";
  EObjType[EObjType["MileStone"] = 27] = "MileStone";
  EObjType[EObjType["KanBan"] = 66] = "KanBan";
  EObjType[EObjType["Report"] = 8] = "Report";
})(EObjType || (exports.EObjType = EObjType = {}));

var KrProgressRenderer = function KrProgressRenderer(_ref4) {
  var data = _ref4.data;
  if (!data.Kr) return '';
  return /*#__PURE__*/_react["default"].createElement("div", {
    className: "".concat(preCls, "__okr-progress")
  }, /*#__PURE__*/_react["default"].createElement(_okrProgress["default"], {
    status: getStatus(data.Kr.riskLevel),
    value: data.Kr.progress
  }));
};

exports.KrProgressRenderer = KrProgressRenderer;

var ConfidenceRenderer = function ConfidenceRenderer(_ref5) {
  var data = _ref5.data;
  return data.Kr && data.Kr.confidenceIndex ? /*#__PURE__*/_react["default"].createElement(_newConfidence["default"], {
    value: data.Kr.confidenceIndex,
    editable: false
  }) : '';
};

exports.ConfidenceRenderer = ConfidenceRenderer;

var krWeightRenderer = function krWeightRenderer(_ref6) {
  var value = _ref6.value;
  return /*#__PURE__*/_react["default"].createElement("p", {
    className: "".concat(preCls, "__kr-weight")
  }, value && "".concat(value, "%"));
};

exports.krWeightRenderer = krWeightRenderer;

var krUserRenderer = function krUserRenderer(_ref7) {
  var _data$Kr$user;

  var value = _ref7.value,
      data = _ref7.data;
  if (!data.Kr || !data.Kr.user) return '';
  return /*#__PURE__*/_react["default"].createElement("div", {
    className: "".concat(preCls, "__kr-user")
  }, /*#__PURE__*/_react["default"].createElement(_avatar["default"], {
    src: data.Kr.user.avatar.small,
    name: value,
    color: "#2879ff"
  }), /*#__PURE__*/_react["default"].createElement(_openData2.OpenUserName, {
    name: value,
    id: (_data$Kr$user = data.Kr.user) === null || _data$Kr$user === void 0 ? void 0 : _data$Kr$user.userId
  }));
};

exports.krUserRenderer = krUserRenderer;

var userRenderer = function userRenderer(_ref8) {
  var _data$principalUser;

  var value = _ref8.value,
      data = _ref8.data;
  if (!data.principalUser || !data.workId) return '';
  return /*#__PURE__*/_react["default"].createElement("div", {
    className: "".concat(preCls, "__kr-user")
  }, /*#__PURE__*/_react["default"].createElement(_avatar["default"], {
    src: data.principalUser.avatar.small,
    name: value,
    color: "#2879ff"
  }), /*#__PURE__*/_react["default"].createElement(_openData2.OpenUserName, {
    name: value,
    id: (_data$principalUser = data.principalUser) === null || _data$principalUser === void 0 ? void 0 : _data$principalUser.userId
  }));
};

exports.userRenderer = userRenderer;

var getOkrTypeOption = function getOkrTypeOption(data) {
  var okrType = data.okrType,
      departmentId = data.departmentId,
      departmentName = data.departmentName,
      groupName = data.groupName;
  return {
    1: {
      icon: 'tu-icon-liebiao-geren',
      text: (0, _getLocale.getLocale)('OKR_MyO_Pop_Individual')
    },
    // 个人目标
    2: {
      icon: 'tu-icon-liebiao-xiashu',
      text: /*#__PURE__*/_react["default"].createElement(_openData.OpenDepartmentName, {
        name: departmentName,
        id: departmentId
      })
    },
    // 部门级目标
    3: {
      icon: 'tu-icon-gong_si',
      text: (0, _getLocale.getLocale)('OKR_MyO_Pop_Company')
    },
    // 公司级目标
    4: {
      icon: 'tu-icon-liebiao-tuandui',
      text: groupName || (0, _getLocale.getLocale)('OKR_MyO_Text_Team')
    } // 团队目标

  }[okrType];
};

var okrTypeRenderer = function okrTypeRenderer(_ref9) {
  var data = _ref9.data;
  if (!data.workId) return '';
  var option = getOkrTypeOption(data);
  return /*#__PURE__*/_react["default"].createElement("p", {
    className: "".concat(preCls, "__okr-type")
  }, /*#__PURE__*/_react["default"].createElement("span", {
    className: option.icon
  }), option.text);
};

exports.okrTypeRenderer = okrTypeRenderer;

var visibilityRenderer = function visibilityRenderer(_ref10) {
  var value = _ref10.value,
      data = _ref10.data;
  if (!data.workId) return '';
  var visibilityText = (0, _okrVisibility.visibilityMapText)()[value];
  return visibilityText;
};

exports.visibilityRenderer = visibilityRenderer;

var tooltipRenderer = function tooltipRenderer(params) {
  return /*#__PURE__*/_react["default"].createElement(_tooltip["default"], {
    overlay: params.value,
    placement: "top"
  }, /*#__PURE__*/_react["default"].createElement("p", {
    className: "".concat(preCls, "__tooltip")
  }, params.value));
};

exports.tooltipRenderer = tooltipRenderer;

var tooltipHtmlRenderer = function tooltipHtmlRenderer(params) {
  var isHtmlValue = (0, _check.isHtml)(params.value);
  return params.value && /*#__PURE__*/_react["default"].createElement(_tooltip["default"], {
    overlay: isHtmlValue ? /*#__PURE__*/_react["default"].createElement("div", {
      className: "editor-style",
      dangerouslySetInnerHTML: {
        __html: params.value
      }
    }) : /*#__PURE__*/_react["default"].createElement("pre", {
      style: {
        padding: 0,
        whiteSpace: 'pre-wrap'
      }
    }, params.value),
    placement: "top"
  }, /*#__PURE__*/_react["default"].createElement("div", {
    className: "".concat(preCls, "__html-container editor-style")
  }, isHtmlValue ? /*#__PURE__*/_react["default"].createElement("div", {
    dangerouslySetInnerHTML: {
      __html: params.value
    }
  }) : /*#__PURE__*/_react["default"].createElement("pre", {
    style: {
      padding: '5px 0px',
      width: 'max-content'
    }
  }, params.value)));
};

exports.tooltipHtmlRenderer = tooltipHtmlRenderer;