'use strict';

var React = require('react');
var LocalizationContext = require('../../LocalizationContext-8cc9717d.js');
var index = require('../../index-a91b85d9.js');
var ui_Label = require('../../index-35633fb6.js');
var ui_ImageRenderer = require('../../ui/ImageRenderer.js');
var ui_Icon = require('../../ui/Icon.js');
var ui_TextButton = require('../../ui/TextButton.js');
var useSendbirdStateContext = require('../../useSendbirdStateContext.js');
var ui_EmojiReactions = require('../../ui/EmojiReactions.js');
var Thread_context = require('../../ThreadProvider-c83249cf.js');
var ui_VoiceMessageItemBody = require('../../ui/VoiceMessageItemBody.js');
var index$1 = require('../../index-db8116c0.js');
var tokenize = require('../../tokenize-88b021e0.js');
require('../../stringSet-ce782136.js');
require('../../index-d749c4c2.js');
require('../../_rollupPluginBabelHelpers-acf412a3.js');
require('../../utils/message/getOutgoingMessageState.js');
require('prop-types');
require('../../color-5cfb41c7.js');
require('../../withSendbird.js');
require('../../ui/ReactionBadge.js');
require('../../ui/ReactionButton.js');
require('../../useLongPress-cf56e64a.js');
require('../../MediaQueryContext-fad211ad.js');
require('../../utils-5aa0708e.js');
require('../../ui/ContextMenu.js');
require('react-dom');
require('../../ui/SortByRow.js');
require('../../uuid-1eceb0c8.js');
require('../../ui/BottomSheet.js');
require('../../index-8029e07a.js');
require('../../ui/UserListItem.js');
require('../../UserProfileContext-d993c96b.js');
require('../../ui/Avatar.js');
require('../../ui/MutedAvatarOverlay.js');
require('../../ui/Checkbox.js');
require('../../ui/UserProfile.js');
require('../../sendbirdSelectors.js');
require('../../topics-e24ef339.js');
require('../../ui/Button.js');
require('../../ui/Tooltip.js');
require('../../ui/TooltipWrapper.js');
require('../../Message/context.js');
require('../../index-3fc4f7d7.js');
require('../context/types.js');
require('@sendbird/chat');
require('@sendbird/chat/groupChannel');
require('@sendbird/chat/message');
require('../../consts-9641990e.js');
require('../../ui/ProgressBar.js');
require('../../VoicePlayer/useVoicePlayer.js');
require('../../index-90711a57.js');
require('../../VoiceRecorder/context.js');
require('../../ui/Modal.js');
require('../../ui/IconButton.js');
require('../../ui/PlaybackTime.js');
require('../../ui/Loader.js');
require('../../index.module-e3392caa.js');
require('../../ui/MentionLabel.js');
require('../../ui/LinkLabel.js');

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

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

function ParentMessageInfoItem(_ref) {
  var _stores$userStore, _stores$userStore$use, _message$mentionedMes, _message$mentionedUse, _message$reactions, _thumbnails, _thumbnails$, _getUIKitMessageTypes;
  let {
    className,
    message,
    showFileViewer
  } = _ref;
  const {
    stores,
    config
  } = useSendbirdStateContext();
  const {
    replyType,
    isMentionEnabled,
    isReactionEnabled
  } = config;
  const currentUserId = stores === null || stores === void 0 ? void 0 : (_stores$userStore = stores.userStore) === null || _stores$userStore === void 0 ? void 0 : (_stores$userStore$use = _stores$userStore.user) === null || _stores$userStore$use === void 0 ? void 0 : _stores$userStore$use.userId;
  const {
    stringSet
  } = LocalizationContext.useLocalization();
  const {
    currentChannel,
    emojiContainer,
    nicknamesMap,
    toggleReaction
  } = Thread_context.useThreadContext();
  const isMentionedMessage = 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;

  // Emoji reactions
  const isReactionActivated = isReactionEnabled && replyType === 'THREAD' && !(currentChannel !== null && currentChannel !== void 0 && currentChannel.isSuper) && !(currentChannel !== null && currentChannel !== void 0 && currentChannel.isBroadcast) && (message === null || message === void 0 ? void 0 : (_message$reactions = message.reactions) === null || _message$reactions === void 0 ? void 0 : _message$reactions.length) > 0;
  const tokens = React.useMemo(() => {
    if (isMentionedMessage) {
      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]);

  // Thumbnail mesage
  const [isImageRendered, setImageRendered] = React.useState(false);
  const thumbnailUrl = (message === null || message === void 0 ? void 0 : (_thumbnails = message.thumbnails) === null || _thumbnails === void 0 ? void 0 : _thumbnails.length) > 0 ? message === null || message === void 0 ? void 0 : (_thumbnails$ = message.thumbnails[0]) === null || _thumbnails$ === void 0 ? void 0 : _thumbnails$.url : '';
  return /*#__PURE__*/React__default["default"].createElement("div", {
    className: `sendbird-parent-message-info-item ${className}`
  }, index.isUserMessage(message) && /*#__PURE__*/React__default["default"].createElement(ui_Label.Label, {
    className: "sendbird-parent-message-info-item__text-message",
    type: ui_Label.LabelTypography.BODY_1,
    color: ui_Label.LabelColors.ONBACKGROUND_1
  }, /*#__PURE__*/React__default["default"].createElement(index$1.TextFragment, {
    tokens: tokens
  }), index.isEditedMessage(message) && /*#__PURE__*/React__default["default"].createElement(ui_Label.Label, {
    className: "sendbird-parent-message-info-item__text-message edited",
    type: ui_Label.LabelTypography.BODY_1,
    color: ui_Label.LabelColors.ONBACKGROUND_2
  }, ` ${stringSet.MESSAGE_EDITED} `)), index.getUIKitMessageType(message) === index.getUIKitMessageTypes().FILE && /*#__PURE__*/React__default["default"].createElement("div", {
    className: "sendbird-parent-message-info-item__file-message"
  }, /*#__PURE__*/React__default["default"].createElement("div", {
    className: "sendbird-parent-message-info-item__file-message__file-icon"
  }, /*#__PURE__*/React__default["default"].createElement(ui_Icon["default"], {
    className: "sendbird-parent-message-info-item__file-message__file-icon__icon",
    type: {
      IMAGE: ui_Icon.IconTypes.PHOTO,
      VIDEO: ui_Icon.IconTypes.PLAY,
      AUDIO: ui_Icon.IconTypes.FILE_AUDIO,
      GIF: ui_Icon.IconTypes.GIF,
      OTHERS: ui_Icon.IconTypes.FILE_DOCUMENT
    }[index.getUIKitFileType(message === null || message === void 0 ? void 0 : message.type)],
    fillColor: ui_Icon.IconColors.PRIMARY,
    width: "24px",
    height: "24px"
  })), /*#__PURE__*/React__default["default"].createElement(ui_TextButton, {
    className: "sendbird-parent-message-info-item__file-message__file-name",
    onClick: () => {
      window.open(message === null || message === void 0 ? void 0 : message.url);
    },
    color: ui_Label.LabelColors.ONBACKGROUND_1
  }, /*#__PURE__*/React__default["default"].createElement(ui_Label.Label, {
    className: "sendbird-parent-message-info-item__file-message__file-name__text",
    type: ui_Label.LabelTypography.BODY_1,
    color: ui_Label.LabelColors.ONBACKGROUND_1
  }, index.truncateString((message === null || message === void 0 ? void 0 : message.name) || (message === null || message === void 0 ? void 0 : message.url), 30)))), index.isVoiceMessage(message) && /*#__PURE__*/React__default["default"].createElement("div", {
    className: "sendbird-parent-message-info-item__voice-message"
  }, /*#__PURE__*/React__default["default"].createElement(ui_VoiceMessageItemBody.VoiceMessageItemBody, {
    className: "sendbird-parent-message-info-item__voice-message__item",
    message: message,
    channelUrl: currentChannel === null || currentChannel === void 0 ? void 0 : currentChannel.url,
    isByMe: false,
    isReactionEnabled: isReactionEnabled
  })), index.isThumbnailMessage(message) && /*#__PURE__*/React__default["default"].createElement("div", {
    className: "sendbird-parent-message-info-item__thumbnail-message",
    onClick: () => {
      if (index.isSentMessage(message)) {
        showFileViewer(true);
      }
    }
  }, /*#__PURE__*/React__default["default"].createElement(ui_ImageRenderer, {
    className: "sendbird-parent-message-info-item__thumbnail-message__thumbnail",
    url: thumbnailUrl || (message === null || message === void 0 ? void 0 : message.url) || (message === null || message === void 0 ? void 0 : message.plainUrl),
    alt: message === null || message === void 0 ? void 0 : message.type,
    width: "200px",
    height: "148px",
    onLoad: () => {
      setImageRendered(true);
    },
    placeHolder: style_ => /*#__PURE__*/React__default["default"].createElement("div", {
      className: "sendbird-parent-message-info-item__thumbnail-message__placeholder",
      style: style_
    }, /*#__PURE__*/React__default["default"].createElement("div", {
      className: "sendbird-parent-message-info-item__thumbnail-message__placeholder__icon"
    }, /*#__PURE__*/React__default["default"].createElement(ui_Icon["default"], {
      type: index.isVideoMessage(message) ? ui_Icon.IconTypes.PLAY : ui_Icon.IconTypes.PHOTO,
      fillColor: ui_Icon.IconColors.ON_BACKGROUND_2,
      width: "34px",
      height: "34px"
    })))
  }), index.isVideoMessage(message) && !thumbnailUrl && !isImageRendered && /*#__PURE__*/React__default["default"].createElement("video", {
    className: "sendbird-parent-message-info-item__thumbnail-message__video"
  }, /*#__PURE__*/React__default["default"].createElement("source", {
    src: (message === null || message === void 0 ? void 0 : message.url) || (message === null || message === void 0 ? void 0 : message.plainUrl),
    type: message === null || message === void 0 ? void 0 : message.type
  })), /*#__PURE__*/React__default["default"].createElement("div", {
    className: "sendbird-parent-message-info-item__thumbnail-message__image-cover"
  }), (index.isVideoMessage(message) || index.isGifMessage(message)) && /*#__PURE__*/React__default["default"].createElement("div", {
    className: "sendbird-parent-message-info-item__thumbnail-message__icon-wrapper"
  }, /*#__PURE__*/React__default["default"].createElement("div", {
    className: "sendbird-parent-message-info-item__thumbnail-message__icon-wrapper__icon"
  }, /*#__PURE__*/React__default["default"].createElement(ui_Icon["default"], {
    type: index.isVideoMessage(message) ? ui_Icon.IconTypes.PLAY : ui_Icon.IconTypes.GIF,
    fillColor: ui_Icon.IconColors.GRAY,
    width: "34px",
    height: "34px"
  })))), index.getUIKitMessageType(message) === (index.getUIKitMessageTypes === null || index.getUIKitMessageTypes === void 0 ? void 0 : (_getUIKitMessageTypes = index.getUIKitMessageTypes()) === null || _getUIKitMessageTypes === void 0 ? void 0 : _getUIKitMessageTypes.UNKNOWN) && /*#__PURE__*/React__default["default"].createElement("div", {
    className: "sendbird-parent-message-info-item__unknown-message"
  }, /*#__PURE__*/React__default["default"].createElement(ui_Label.Label, {
    className: "sendbird-parent-message-info-item__unknown-message__header",
    type: ui_Label.LabelTypography.BODY_1,
    color: ui_Label.LabelColors.ONBACKGROUND_1
  }, stringSet.UNKNOWN__UNKNOWN_MESSAGE_TYPE), /*#__PURE__*/React__default["default"].createElement(ui_Label.Label, {
    className: "sendbird-parent-message-info-item__unknown-message__description",
    type: ui_Label.LabelTypography.BODY_1,
    color: ui_Label.LabelColors.ONBACKGROUND_2
  }, stringSet.UNKNOWN__CANNOT_READ_MESSAGE)), isReactionActivated && /*#__PURE__*/React__default["default"].createElement("div", {
    className: "sendbird-parent-message-info__reactions"
  }, /*#__PURE__*/React__default["default"].createElement(ui_EmojiReactions, {
    userId: currentUserId,
    message: message,
    channel: currentChannel,
    isByMe: false,
    emojiContainer: emojiContainer,
    memberNicknamesMap: nicknamesMap,
    toggleReaction: toggleReaction
  })));
}

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