"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 _avatar = _interopRequireDefault(require("../../../../../../components/avatar"));

var _tooltipText = _interopRequireDefault(require("../../../../../tooltip/tooltip-text"));

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

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

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

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

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

require("./index.css");

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

var preCls = "titaui-user-message-msg-inform";

function Inform(props) {
  var item = props.item,
      onItemClick = props.onItemClick,
      informs = props.informs;
  var domRef = (0, _react.useRef)();

  var handleItemClick = function handleItemClick() {
    onItemClick && onItemClick(false);
    var objType = item.objType,
        objId = item.objId,
        messageType = item.messageType,
        user = item.user;

    if (objType === _constant.EObjType.Kr) {
      _drawerManager["default"].open("krDetail", {
        krId: objId
      });

      return;
    }

    if (objType === _constant.EObjType.O) {
      _drawerManager["default"].open("okrDetail", {
        okrId: objId
      });

      return;
    }

    if (objType === _constant.EObjType.Project) {
      (0, _tools.openPage)("".concat(_constant.apiServer, "/u/").concat(_constant.userId, "/Home#more/messages?messageType=2&tabAppId=1&tabAppType=1&isRead=2&messageSubNav=1"));
      return;
    }

    if (objType === _constant.EObjType.Task) {
      // @ts-ignore
      window.Talent.app.vent.trigger("global-pull-screen", objId, "task");
      return;
    }

    if (objType === _constant.EObjType.Remind) {
      var reg = /href=".*?(?=")/g;
      var url = "";
      item.content.replace(reg, function ($0) {
        url = $0.slice(6);
      });

      if (url) {
        (0, _tools.openPage)(url);
        return;
      } // @ts-ignore


      window.Talent.app.vent.trigger("global-daily-detail-pull-screen", objId);
      return;
    }

    if (objType === _constant.EObjType.Interview) {
      messageType !== 153 && (0, _tools.openPage)( // 153：删除面谈的通知类型
      "".concat(_constant.apiServer, "/u/").concat(_constant.userId, "/Home#/interview?reactRouterName=detail&hideNavTop=true&recordId=").concat(objId, "&toUserId=").concat(user === null || user === void 0 ? void 0 : user.userId));
      return;
    }

    if (messageType == 135) {
      var redisKey = item.content.match(/redisKey=(\S*?)"/)[1]; // @ts-ignore

      Talent.app.vent.trigger("open-weekly-report-modal", redisKey);
      return;
    } // 处理合并的消息


    var isMessageMerging = [83, 94, 95, 96, 97, 98, 99, 100, 131, 136, 180, 13018, 30362].includes(messageType);

    if (!isMessageMerging) {
      if (messageType === _constant.informType.details) {
        (0, _tools.openPage)("".concat(_constant.apiServer, "/u/").concat(_constant.userId, "/Home#more/taskinfo?Id=").concat(item.objId));
        return;
      }

      if (messageType === _constant.informType.todayJob) {
        window.open("".concat(_constant.apiServer, "/u/").concat(_constant.userId, "/Home#plan?tag_id=0&tag_type=0&filter=1"));
        return;
      }

      if (objType === 0 && messageType === 93) {
        (0, _tools.openPage)("".concat(_constant.apiServer, "/u/").concat(_constant.userId, "/Home#more/messages?messageType=2&tabAppId=1&tabAppType=1&isRead=2&messageSubNav=1"));
        return;
      }

      if (objType === 0) {
        var str = item.content.match(/\/\/.*?[\"|\']/gi);
        if (!str) return;
        str = str.join("");

        var _url2 = str.slice(0, str.length - 1);

        if (_url2) {
          if (item.content.indexOf("点击此处下载") !== -1) {
            window.open(_url2, "_self");
          }

          (0, _tools.openPage)(_url2);
        }

        return;
      }

      if (item.objUrl) {
        window.open(item.objUrl);
        return;
      }

      if (objType === _constant.informType.Okr) {
        var _url3 = item.content.match(/(http[s]?:\/\/([\w-]+.)+([:\d+])?(\/[\w-\.\/\?%&=]*))/g);

        (0, _tools.openPage)(_url3);
        return;
      }

      if (objType === _constant.informType.okrRemind) {
        window.open("".concat(_constant.apiServer, "/u/").concat(_constant.userId, "/Home#/work?iTalentNavCode=tita-work&work_id=").concat(objId));
        return;
      }

      if (objType === _constant.informType.plan) {
        var _str = item.content.match(/\/\/.*?[\"|\']/gi);

        if (!_str) return;
        _str = _str.join("");

        var _url4 = _str.slice(0, _str.length - 1);

        (0, _tools.openPage)(_url4);
        return;
      }

      if (objType === _constant.informType.remindLeader) {
        var _str2 = item.content.match(/https:.*?[\"|\']/gi);

        if (!_str2) return;
        _str2 = _str2.join("");

        var _url5 = _str2.slice(0, _str2.length - 1);

        (0, _tools.openPage)(_url5);
        return;
      }

      if (objId && objType !== 8) {
        window.open("".concat(_constant.apiServer, "/u/").concat(_constant.userId, "/Home#work?work_id=").concat(item.objId));
        return;
      }

      if (objId && objType == 74) {
        window.open("".concat(_constant.apiServer, "/u/").concat(_constant.userId, "/Home#performance?formId=").concat(item.objId, "&reactRouterName=detail"));
        return;
      }

      var _reg = /href='.*?(?=')/g;
      var _url = "";
      item.content.replace(_reg, function ($0) {
        _url = $0.slice(6);
      });

      if (_url) {
        (0, _tools.openPage)(_url);
        return;
      }
    }

    var notificationType = "e-report"; // E-周报提醒消息合并

    var content = domRef.current.textContent;

    if (messageType == "83") {
      // 项目，目标进展提醒消息合并
      notificationType = "project-objective";
    } else if (Number(messageType) > 93 && Number(messageType) <= 100) {
      // OKR 仪表盘消息提醒
      notificationType = "okr-dashBoard";
    } else if ([131, 136, 180].includes(Number(messageType))) {
      notificationType = "performance";
      content = item.content;
    }

    _drawerManager["default"].open("NotificationMergeDetail", {
      config: {
        content: content,
        messageId: item.messageId,
        messageType: item.messageType,
        notificationDate: item.createTime,
        notificationType: notificationType,
        objId: item.objId,
        objType: item.objType
      }
    }, {
      width: 680
    });
  };

  return /*#__PURE__*/_react["default"].createElement("li", {
    className: (0, _classnames["default"])("".concat(preCls, "__item"), _defineProperty({}, "".concat(preCls, "__item--scroll"), informs.length >= 4)),
    key: item.messageId,
    onClick: handleItemClick
  }, /*#__PURE__*/_react["default"].createElement("div", {
    className: (0, _classnames["default"])("".concat(preCls, "__item-photo"))
  }, /*#__PURE__*/_react["default"].createElement(_avatar["default"], {
    userId: item.user.userId,
    name: item.user.name,
    color: item.user.avatar.Color,
    src: item.user.avatar.Small,
    size: {
      width: 32,
      textNum: 1,
      fontSize: 12
    }
  })), /*#__PURE__*/_react["default"].createElement("div", {
    className: (0, _classnames["default"])("".concat(preCls, "__item-right"))
  }, /*#__PURE__*/_react["default"].createElement("span", {
    ref: domRef
  }, /*#__PURE__*/_react["default"].createElement("div", {
    className: (0, _classnames["default"])("".concat(preCls, "__item-right-name"))
  }, /*#__PURE__*/_react["default"].createElement(_tooltipText["default"], {
    overlayClassName: "".concat(preCls, "__item-right-name-tooltip"),
    text: /*#__PURE__*/_react["default"].createElement(_openData.OpenUserName, {
      name: item.user.name,
      id: item.user.userId
    }),
    maxWidth: 100,
    mouseEnterDelay: 0.8
  })), /*#__PURE__*/_react["default"].createElement("div", {
    className: (0, _classnames["default"])("".concat(preCls, "__item-right-content"))
  }, /*#__PURE__*/_react["default"].createElement(_tooltipText["default"], {
    overlayClassName: "".concat(preCls, "__item-right-content-tooltip"),
    text: (0, _openData.parseString)((0, _utils.deleteText)(item.content)),
    isPercent: true,
    mouseEnterDelay: 0.8
  })), /*#__PURE__*/_react["default"].createElement("div", {
    className: (0, _classnames["default"])("".concat(preCls, "__item-right-time"))
  }, item.createTime))));
}

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