'use strict';

var React = require('react');
var ui_Label = require('../index-72e412f7.js');
var index = require('../index-0b8a1074.js');
var LocalizationContext = require('../LocalizationContext-b42fa07d.js');
var tokenize = require('../tokenize-e944d548.js');
var index$1 = require('../index-1c18afa8.js');
var consts = require('../consts-ad8ba629.js');
require('prop-types');
require('../stringSet-4f30313f.js');
require('../_rollupPluginBabelHelpers-3a9d1641.js');
require('../utils/message/getOutgoingMessageState.js');
require('../index-97005534.js');
require('../index.module-d2876b1c.js');
require('../Message/context.js');
require('./MentionLabel.js');
require('./ContextMenu.js');
require('react-dom');
require('./SortByRow.js');
require('../uuid-5ab4f88b.js');
require('./UserProfile.js');
require('../UserProfileContext-c87514d3.js');
require('../sendbirdSelectors.js');
require('../topics-3226c6ee.js');
require('../utils-146517a9.js');
require('./Avatar.js');
require('./ImageRenderer.js');
require('./Icon.js');
require('./Button.js');
require('../useSendbirdStateContext.js');
require('../withSendbird.js');
require('./LinkLabel.js');

function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }

var React__default = /*#__PURE__*/_interopDefaultLegacy(React);

function TextMessageItemBody(_ref) {
  var _message$mentionedMes, _message$mentionedUse, _message$reactions;
  let {
    className = '',
    message,
    isByMe = false,
    mouseHover = false,
    isMentionEnabled = false,
    isReactionEnabled = false
  } = _ref;
  const {
    stringSet
  } = React.useContext(LocalizationContext.LocalizationContext);
  const isMessageMentioned = isMentionEnabled && (message === null || message === void 0 ? void 0 : (_message$mentionedMes = message.mentionedMessageTemplate) === null || _message$mentionedMes === void 0 ? void 0 : _message$mentionedMes.length) > 0 && (message === null || message === void 0 ? void 0 : (_message$mentionedUse = message.mentionedUsers) === null || _message$mentionedUse === void 0 ? void 0 : _message$mentionedUse.length) > 0;
  const tokens = React.useMemo(() => {
    if (isMessageMentioned) {
      return tokenize.tokenizeMessage({
        mentionedUsers: message === null || message === void 0 ? void 0 : message.mentionedUsers,
        messageText: message === null || message === void 0 ? void 0 : message.mentionedMessageTemplate
      });
    }
    return tokenize.tokenizeMessage({
      messageText: message === null || message === void 0 ? void 0 : message.message
    });
  }, [message === null || message === void 0 ? void 0 : message.updatedAt]);
  return /*#__PURE__*/React__default["default"].createElement(ui_Label.Label, {
    type: ui_Label.LabelTypography.BODY_1,
    color: isByMe ? ui_Label.LabelColors.ONCONTENT_1 : ui_Label.LabelColors.ONBACKGROUND_1
  }, /*#__PURE__*/React__default["default"].createElement("div", {
    className: index.getClassName([className, consts.TEXT_MESSAGE_BODY_CLASSNAME, isByMe ? 'outgoing' : 'incoming', mouseHover ? 'mouse-hover' : '', isReactionEnabled && (message === null || message === void 0 ? void 0 : (_message$reactions = message.reactions) === null || _message$reactions === void 0 ? void 0 : _message$reactions.length) > 0 ? 'reactions' : ''])
  }, /*#__PURE__*/React__default["default"].createElement(index$1.TextFragment, {
    tokens: tokens
  }), index.isEditedMessage(message) && /*#__PURE__*/React__default["default"].createElement(ui_Label.Label, {
    className: "sendbird-text-message-item-body__message edited",
    type: ui_Label.LabelTypography.BODY_1,
    color: isByMe ? ui_Label.LabelColors.ONCONTENT_2 : ui_Label.LabelColors.ONBACKGROUND_2
  }, ` ${stringSet.MESSAGE_EDITED} `)));
}

module.exports = TextMessageItemBody;
//# sourceMappingURL=TextMessageItemBody.js.map
