"use strict";

function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }

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

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

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

var _dynamicLeftQuoto = _interopRequireDefault(require("../../img/dynamic-left-quoto.svg"));

var _dynamicRightQuoto = _interopRequireDefault(require("../../img/dynamic-right-quoto.svg"));

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

var _context = require("../../context");

var _searchKeyHandle = _interopRequireDefault(require("../../../search-key-handle"));

var _header = _interopRequireDefault(require("../components/header"));

var _title = _interopRequireDefault(require("../../components/title"));

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

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

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

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

var _utils = require("../dynamic-progress/utils");

var _reward = _interopRequireDefault(require("./img/reward.png"));

var _utils2 = require("./utils");

require("./index.css");

var _excluded = ["data"];

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

function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }

function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { "default": obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj["default"] = obj; if (cache) { cache.set(obj, newObj); } return newObj; }

function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }

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; }

function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }

function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }

var prefix = "titaui-dynamic-reward-item";

var DynamicReward = function DynamicReward(_ref) {
  var data = _ref.data,
      restProps = _objectWithoutProperties(_ref, _excluded);

  var rewardContent = data.rewardContent,
      rewardTags = data.rewardTags,
      obj = data.obj,
      rewardUser = data.rewardUser,
      publishUser = data.publishUser;

  var _useContext = (0, _react.useContext)(_context.SearchKeyContext),
      searchKeyWord = _useContext.searchKeyWord;

  var handleClickTitle = function handleClickTitle() {
    if (!obj) {
      return;
    }

    var objType = obj.objType,
        objId = obj.objId;

    if (objType === _constant.EObjType.Kr) {
      _drawerManager["default"].open("krDetail", {
        krId: objId
      });
    } else if (objType === _constant.EObjType.O) {
      _drawerManager["default"].open("okrDetail", {
        okrId: objId
      });
    } else if (objType === _constant.EObjType.Task) {
      window.Talent.app.vent.trigger("global-pull-screen", objId, "task");
    } else if (objType === _constant.EObjType.Project) {
      window.open(window.location.href.replace(window.location.hash, "#work?iTalentNavCode=tita-work&work_id=".concat(objId)));
    } else if (objType === _constant.EObjType.Assess) {
      var assessId = data.url.split("assessId=")[1];
      window.open(window.location.href.replace(window.location.hash, "#performance?reactRouterName=detail&formId=".concat(assessId)));
    }
  };

  var renderDesc = (0, _react.useMemo)(function () {
    var url = ""; // const url = getUrlForUserPage({
    //   userId: rewardUser.name,
    //   userType: rewardUser.userType,
    // });

    var handleOpenUserPage = function handleOpenUserPage() {
      if (!url) return;
      window.open(url, "_blank");
    };

    return /*#__PURE__*/_react["default"].createElement("span", {
      className: "".concat(prefix, "__operate-desc")
    }, /*#__PURE__*/_react["default"].createElement("span", {
      className: "".concat(prefix, "__reward")
    }, "\u83B7\u5F97", /*#__PURE__*/_react["default"].createElement("span", {
      className: (0, _classnames["default"])("".concat(prefix, "__reward-user"), _defineProperty({}, "".concat(prefix, "__reward-user--not-link"), !url)),
      onClick: handleOpenUserPage
    }, /*#__PURE__*/_react["default"].createElement(_openData.OpenUserName, {
      name: rewardUser.name,
      id: rewardUser.userId
    })), (0, _getLocale.getLocale)("OKR_MyO_E_Reward"), /*#__PURE__*/_react["default"].createElement("img", {
      alt: "",
      src: _reward["default"],
      className: "".concat(prefix, "__reward-img")
    })));
  }, []);
  return /*#__PURE__*/_react["default"].createElement("div", {
    className: prefix
  }, /*#__PURE__*/_react["default"].createElement(_header["default"], _extends({
    data: data,
    desc: renderDesc,
    user: publishUser
  }, restProps)), /*#__PURE__*/_react["default"].createElement("div", {
    className: "".concat(prefix, "__content")
  }, /*#__PURE__*/_react["default"].createElement("div", {
    className: "".concat(prefix, "__title")
  }, obj && obj.objName && (0, _utils2.isShowRewardObj)(obj.objType) && /*#__PURE__*/_react["default"].createElement(_title["default"], _extends({
    content: (0, _tools.htmlDecodeByRegExp)(obj.objName),
    onClickTitle: handleClickTitle
  }, (0, _utils.getDynamicTitleProps)(obj)))), /*#__PURE__*/_react["default"].createElement("div", {
    className: "".concat(prefix, "__description"),
    style: {
      marginTop: obj && obj.objName ? "12px" : "0"
    }
  }, /*#__PURE__*/_react["default"].createElement("div", null, /*#__PURE__*/_react["default"].createElement("img", {
    className: (0, _classnames["default"])("".concat(prefix, "__description-quoto"), "".concat(prefix, "__description-quoto--left")),
    alt: "",
    src: _dynamicLeftQuoto["default"]
  })), /*#__PURE__*/_react["default"].createElement("div", null, /*#__PURE__*/_react["default"].createElement(_searchKeyHandle["default"], {
    str: rewardContent || "赐予你力量!",
    keyWord: searchKeyWord
  }), /*#__PURE__*/_react["default"].createElement("img", {
    className: (0, _classnames["default"])("".concat(prefix, "__description-quoto"), "".concat(prefix, "__description-quoto--right")),
    alt: "",
    src: _dynamicRightQuoto["default"]
  }), rewardTags && rewardTags.length && rewardTags.map(function (reward) {
    return reward.tagName && /*#__PURE__*/_react["default"].createElement("span", {
      className: "".concat(prefix, "__reward-tag"),
      style: {
        background: (0, _tools.hexToRgba)(reward.color, 0.2),
        color: reward.color
      }
    }, reward.tagName);
  })))));
};

var _default = DynamicReward;
exports["default"] = _default;