import React__default, { useMemo, useState } from 'react';
import { u as useLocalization } from '../../LocalizationContext-426f3d58.js';
import { q as isUserMessage, B as isEditedMessage, r as getUIKitMessageType, s as getUIKitMessageTypes, L as getUIKitFileType, t as truncateString, d as isVoiceMessage, m as isThumbnailMessage, C as isSentMessage, p as isVideoMessage, o as isGifMessage } from '../../index-f83f0aac.js';
import { L as Label, a as LabelTypography, b as LabelColors } from '../../index-4105bc4d.js';
import ImageRenderer from '../../ui/ImageRenderer.js';
import Icon, { IconTypes, IconColors } from '../../ui/Icon.js';
import TextButton from '../../ui/TextButton.js';
import useSendbirdStateContext from '../../useSendbirdStateContext.js';
import EmojiReactions from '../../ui/EmojiReactions.js';
import { u as useThreadContext } from '../../ThreadProvider-7f67575f.js';
import { VoiceMessageItemBody } from '../../ui/VoiceMessageItemBody.js';
import { T as TextFragment } from '../../index-89c84c27.js';
import { t as tokenizeMessage } from '../../tokenize-eec42500.js';
import '../../stringSet-a62108b2.js';
import '../../index-90420b99.js';
import '../../_rollupPluginBabelHelpers-a69fd1ce.js';
import '../../utils/message/getOutgoingMessageState.js';
import 'prop-types';
import '../../color-e708f53d.js';
import '../../withSendbird.js';
import '../../ui/ReactionBadge.js';
import '../../ui/ReactionButton.js';
import '../../useLongPress-c0ba590c.js';
import '../../MediaQueryContext-b531adc9.js';
import '../../utils-4bf6e4e6.js';
import '../../ui/ContextMenu.js';
import 'react-dom';
import '../../ui/SortByRow.js';
import '../../uuid-2e8efc75.js';
import '../../ui/BottomSheet.js';
import '../../index-3e548496.js';
import '../../ui/UserListItem.js';
import '../../UserProfileContext-a59f0533.js';
import '../../ui/Avatar.js';
import '../../ui/MutedAvatarOverlay.js';
import '../../ui/Checkbox.js';
import '../../ui/UserProfile.js';
import '../../sendbirdSelectors.js';
import '../../topics-247fcf3a.js';
import '../../ui/Button.js';
import '../../ui/Tooltip.js';
import '../../ui/TooltipWrapper.js';
import '../../Message/context.js';
import '../../index-e7f4cbdf.js';
import '../context/types.js';
import '@sendbird/chat';
import '@sendbird/chat/groupChannel';
import '@sendbird/chat/message';
import '../../consts-e64103c6.js';
import '../../ui/ProgressBar.js';
import '../../VoicePlayer/useVoicePlayer.js';
import '../../index-52ba73b9.js';
import '../../VoiceRecorder/context.js';
import '../../ui/Modal.js';
import '../../ui/IconButton.js';
import '../../ui/PlaybackTime.js';
import '../../ui/Loader.js';
import '../../index.module-8bb7760e.js';
import '../../ui/MentionLabel.js';
import '../../ui/LinkLabel.js';

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
  } = useLocalization();
  const {
    currentChannel,
    emojiContainer,
    nicknamesMap,
    toggleReaction
  } = 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 = useMemo(() => {
    if (isMentionedMessage) {
      return tokenizeMessage({
        mentionedUsers: message === null || message === void 0 ? void 0 : message.mentionedUsers,
        messageText: message === null || message === void 0 ? void 0 : message.mentionedMessageTemplate
      });
    }
    return 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] = 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.createElement("div", {
    className: `sendbird-parent-message-info-item ${className}`
  }, isUserMessage(message) && /*#__PURE__*/React__default.createElement(Label, {
    className: "sendbird-parent-message-info-item__text-message",
    type: LabelTypography.BODY_1,
    color: LabelColors.ONBACKGROUND_1
  }, /*#__PURE__*/React__default.createElement(TextFragment, {
    tokens: tokens
  }), isEditedMessage(message) && /*#__PURE__*/React__default.createElement(Label, {
    className: "sendbird-parent-message-info-item__text-message edited",
    type: LabelTypography.BODY_1,
    color: LabelColors.ONBACKGROUND_2
  }, ` ${stringSet.MESSAGE_EDITED} `)), getUIKitMessageType(message) === getUIKitMessageTypes().FILE && /*#__PURE__*/React__default.createElement("div", {
    className: "sendbird-parent-message-info-item__file-message"
  }, /*#__PURE__*/React__default.createElement("div", {
    className: "sendbird-parent-message-info-item__file-message__file-icon"
  }, /*#__PURE__*/React__default.createElement(Icon, {
    className: "sendbird-parent-message-info-item__file-message__file-icon__icon",
    type: {
      IMAGE: IconTypes.PHOTO,
      VIDEO: IconTypes.PLAY,
      AUDIO: IconTypes.FILE_AUDIO,
      GIF: IconTypes.GIF,
      OTHERS: IconTypes.FILE_DOCUMENT
    }[getUIKitFileType(message === null || message === void 0 ? void 0 : message.type)],
    fillColor: IconColors.PRIMARY,
    width: "24px",
    height: "24px"
  })), /*#__PURE__*/React__default.createElement(TextButton, {
    className: "sendbird-parent-message-info-item__file-message__file-name",
    onClick: () => {
      window.open(message === null || message === void 0 ? void 0 : message.url);
    },
    color: LabelColors.ONBACKGROUND_1
  }, /*#__PURE__*/React__default.createElement(Label, {
    className: "sendbird-parent-message-info-item__file-message__file-name__text",
    type: LabelTypography.BODY_1,
    color: LabelColors.ONBACKGROUND_1
  }, truncateString((message === null || message === void 0 ? void 0 : message.name) || (message === null || message === void 0 ? void 0 : message.url), 30)))), isVoiceMessage(message) && /*#__PURE__*/React__default.createElement("div", {
    className: "sendbird-parent-message-info-item__voice-message"
  }, /*#__PURE__*/React__default.createElement(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
  })), isThumbnailMessage(message) && /*#__PURE__*/React__default.createElement("div", {
    className: "sendbird-parent-message-info-item__thumbnail-message",
    onClick: () => {
      if (isSentMessage(message)) {
        showFileViewer(true);
      }
    }
  }, /*#__PURE__*/React__default.createElement(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.createElement("div", {
      className: "sendbird-parent-message-info-item__thumbnail-message__placeholder",
      style: style_
    }, /*#__PURE__*/React__default.createElement("div", {
      className: "sendbird-parent-message-info-item__thumbnail-message__placeholder__icon"
    }, /*#__PURE__*/React__default.createElement(Icon, {
      type: isVideoMessage(message) ? IconTypes.PLAY : IconTypes.PHOTO,
      fillColor: IconColors.ON_BACKGROUND_2,
      width: "34px",
      height: "34px"
    })))
  }), isVideoMessage(message) && !thumbnailUrl && !isImageRendered && /*#__PURE__*/React__default.createElement("video", {
    className: "sendbird-parent-message-info-item__thumbnail-message__video"
  }, /*#__PURE__*/React__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.createElement("div", {
    className: "sendbird-parent-message-info-item__thumbnail-message__image-cover"
  }), (isVideoMessage(message) || isGifMessage(message)) && /*#__PURE__*/React__default.createElement("div", {
    className: "sendbird-parent-message-info-item__thumbnail-message__icon-wrapper"
  }, /*#__PURE__*/React__default.createElement("div", {
    className: "sendbird-parent-message-info-item__thumbnail-message__icon-wrapper__icon"
  }, /*#__PURE__*/React__default.createElement(Icon, {
    type: isVideoMessage(message) ? IconTypes.PLAY : IconTypes.GIF,
    fillColor: IconColors.GRAY,
    width: "34px",
    height: "34px"
  })))), getUIKitMessageType(message) === (getUIKitMessageTypes === null || getUIKitMessageTypes === void 0 ? void 0 : (_getUIKitMessageTypes = getUIKitMessageTypes()) === null || _getUIKitMessageTypes === void 0 ? void 0 : _getUIKitMessageTypes.UNKNOWN) && /*#__PURE__*/React__default.createElement("div", {
    className: "sendbird-parent-message-info-item__unknown-message"
  }, /*#__PURE__*/React__default.createElement(Label, {
    className: "sendbird-parent-message-info-item__unknown-message__header",
    type: LabelTypography.BODY_1,
    color: LabelColors.ONBACKGROUND_1
  }, stringSet.UNKNOWN__UNKNOWN_MESSAGE_TYPE), /*#__PURE__*/React__default.createElement(Label, {
    className: "sendbird-parent-message-info-item__unknown-message__description",
    type: LabelTypography.BODY_1,
    color: LabelColors.ONBACKGROUND_2
  }, stringSet.UNKNOWN__CANNOT_READ_MESSAGE)), isReactionActivated && /*#__PURE__*/React__default.createElement("div", {
    className: "sendbird-parent-message-info__reactions"
  }, /*#__PURE__*/React__default.createElement(EmojiReactions, {
    userId: currentUserId,
    message: message,
    channel: currentChannel,
    isByMe: false,
    emojiContainer: emojiContainer,
    memberNicknamesMap: nicknamesMap,
    toggleReaction: toggleReaction
  })));
}

export { ParentMessageInfoItem as default };
//# sourceMappingURL=ParentMessageInfoItem.js.map
