"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 _reactTooltip = _interopRequireDefault(require("react-tooltip"));

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

var _Portals = _interopRequireDefault(require("../../components-v1/portals/Portals"));

var _ConfirmPop = _interopRequireDefault(require("../delete-confirm-pop/ConfirmPop"));

var _ConvertUserName = _interopRequireDefault(require("./ConvertUserName"));

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

var _richEditor = _interopRequireDefault(require("@titaui/rich-editor"));

var _fileList = _interopRequireDefault(require("../file-list"));

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

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

require("./index.css");

var _style = require("./style");

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

var prefix = "titaui-communication";

var CommunicationRecord = function CommunicationRecord(_ref) {
  var communicationTrack = _ref.communicationTrack,
      _ref$confirmPopAlign = _ref.confirmPopAlign,
      confirmPopAlign = _ref$confirmPopAlign === void 0 ? "top right" : _ref$confirmPopAlign,
      highLightKeyWord = _ref.highLightKeyWord,
      index = _ref.index,
      onCommunicationRecordChange = _ref.onCommunicationRecordChange,
      className = _ref.className,
      praiseStatus = _ref.praiseStatus;
  var contentRef = (0, _react.useRef)();
  (0, _react.useEffect)(function () {
    (0, _tools.unHighLight)({
      parentDom: contentRef.current
    });

    if (highLightKeyWord) {
      (0, _tools.highLightWord)({
        parentDom: contentRef.current,
        keyWord: highLightKeyWord
      });
    }
  }, [highLightKeyWord]);
  return /*#__PURE__*/_react["default"].createElement(_style.CommunicationItem, {
    className: className
  }, /*#__PURE__*/_react["default"].createElement(_avatar["default"], {
    size: {
      width: 28,
      fontSize: 14,
      textNum: 1
    },
    name: communicationTrack.publishUser.name,
    src: communicationTrack.publishUser.avatar.small,
    color: communicationTrack.publishUser.avatar.color,
    userId: communicationTrack.publishUser.userId
  }), /*#__PURE__*/_react["default"].createElement(_style.CommunicationDetail, null, /*#__PURE__*/_react["default"].createElement("p", {
    style: {
      color: "#3a4247",
      wordBreak: "break-all",
      display: 'flex',
      alignItems: 'center'
    }
  }, communicationTrack.commentType != 2 ? /*#__PURE__*/_react["default"].createElement("span", {
    className: "".concat(prefix, "__communication-item")
  }, /*#__PURE__*/_react["default"].createElement(_ConvertUserName["default"], {
    userName: communicationTrack.publishUser.name,
    userId: communicationTrack.publishUser.userId
  }), /*#__PURE__*/_react["default"].createElement("span", {
    className: "".concat(prefix, "__communication-time")
  }, communicationTrack.createDate)) : /*#__PURE__*/_react["default"].createElement("span", {
    className: "".concat(prefix, "__communication-item")
  }, /*#__PURE__*/_react["default"].createElement(_ConvertUserName["default"], {
    userName: communicationTrack.publishUser.name,
    userId: communicationTrack.publishUser.userId
  }), /*#__PURE__*/_react["default"].createElement("span", {
    className: "".concat(prefix, "__communication-text")
  }, (0, _getLocale.getLocale)("Mod_Reply")), /*#__PURE__*/_react["default"].createElement(_ConvertUserName["default"], {
    userName: communicationTrack.parentUser.name,
    userId: communicationTrack.parentUser.userId
  }), /*#__PURE__*/_react["default"].createElement("span", {
    className: "".concat(prefix, "__communication-time")
  }, communicationTrack.createDate), /*#__PURE__*/_react["default"].createElement(_Portals["default"], null, /*#__PURE__*/_react["default"].createElement(_reactTooltip["default"], {
    html: true,
    className: "tt-react-tooltip",
    place: "top",
    type: "dark",
    effect: "solid"
  })))), /*#__PURE__*/_react["default"].createElement("span", {
    className: "".concat(prefix, "__communication-content"),
    ref: contentRef
  }, [undefined, 0].includes(communicationTrack.version) && (0, _openData.parseTag)(communicationTrack.content.trim()), communicationTrack.version === 1 && /*#__PURE__*/_react["default"].createElement(_richEditor["default"], {
    className: "".concat(prefix, "__editor-preview"),
    placeholder: "",
    editable: false,
    showToolbar: false,
    initialState: communicationTrack.content
  })), communicationTrack.attachments && /*#__PURE__*/_react["default"].createElement("div", {
    className: "".concat(prefix, "__communication-attachments")
  }, /*#__PURE__*/_react["default"].createElement(_fileList["default"], {
    data: communicationTrack.attachments
  })), /*#__PURE__*/_react["default"].createElement(_style.CommunicationActionbar, {
    className: "communication__actionbar"
  }, /*#__PURE__*/_react["default"].createElement(_style.ActionbarList, null, /*#__PURE__*/_react["default"].createElement(_style.ActionbarItem, {
    onMouseDown: function onMouseDown(event) {
      praiseStatus != 2 && onCommunicationRecordChange(event, "reply", index);
    }
  }, (0, _getLocale.getLocale)("Mod_Reply")), /*#__PURE__*/_react["default"].createElement(_style.ActionbarItem, {
    onMouseDown: function onMouseDown(event) {
      praiseStatus != 2 && onCommunicationRecordChange(event, "praise", index);
    }
  }, communicationTrack.isPraise ? (0, _getLocale.getLocale)("Mod_Alreadyliked") : (0, _getLocale.getLocale)("Mod_Kudos")), communicationTrack.praiseTotal > 0 && /*#__PURE__*/_react["default"].createElement(_style.CommunicationPraiseTotal, {
    className: "communication__praise__total",
    onMouseDown: function onMouseDown(event) {
      onCommunicationRecordChange(event, "showPraiseRecord", index);
      event.stopPropagation();
      event.nativeEvent.stopImmediatePropagation();
    },
    onClick: function onClick(event) {
      event.stopPropagation();
      event.nativeEvent.stopImmediatePropagation();
    },
    "data-for": "praise-record",
    "data-tip": communicationTrack.praiseTotal ? (0, _getLocale.getLocale)("Tasks_Tab_MyS_Clickrecord") : ""
  }, communicationTrack.praiseTotal) // </ToolTip>
  , communicationTrack.isEdit && /*#__PURE__*/_react["default"].createElement(_ConfirmPop["default"], {
    align: confirmPopAlign,
    onSubmit: function onSubmit(event) {
      return onCommunicationRecordChange(event, "delete", index);
    }
  }, /*#__PURE__*/_react["default"].createElement(_style.ActionbarItem, null, (0, _getLocale.getLocale)("Mod_Delete")))))), /*#__PURE__*/_react["default"].createElement(_reactTooltip["default"], {
    id: "praise-record",
    className: "tt-react-tooltip",
    place: "top",
    type: "dark",
    effect: "solid"
  }));
};

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