'use strict';

var React = require('react');
var ui_Label = require('../index-2bfd366f.js');
var index = require('../index-1b3c69da.js');
var LocalizationContext = require('../LocalizationContext-44d2f61b.js');
var tokenize = require('../tokenize-44139f1e.js');
var index$1 = require('../index-8cd9b25d.js');
var consts = require('../consts-b93ef9ea.js');
require('prop-types');
require('../stringSet-7aebf034.js');
require('../_rollupPluginBabelHelpers-21ae158b.js');
require('../utils/message/getOutgoingMessageState.js');
require('../index-88e8fdfa.js');
require('../index.module-5a6a79b6.js');
require('../Message/context.js');
require('./MentionLabel.js');
require('./ContextMenu.js');
require('react-dom');
require('./SortByRow.js');
require('../uuid-dee74248.js');
require('./UserProfile.js');
require('../UserProfileContext-9d843d68.js');
require('../sendbirdSelectors.js');
require('../topics-373d2156.js');
require('../utils-6a748c02.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
