"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports["default"] = void 0;

var _classnames = _interopRequireDefault(require("classnames"));

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

var _checkbox = _interopRequireDefault(require("../../../checkbox"));

var _radio = _interopRequireDefault(require("../../radio"));

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

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

var _helper = require("../../helper");

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

var _tools = require("../../../../utils/tools");

require("./index.css");

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

var precls = "import-milestone-node";

function MileStone(props) {
  var data = props.data,
      _props$checked = props.checked,
      checked = _props$checked === void 0 ? false : _props$checked,
      disabled = props.disabled,
      _props$addSelected = props.addSelected,
      addSelected = _props$addSelected === void 0 ? function () {} : _props$addSelected,
      _props$removeSelected = props.removeSelected,
      removeSelected = _props$removeSelected === void 0 ? function () {} : _props$removeSelected,
      _props$multiple = props.multiple,
      multiple = _props$multiple === void 0 ? true : _props$multiple;
  var user = data.user;

  var openKrDrawer = function openKrDrawer() {
    window.Talent.app.vent.trigger("global-pull-screen", data.mileStoneId, "milestone", new window.Talent.Model(data), {
      option: true,
      width: 465,
      zIndex: 1310,
      top: 0
    });
  };

  var statusMap = {
    1: (0, _getLocale.getLocale)("OKR_MyO_E_From_NotStarted"),
    2: (0, _getLocale.getLocale)("Per_Ma_form_detail_Incomplete"),
    3: (0, _getLocale.getLocale)("OKR_MyO_E_From_Completed")
  };

  var onCheckHandler = function onCheckHandler(checked) {
    if (checked) {
      addSelected({
        type: "milestone",
        workId: data.workId,
        krId: data.mileStoneId,
        id: "mileStoneId-".concat(data.mileStoneId),
        name: data.mileStoneName,
        workName: data.workName
      });
    } else {
      removeSelected("mileStoneId-".concat(data.mileStoneId));
    }
  };

  return /*#__PURE__*/_react["default"].createElement("div", {
    className: precls,
    onClick: function onClick(e) {
      return e.stopPropagation();
    }
  }, multiple && /*#__PURE__*/_react["default"].createElement("span", {
    className: "".concat(precls, "__checkbox")
  }, /*#__PURE__*/_react["default"].createElement(_checkbox["default"], {
    onChange: onCheckHandler,
    checked: checked,
    disabled: disabled
  })), !multiple && /*#__PURE__*/_react["default"].createElement("span", {
    className: "".concat(precls, "__checkbox")
  }, /*#__PURE__*/_react["default"].createElement(_radio["default"], {
    onChange: onCheckHandler,
    id: data.mileStoneId,
    checked: checked
  })), /*#__PURE__*/_react["default"].createElement("span", {
    className: "".concat(precls, "__name")
  }, /*#__PURE__*/_react["default"].createElement("span", {
    className: (0, _classnames["default"])("tu-icon-licheng-s", "".concat(precls, "__name-icon"))
  }), /*#__PURE__*/_react["default"].createElement("span", {
    onClick: openKrDrawer
  }, (0, _openData.parseString)((0, _tools.htmlDecodeByHtmlRegExp)(data.mileStoneName)))), /*#__PURE__*/_react["default"].createElement("span", {
    className: "".concat(precls, "__status")
  }, statusMap[data.status]), /*#__PURE__*/_react["default"].createElement("span", {
    className: "".concat(precls, "__principle")
  }, /*#__PURE__*/_react["default"].createElement(_tooltip["default"].Text, {
    text: /*#__PURE__*/_react["default"].createElement(_openData.OpenUserName, {
      name: user.name,
      id: user.userId
    }),
    maxWidth: 60
  })), /*#__PURE__*/_react["default"].createElement("span", {
    className: "".concat(precls, "__time")
  }, (0, _helper.formatDateStr)(data.startDate), "-", (0, _helper.formatDateStr)(data.endDate)));
}

MileStone.defaultProps = {
  checked: false,
  disabled: false
};
var _default = MileStone;
exports["default"] = _default;