import { b as _extends, _ as _objectSpread2 } from '../_rollupPluginBabelHelpers-b2d9bfc5.js';
import React__default, { useState, useContext, useRef } from 'react';
import { f as format } from '../index-f48cfdf7.js';
import Avatar from './Avatar.js';
import UserProfile from './UserProfile.js';
import { M as MessageStatus } from '../index-51bd074f.js';
import MessageItemMenu from './MessageItemMenu.js';
import MessageItemReactionMenu from './MessageItemReactionMenu.js';
import ContextMenu, { MenuItems, MenuItem } from './ContextMenu.js';
import { L as Label, a as LabelTypography, b as LabelColors } from '../index-4111594a.js';
import EmojiReactions from './EmojiReactions.js';
import AdminMessage from './AdminMessage.js';
import TextMessageItemBody from './TextMessageItemBody.js';
import FileMessageItemBody from './FileMessageItemBody.js';
import ThumbnailMessageItemBody from './ThumbnailMessageItemBody.js';
import OGMessageItemBody from './OGMessageItemBody.js';
import UnknownMessageItemBody from './UnknownMessageItemBody.js';
import QuoteMessage from './QuoteMessage.js';
import { r as isUserMessage, u as isSentMessage, v as isFailedMessage, w as isPendingMessage, l as isFileMessage, x as copyToClipboard, y as getEmojiListAll, z as getUIKitMessageTypes, j as getClassName, A as getSenderName, B as isTextMessage, C as isOGMessage, s as getUIKitMessageType, d as isVoiceMessage, n as isThumbnailMessage } from '../index-dbe0e004.js';
import { a as UserProfileContext } from '../UserProfileContext-a8aa4c0f.js';
import { u as useLocalization } from '../LocalizationContext-9c54e783.js';
import useSendbirdStateContext from '../useSendbirdStateContext.js';
import { u as useLongPress } from '../useLongPress-8acf717c.js';
import Icon, { IconTypes, IconColors } from './Icon.js';
import BottomSheet from './BottomSheet.js';
import ImageRenderer from './ImageRenderer.js';
import ReactionButton from './ReactionButton.js';
import { u as useMediaQueryContext } from '../MediaQueryContext-1988a4bc.js';
import ThreadReplies from './ThreadReplies.js';
import { T as ThreadReplySelectType } from '../const-5f722b91.js';
import { VoiceMessageItemBody } from './VoiceMessageItemBody.js';
import '../index-a9ddd0f5.js';
import '../uuid-48baadaf.js';
import 'prop-types';
import '../sendbirdSelectors.js';
import '../topics-d8d10f83.js';
import '../utils-0c09801e.js';
import './Button.js';
import '../stringSet-1f18348a.js';
import './Loader.js';
import '../utils/message/getOutgoingMessageState.js';
import '../index-3062a861.js';
import '../index-1a3c0d72.js';
import './IconButton.js';
import '../types-a85de720.js';
import 'react-dom';
import './SortByRow.js';
import './Tooltip.js';
import './TooltipWrapper.js';
import './ReactionBadge.js';
import '../tokenize-63d895d3.js';
import '../index-8df6bff0.js';
import '../index.module-ab8289c1.js';
import '../Message/context.js';
import './MentionLabel.js';
import './LinkLabel.js';
import '../consts-aadaccca.js';
import './TextButton.js';
import '../color-3bac434a.js';
import '../consts-790ae3a9.js';
import '../withSendbird.js';
import '../index-2a938266.js';
import './ProgressBar.js';
import '../VoicePlayer/useVoicePlayer.js';
import '../index-38a78d99.js';
import '../consts-c9746f2b.js';
import '../VoiceRecorder/context.js';
import './PlaybackTime.js';

const MobileContextMenu = props => {
  var _message$sender;
  const {
    hideMenu,
    channel,
    message,
    replyType,
    userId,
    resendMessage,
    showEdit,
    showRemove,
    setQuoteMessage,
    parentRef
  } = props;
  const isByMe = (message === null || message === void 0 ? void 0 : (_message$sender = message.sender) === null || _message$sender === void 0 ? void 0 : _message$sender.userId) === userId;
  const {
    stringSet
  } = useLocalization();
  const showMenuItemCopy = isUserMessage(message);
  const showMenuItemEdit = isUserMessage(message) && isSentMessage(message) && isByMe;
  const showMenuItemResend = isFailedMessage(message) && (message === null || message === void 0 ? void 0 : message.isResendable) && isByMe;
  const showMenuItemDelete = !isPendingMessage(message) && isByMe;
  const showMenuItemDownload = !isPendingMessage(message) && isFileMessage(message);
  const showMenuItemReply = replyType === 'QUOTE_REPLY' && !isFailedMessage(message) && !isPendingMessage(message) && (channel === null || channel === void 0 ? void 0 : channel.isGroupChannel()) && !(channel !== null && channel !== void 0 && channel.isBroadcast);
  const fileMessage = message;
  return /*#__PURE__*/React__default.createElement(ContextMenu, {
    isOpen: true,
    menuItems: () => {
      var _message$threadInfo;
      return /*#__PURE__*/React__default.createElement(MenuItems, {
        className: "sendbird-message__mobile-context-menu",
        parentRef: parentRef,
        parentContainRef: parentRef,
        closeDropdown: hideMenu
      }, showMenuItemCopy && /*#__PURE__*/React__default.createElement(MenuItem, {
        className: "sendbird-message__mobile-context-menu-item menu-item-copy",
        onClick: () => {
          hideMenu();
          copyToClipboard(message === null || message === void 0 ? void 0 : message.message);
        }
      }, /*#__PURE__*/React__default.createElement(Label, {
        type: LabelTypography.SUBTITLE_1
      }, stringSet === null || stringSet === void 0 ? void 0 : stringSet.MESSAGE_MENU__COPY), /*#__PURE__*/React__default.createElement(Icon, {
        type: IconTypes.COPY,
        fillColor: IconColors.PRIMARY,
        width: "24px",
        height: "24px"
      })), showMenuItemReply && /*#__PURE__*/React__default.createElement(MenuItem, {
        className: "sendbird-message__mobile-context-menu-item menu-item-reply",
        onClick: () => {
          hideMenu();
          setQuoteMessage(message);
        },
        disable: (message === null || message === void 0 ? void 0 : message.parentMessageId) > 0
      }, /*#__PURE__*/React__default.createElement(Label, {
        type: LabelTypography.SUBTITLE_1
      }, stringSet.MESSAGE_MENU__REPLY), /*#__PURE__*/React__default.createElement(Icon, {
        type: IconTypes.REPLY,
        fillColor: IconColors.PRIMARY,
        width: "24px",
        height: "24px"
      })), showMenuItemEdit && /*#__PURE__*/React__default.createElement(MenuItem, {
        className: "sendbird-message__mobile-context-menu-item menu-item-edit",
        onClick: () => {
          hideMenu();
          showEdit(true);
        }
      }, /*#__PURE__*/React__default.createElement(Label, {
        type: LabelTypography.SUBTITLE_1
      }, stringSet.MESSAGE_MENU__EDIT), /*#__PURE__*/React__default.createElement(Icon, {
        type: IconTypes.EDIT,
        fillColor: IconColors.PRIMARY,
        width: "24px",
        height: "24px"
      })), showMenuItemResend && /*#__PURE__*/React__default.createElement(MenuItem, {
        className: "sendbird-message__mobile-context-menu-item menu-item-resend",
        onClick: () => {
          hideMenu();
          resendMessage(message);
        }
      }, /*#__PURE__*/React__default.createElement(Label, {
        type: LabelTypography.SUBTITLE_1
      }, stringSet.MESSAGE_MENU__RESEND), /*#__PURE__*/React__default.createElement(Icon, {
        type: IconTypes.REFRESH,
        fillColor: IconColors.PRIMARY,
        width: "24px",
        height: "24px"
      })), showMenuItemDelete && /*#__PURE__*/React__default.createElement(MenuItem, {
        className: "sendbird-message__mobile-context-menu-item menu-item-delete",
        onClick: () => {
          hideMenu();
          showRemove(true);
        },
        disable: (message === null || message === void 0 ? void 0 : (_message$threadInfo = message.threadInfo) === null || _message$threadInfo === void 0 ? void 0 : _message$threadInfo.replyCount) > 0
      }, /*#__PURE__*/React__default.createElement(Label, {
        type: LabelTypography.SUBTITLE_1
      }, stringSet.MESSAGE_MENU__DELETE), /*#__PURE__*/React__default.createElement(Icon, {
        type: IconTypes.DELETE,
        fillColor: IconColors.PRIMARY,
        width: "24px",
        height: "24px"
      })), showMenuItemDownload && /*#__PURE__*/React__default.createElement(MenuItem, {
        className: "sendbird-message__mobile-context-menu-item menu-item-save",
        onClick: () => {
          hideMenu();
        }
      }, /*#__PURE__*/React__default.createElement("a", {
        className: "sendbird-message__contextmenu--hyperlink",
        rel: "noopener noreferrer",
        href: fileMessage === null || fileMessage === void 0 ? void 0 : fileMessage.url,
        target: "_blank"
      }, /*#__PURE__*/React__default.createElement(Label, {
        type: LabelTypography.SUBTITLE_1
      }, stringSet.MESSAGE_MENU__SAVE), /*#__PURE__*/React__default.createElement(Icon, {
        type: IconTypes.DOWNLOAD,
        fillColor: IconColors.PRIMARY,
        width: "24px",
        height: "24px"
      }))));
    }
  });
};

const EMOJI_SIZE = 38;
const MobileBottomSheet = props => {
  var _message$sender, _window;
  const {
    hideMenu,
    channel,
    emojiContainer,
    message,
    replyType,
    userId,
    resendMessage,
    toggleReaction,
    isReactionEnabled,
    showEdit,
    showRemove,
    setQuoteMessage
  } = props;
  const isByMe = (message === null || message === void 0 ? void 0 : (_message$sender = message.sender) === null || _message$sender === void 0 ? void 0 : _message$sender.userId) === userId;
  const {
    stringSet
  } = useLocalization();
  const showMenuItemCopy = isUserMessage(message);
  const showMenuItemEdit = isUserMessage(message) && isSentMessage(message) && isByMe;
  const showMenuItemResend = isFailedMessage(message) && (message === null || message === void 0 ? void 0 : message.isResendable) && isByMe;
  const showMenuItemDelete = !isPendingMessage(message) && isByMe;
  const showMenuItemDownload = !isPendingMessage(message) && isFileMessage(message);
  const showReaction = !isFailedMessage(message) && !isPendingMessage(message) && isReactionEnabled;
  const showMenuItemReply = replyType === 'QUOTE_REPLY' && !isFailedMessage(message) && !isPendingMessage(message) && (channel === null || channel === void 0 ? void 0 : channel.isGroupChannel()) && !(channel !== null && channel !== void 0 && channel.isBroadcast);
  const disableReaction = (message === null || message === void 0 ? void 0 : message.parentMessageId) > 0;
  const fileMessage = message;
  const maxEmojisPerRow = Math.floor(((_window = window) === null || _window === void 0 ? void 0 : _window.innerWidth) / EMOJI_SIZE) - 1;
  const [showEmojisOnly, setShowEmojisOnly] = useState(false);
  const emojis = getEmojiListAll(emojiContainer);
  // calculate max emojis that can be shown in screen
  const visibleEmojis = showEmojisOnly ? emojis : emojis === null || emojis === void 0 ? void 0 : emojis.slice(0, maxEmojisPerRow);
  const canShowMoreEmojis = emojis.length > maxEmojisPerRow;
  return /*#__PURE__*/React__default.createElement(BottomSheet, {
    onBackdropClick: hideMenu
  }, /*#__PURE__*/React__default.createElement("div", {
    className: "sendbird-message__bottomsheet"
  }, showReaction && /*#__PURE__*/React__default.createElement("div", {
    className: "sendbird-message__bottomsheet-reactions"
  }, /*#__PURE__*/React__default.createElement("ul", {
    className: "sendbird-message__bottomsheet-reaction-bar"
  }, /*#__PURE__*/React__default.createElement("div", {
    className: `
                    sendbird-message__bottomsheet-reaction-bar__row
                    ${showEmojisOnly ? 'sendbird-message__bottomsheet-reaction-bar__all' : ''}
                  `
  }, visibleEmojis.map(emoji => {
    var _message$reactions, _message$reactions$fi, _message$reactions$fi2;
    const isReacted = message === null || message === void 0 ? void 0 : (_message$reactions = message.reactions) === null || _message$reactions === void 0 ? void 0 : (_message$reactions$fi = _message$reactions.filter(reaction => reaction.key === emoji.key)[0]) === null || _message$reactions$fi === void 0 ? void 0 : (_message$reactions$fi2 = _message$reactions$fi.userIds) === null || _message$reactions$fi2 === void 0 ? void 0 : _message$reactions$fi2.some(reactorId => reactorId === userId);
    return /*#__PURE__*/React__default.createElement(ReactionButton, {
      key: emoji.key,
      width: `${EMOJI_SIZE}px`,
      height: `${EMOJI_SIZE}px`,
      selected: isReacted,
      onClick: () => {
        hideMenu();
        toggleReaction(message, emoji.key, isReacted);
      }
    }, /*#__PURE__*/React__default.createElement(ImageRenderer, {
      url: (emoji === null || emoji === void 0 ? void 0 : emoji.url) || '',
      width: "28px",
      height: "28px",
      placeHolder: style => /*#__PURE__*/React__default.createElement("div", {
        style: style
      }, /*#__PURE__*/React__default.createElement(Icon, {
        type: IconTypes.QUESTION,
        fillColor: IconColors.ON_BACKGROUND_3,
        width: "28px",
        height: "28px"
      }))
    }));
  }), canShowMoreEmojis && !showEmojisOnly && /*#__PURE__*/React__default.createElement(ReactionButton, {
    key: "emoji_more",
    width: "38px",
    height: "38px",
    onClick: () => {
      setShowEmojisOnly(true);
    }
  }, /*#__PURE__*/React__default.createElement(ImageRenderer, {
    url: '',
    width: "28px",
    height: "28px",
    placeHolder: style => /*#__PURE__*/React__default.createElement("div", {
      style: style
    }, /*#__PURE__*/React__default.createElement(Icon, {
      type: IconTypes.EMOJI_MORE,
      fillColor: IconColors.ON_BACKGROUND_3,
      width: "28px",
      height: "28px"
    }))
  }))))), !showEmojisOnly && /*#__PURE__*/React__default.createElement("div", {
    className: "sendbird-message__bottomsheet--actions"
  }, showMenuItemCopy && /*#__PURE__*/React__default.createElement("div", {
    className: "sendbird-message__bottomsheet--action",
    onClick: () => {
      hideMenu();
      copyToClipboard(message === null || message === void 0 ? void 0 : message.message);
    }
  }, /*#__PURE__*/React__default.createElement(Icon, {
    type: IconTypes.COPY,
    fillColor: IconColors.PRIMARY,
    width: "24px",
    height: "24px"
  }), /*#__PURE__*/React__default.createElement(Label, {
    type: LabelTypography.SUBTITLE_1
  }, stringSet === null || stringSet === void 0 ? void 0 : stringSet.MESSAGE_MENU__COPY)), showMenuItemEdit && /*#__PURE__*/React__default.createElement("div", {
    className: "sendbird-message__bottomsheet--action",
    onClick: () => {
      hideMenu();
      showEdit(true);
    }
  }, /*#__PURE__*/React__default.createElement(Icon, {
    type: IconTypes.EDIT,
    fillColor: IconColors.PRIMARY,
    width: "24px",
    height: "24px"
  }), /*#__PURE__*/React__default.createElement(Label, {
    type: LabelTypography.SUBTITLE_1
  }, stringSet === null || stringSet === void 0 ? void 0 : stringSet.MESSAGE_MENU__EDIT)), showMenuItemResend && /*#__PURE__*/React__default.createElement("div", {
    className: "sendbird-message__bottomsheet--action",
    onClick: () => {
      hideMenu();
      resendMessage(message);
    }
  }, /*#__PURE__*/React__default.createElement(Icon, {
    type: IconTypes.REFRESH,
    fillColor: IconColors.PRIMARY,
    width: "24px",
    height: "24px"
  }), /*#__PURE__*/React__default.createElement(Label, {
    type: LabelTypography.SUBTITLE_1
  }, stringSet === null || stringSet === void 0 ? void 0 : stringSet.MESSAGE_MENU__RESEND)), showMenuItemReply && /*#__PURE__*/React__default.createElement("div", {
    className: `sendbird-message__bottomsheet--action
                      ${disableReaction ? 'sendbird-message__bottomsheet--action-disabled' : ''}
                    `,
    role: "menuitem",
    "aria-disabled": disableReaction ? true : false,
    onClick: () => {
      if (!disableReaction) {
        hideMenu();
        setQuoteMessage(message);
      }
    }
  }, /*#__PURE__*/React__default.createElement(Icon, {
    type: IconTypes.REPLY,
    fillColor: disableReaction ? IconColors.ON_BACKGROUND_3 : IconColors.PRIMARY,
    width: "24px",
    height: "24px"
  }), /*#__PURE__*/React__default.createElement(Label, {
    type: LabelTypography.SUBTITLE_1,
    color: disableReaction && LabelColors.ONBACKGROUND_4
  }, stringSet === null || stringSet === void 0 ? void 0 : stringSet.MESSAGE_MENU__REPLY)), showMenuItemDelete && /*#__PURE__*/React__default.createElement("div", {
    className: "sendbird-message__bottomsheet--action",
    onClick: () => {
      hideMenu();
      showRemove(true);
    }
  }, /*#__PURE__*/React__default.createElement(Icon, {
    type: IconTypes.DELETE,
    fillColor: IconColors.PRIMARY,
    width: "24px",
    height: "24px"
  }), /*#__PURE__*/React__default.createElement(Label, {
    type: LabelTypography.SUBTITLE_1
  }, stringSet === null || stringSet === void 0 ? void 0 : stringSet.MESSAGE_MENU__DELETE)), showMenuItemDownload && /*#__PURE__*/React__default.createElement("div", {
    className: "sendbird-message__bottomsheet--action",
    onClick: () => {
      hideMenu();
    }
  }, /*#__PURE__*/React__default.createElement("a", {
    className: "sendbird-message__bottomsheet--hyperlink",
    rel: "noopener noreferrer",
    href: fileMessage === null || fileMessage === void 0 ? void 0 : fileMessage.url,
    target: "_blank"
  }, /*#__PURE__*/React__default.createElement(Icon, {
    type: IconTypes.DOWNLOAD,
    fillColor: IconColors.PRIMARY,
    width: "24px",
    height: "24px"
  }), /*#__PURE__*/React__default.createElement(Label, {
    type: LabelTypography.SUBTITLE_1
  }, stringSet === null || stringSet === void 0 ? void 0 : stringSet.MESSAGE_MENU__SAVE))))));
};

const MobileMenu = props => {
  const {
    message,
    hideMenu,
    userId,
    channel,
    isReactionEnabled = false,
    isByMe,
    replyType,
    disabled,
    showRemove,
    showEdit,
    resendMessage,
    setQuoteMessage,
    emojiContainer,
    toggleReaction,
    parentRef
  } = props;
  return /*#__PURE__*/React__default.createElement(React__default.Fragment, null, isReactionEnabled ? /*#__PURE__*/React__default.createElement(MobileBottomSheet, {
    channel: channel,
    message: message,
    hideMenu: hideMenu,
    isByMe: isByMe,
    userId: userId,
    replyType: replyType,
    disabled: disabled,
    showRemove: showRemove,
    showEdit: showEdit,
    resendMessage: resendMessage,
    setQuoteMessage: setQuoteMessage,
    emojiContainer: emojiContainer,
    toggleReaction: toggleReaction,
    isReactionEnabled: isReactionEnabled
  }) : /*#__PURE__*/React__default.createElement(MobileContextMenu, {
    channel: channel,
    userId: userId,
    message: message,
    hideMenu: hideMenu,
    isByMe: isByMe,
    showEdit: showEdit,
    replyType: replyType,
    disabled: disabled,
    showRemove: showRemove,
    resendMessage: resendMessage,
    setQuoteMessage: setQuoteMessage,
    parentRef: parentRef
  }));
};

// should initialize in UserProfileContext.jsx

function MessageContent(_ref) {
  var _sender, _message$threadInfo, _message$isAdminMessa, _channel$members2, _channel$members2$fin, _message$parentMessag, _message$reactions, _message$isUserMessag, _message$isFileMessag;
  let {
    className,
    userId,
    channel,
    message,
    disabled = false,
    chainTop = false,
    chainBottom = false,
    isReactionEnabled = false,
    disableQuoteMessage = false,
    replyType,
    threadReplySelectType,
    nicknamesMap,
    emojiContainer,
    scrollToMessage,
    showEdit,
    showRemove,
    showFileViewer,
    resendMessage,
    toggleReaction,
    setQuoteMessage,
    onReplyInThread,
    onQuoteMessageClick,
    onMessageHeightChange
  } = _ref;
  const messageTypes = getUIKitMessageTypes();
  const {
    dateLocale
  } = useLocalization();
  const {
    config
  } = (useSendbirdStateContext === null || useSendbirdStateContext === void 0 ? void 0 : useSendbirdStateContext()) || {};
  const {
    disableUserProfile,
    renderUserProfile
  } = useContext(UserProfileContext);
  const avatarRef = useRef(null);
  const contentRef = useRef(null);
  const {
    isMobile
  } = useMediaQueryContext();
  const [showMenu, setShowMenu] = useState(false);
  const [mouseHover, setMouseHover] = useState(false);
  const [supposedHover, setSupposedHover] = useState(false);
  const isByMe = userId === (message === null || message === void 0 ? void 0 : (_sender = message.sender) === null || _sender === void 0 ? void 0 : _sender.userId) || (message === null || message === void 0 ? void 0 : message.sendingStatus) === 'pending' || (message === null || message === void 0 ? void 0 : message.sendingStatus) === 'failed';
  const isByMeClassName = isByMe ? 'outgoing' : 'incoming';
  const chainTopClassName = chainTop ? 'chain-top' : '';
  const isReactionEnabledInChannel = isReactionEnabled && !(channel !== null && channel !== void 0 && channel.isEphemeral);
  const isReactionEnabledClassName = isReactionEnabledInChannel ? 'use-reactions' : '';
  const supposedHoverClassName = supposedHover ? 'sendbird-mouse-hover' : '';
  const useReplying = !!((replyType === 'QUOTE_REPLY' || replyType === 'THREAD') && message !== null && message !== void 0 && message.parentMessageId && message !== null && message !== void 0 && message.parentMessage && !disableQuoteMessage);
  const useReplyingClassName = useReplying ? 'use-quote' : '';

  // Thread replies
  const displayThreadReplies = (message === null || message === void 0 ? void 0 : (_message$threadInfo = message.threadInfo) === null || _message$threadInfo === void 0 ? void 0 : _message$threadInfo.replyCount) > 0 && replyType === 'THREAD';

  // onMouseDown: (e: React.MouseEvent<T>) => void;
  // onTouchStart: (e: React.TouchEvent<T>) => void;
  // onMouseUp: (e: React.MouseEvent<T>) => void;
  // onMouseLeave: (e: React.MouseEvent<T>) => void;
  // onTouchEnd: (e: React.TouchEvent<T>) => void;
  const longPress = useLongPress({
    onLongPress: () => {
      if (isMobile) {
        setShowMenu(true);
      }
    },
    onClick: () => {
      // @ts-ignore
      if (isMobile && isThumbnailMessage(message) && isSentMessage(message)) {
        showFileViewer(true);
      }
    }
  }, {
    delay: 300
  });
  if (message !== null && message !== void 0 && (_message$isAdminMessa = message.isAdminMessage) !== null && _message$isAdminMessa !== void 0 && _message$isAdminMessa.call(message) || (message === null || message === void 0 ? void 0 : message.messageType) === 'admin') {
    return /*#__PURE__*/React__default.createElement(AdminMessage, {
      message: message
    });
  }
  return /*#__PURE__*/React__default.createElement("div", {
    className: getClassName([className, 'sendbird-message-content', isByMeClassName]),
    onMouseOver: () => setMouseHover(true),
    onMouseLeave: () => setMouseHover(false)
  }, /*#__PURE__*/React__default.createElement("div", {
    className: getClassName(['sendbird-message-content__left', isReactionEnabledClassName, isByMeClassName, useReplyingClassName])
  }, !isByMe && !chainBottom &&
  /*#__PURE__*/
  /** user profile */
  React__default.createElement(ContextMenu, {
    menuTrigger: toggleDropdown => {
      var _channel$members, _channel$members$find, _message$sender2;
      return /*#__PURE__*/React__default.createElement(Avatar, {
        className: `sendbird-message-content__left__avatar ${displayThreadReplies ? 'use-thread-replies' : ''}`
        // @ts-ignore
        ,
        src: (channel === null || channel === void 0 ? void 0 : (_channel$members = channel.members) === null || _channel$members === void 0 ? void 0 : (_channel$members$find = _channel$members.find(member => {
          var _message$sender;
          return (member === null || member === void 0 ? void 0 : member.userId) === (message === null || message === void 0 ? void 0 : (_message$sender = message.sender) === null || _message$sender === void 0 ? void 0 : _message$sender.userId);
        })) === null || _channel$members$find === void 0 ? void 0 : _channel$members$find.profileUrl) || (message === null || message === void 0 ? void 0 : (_message$sender2 = message.sender) === null || _message$sender2 === void 0 ? void 0 : _message$sender2.profileUrl) || ''
        // TODO: Divide getting profileUrl logic to utils
        ,
        ref: avatarRef,
        width: "28px",
        height: "28px",
        onClick: () => {
          if (!disableUserProfile) toggleDropdown();
        }
      });
    },
    menuItems: closeDropdown => /*#__PURE__*/React__default.createElement(MenuItems
    /**
    * parentRef: For catching location(x, y) of MenuItems
    * parentContainRef: For toggling more options(menus & reactions)
    */, {
      parentRef: avatarRef,
      parentContainRef: avatarRef,
      closeDropdown: closeDropdown,
      style: {
        paddingTop: '0px',
        paddingBottom: '0px'
      }
    }, renderUserProfile
    // @ts-ignore
    ? renderUserProfile({
      user: message === null || message === void 0 ? void 0 : message.sender,
      close: closeDropdown
    })
    // @ts-ignore
    : /*#__PURE__*/React__default.createElement(UserProfile, {
      user: message.sender,
      onSuccess: closeDropdown
    }))
  }), isByMe && !isMobile && /*#__PURE__*/React__default.createElement("div", {
    className: getClassName(['sendbird-message-content-menu', isReactionEnabledClassName, supposedHoverClassName, isByMeClassName])
  }, /*#__PURE__*/React__default.createElement(MessageItemMenu, {
    className: "sendbird-message-content-menu__normal-menu",
    channel: channel,
    message: message,
    isByMe: isByMe,
    replyType: replyType,
    disabled: disabled,
    showEdit: showEdit,
    showRemove: showRemove,
    resendMessage: resendMessage,
    setQuoteMessage: setQuoteMessage,
    setSupposedHover: setSupposedHover,
    onReplyInThread: _ref2 => {
      let {
        message
      } = _ref2;
      if (threadReplySelectType === ThreadReplySelectType.THREAD) {
        onReplyInThread({
          message
        });
      } else if (threadReplySelectType === ThreadReplySelectType.PARENT) {
        scrollToMessage(message.parentMessage.createdAt, message.parentMessageId);
      }
    }
  }), isReactionEnabledInChannel && /*#__PURE__*/React__default.createElement(MessageItemReactionMenu, {
    className: "sendbird-message-content-menu__reaction-menu",
    message: message,
    userId: userId,
    spaceFromTrigger: {},
    emojiContainer: emojiContainer,
    toggleReaction: toggleReaction,
    setSupposedHover: setSupposedHover
  }))), /*#__PURE__*/React__default.createElement("div", _extends({
    className: "sendbird-message-content__middle"
  }, isMobile ? _objectSpread2({}, longPress) : {}, {
    ref: contentRef
  }), !isByMe && !chainTop && !useReplying && /*#__PURE__*/React__default.createElement(Label, {
    className: "sendbird-message-content__middle__sender-name",
    type: LabelTypography.CAPTION_2,
    color: LabelColors.ONBACKGROUND_2
  },
  // @ts-ignore
  (channel === null || channel === void 0 ? void 0 : (_channel$members2 = channel.members) === null || _channel$members2 === void 0 ? void 0 : (_channel$members2$fin = _channel$members2.find(member => {
    var _message$sender3;
    return (member === null || member === void 0 ? void 0 : member.userId) === (message === null || message === void 0 ? void 0 : (_message$sender3 = message.sender) === null || _message$sender3 === void 0 ? void 0 : _message$sender3.userId);
  })) === null || _channel$members2$fin === void 0 ? void 0 : _channel$members2$fin.nickname) || getSenderName(message)
  // TODO: Divide getting profileUrl logic to utils
  ), useReplying ? /*#__PURE__*/React__default.createElement("div", {
    className: getClassName(['sendbird-message-content__middle__quote-message', isByMe ? 'outgoing' : 'incoming', useReplyingClassName])
  }, /*#__PURE__*/React__default.createElement(QuoteMessage, {
    message: message,
    userId: userId,
    isByMe: isByMe,
    isUnavailable: replyType === 'THREAD' && (channel === null || channel === void 0 ? void 0 : channel.joinedAt) * 1000 > (message === null || message === void 0 ? void 0 : (_message$parentMessag = message.parentMessage) === null || _message$parentMessag === void 0 ? void 0 : _message$parentMessag.createdAt),
    onClick: () => {
      var _message$parentMessag2;
      if (replyType === 'THREAD' && threadReplySelectType === ThreadReplySelectType.THREAD) {
        onQuoteMessageClick === null || onQuoteMessageClick === void 0 ? void 0 : onQuoteMessageClick({
          message: message
        });
      }
      if ((replyType === 'QUOTE_REPLY' || replyType === 'THREAD' && threadReplySelectType === ThreadReplySelectType.PARENT) && message !== null && message !== void 0 && (_message$parentMessag2 = message.parentMessage) !== null && _message$parentMessag2 !== void 0 && _message$parentMessag2.createdAt && message !== null && message !== void 0 && message.parentMessageId) {
        scrollToMessage(message.parentMessage.createdAt, message.parentMessageId);
      }
    }
  })) : null, /*#__PURE__*/React__default.createElement("div", {
    className: getClassName(['sendbird-message-content__middle__body-container'])
  }, isByMe && !chainBottom && /*#__PURE__*/React__default.createElement("div", {
    className: getClassName(['sendbird-message-content__middle__body-container__created-at', 'left', supposedHoverClassName])
  }, /*#__PURE__*/React__default.createElement("div", {
    className: "sendbird-message-content__middle__body-container__created-at__component-container"
  }, /*#__PURE__*/React__default.createElement(MessageStatus, {
    message: message,
    channel: channel
  }))), isTextMessage(message) && /*#__PURE__*/React__default.createElement(TextMessageItemBody, {
    className: "sendbird-message-content__middle__message-item-body",
    message: message,
    isByMe: isByMe,
    mouseHover: mouseHover,
    isMentionEnabled: (config === null || config === void 0 ? void 0 : config.isMentionEnabled) || false,
    isReactionEnabled: isReactionEnabledInChannel
  }), isOGMessage(message) && /*#__PURE__*/React__default.createElement(OGMessageItemBody, {
    className: "sendbird-message-content__middle__message-item-body",
    message: message,
    isByMe: isByMe,
    mouseHover: mouseHover,
    isMentionEnabled: (config === null || config === void 0 ? void 0 : config.isMentionEnabled) || false,
    isReactionEnabled: isReactionEnabledInChannel,
    onMessageHeightChange: onMessageHeightChange
  }), getUIKitMessageType(message) === messageTypes.FILE && /*#__PURE__*/React__default.createElement(FileMessageItemBody, {
    className: "sendbird-message-content__middle__message-item-body",
    message: message,
    isByMe: isByMe,
    mouseHover: mouseHover,
    isReactionEnabled: isReactionEnabledInChannel
  }), isVoiceMessage(message) && /*#__PURE__*/React__default.createElement(VoiceMessageItemBody, {
    className: "sendbird-message-content__middle__message-item-body",
    message: message,
    channelUrl: channel === null || channel === void 0 ? void 0 : channel.url,
    isByMe: isByMe,
    isReactionEnabled: isReactionEnabledInChannel
  }), isThumbnailMessage(message) && /*#__PURE__*/React__default.createElement(ThumbnailMessageItemBody, {
    className: "sendbird-message-content__middle__message-item-body",
    message: message,
    isByMe: isByMe,
    mouseHover: mouseHover,
    isReactionEnabled: isReactionEnabledInChannel,
    showFileViewer: showFileViewer
  }), getUIKitMessageType(message) === messageTypes.UNKNOWN && /*#__PURE__*/React__default.createElement(UnknownMessageItemBody, {
    className: "sendbird-message-content__middle__message-item-body",
    message: message,
    isByMe: isByMe,
    mouseHover: mouseHover,
    isReactionEnabled: isReactionEnabledInChannel
  }), isReactionEnabledInChannel && (message === null || message === void 0 ? void 0 : (_message$reactions = message.reactions) === null || _message$reactions === void 0 ? void 0 : _message$reactions.length) > 0 && /*#__PURE__*/React__default.createElement("div", {
    className: getClassName(['sendbird-message-content-reactions', !isByMe || isThumbnailMessage(message) || isOGMessage(message) ? '' : 'primary', mouseHover ? 'mouse-hover' : ''])
  }, /*#__PURE__*/React__default.createElement(EmojiReactions, {
    userId: userId,
    message: message,
    isByMe: isByMe,
    emojiContainer: emojiContainer,
    memberNicknamesMap: nicknamesMap,
    toggleReaction: toggleReaction
  })), !isByMe && !chainBottom && /*#__PURE__*/React__default.createElement(Label, {
    className: getClassName(['sendbird-message-content__middle__body-container__created-at', 'right', supposedHoverClassName]),
    type: LabelTypography.CAPTION_3,
    color: LabelColors.ONBACKGROUND_2
  }, format((message === null || message === void 0 ? void 0 : message.createdAt) || 0, 'p', {
    locale: dateLocale
  }))), displayThreadReplies && /*#__PURE__*/React__default.createElement(ThreadReplies, {
    className: "sendbird-message-content__middle__thread-replies",
    threadInfo: message === null || message === void 0 ? void 0 : message.threadInfo,
    onClick: () => onReplyInThread === null || onReplyInThread === void 0 ? void 0 : onReplyInThread({
      message: message
    })
  })), /*#__PURE__*/React__default.createElement("div", {
    className: getClassName(['sendbird-message-content__right', chainTopClassName, isReactionEnabledClassName, useReplyingClassName])
  }, !isByMe && !isMobile && /*#__PURE__*/React__default.createElement("div", {
    className: getClassName(['sendbird-message-content-menu', chainTopClassName, supposedHoverClassName, isByMeClassName])
  }, isReactionEnabledInChannel && /*#__PURE__*/React__default.createElement(MessageItemReactionMenu, {
    className: "sendbird-message-content-menu__reaction-menu",
    message: message,
    userId: userId,
    spaceFromTrigger: {},
    emojiContainer: emojiContainer,
    toggleReaction: toggleReaction,
    setSupposedHover: setSupposedHover
  }), /*#__PURE__*/React__default.createElement(MessageItemMenu, {
    className: "sendbird-message-content-menu__normal-menu",
    channel: channel,
    message: message,
    isByMe: isByMe,
    replyType: replyType,
    disabled: disabled,
    showRemove: showRemove,
    resendMessage: resendMessage,
    setQuoteMessage: setQuoteMessage,
    setSupposedHover: setSupposedHover,
    onReplyInThread: _ref3 => {
      let {
        message
      } = _ref3;
      if (threadReplySelectType === ThreadReplySelectType.THREAD) {
        onReplyInThread({
          message
        });
      } else if (threadReplySelectType === ThreadReplySelectType.PARENT) {
        scrollToMessage(message.parentMessage.createdAt, message.parentMessageId);
      }
    }
  }))), showMenu && ((message === null || message === void 0 ? void 0 : (_message$isUserMessag = message.isUserMessage) === null || _message$isUserMessag === void 0 ? void 0 : _message$isUserMessag.call(message)) || (message === null || message === void 0 ? void 0 : (_message$isFileMessag = message.isFileMessage) === null || _message$isFileMessag === void 0 ? void 0 : _message$isFileMessag.call(message))) && /*#__PURE__*/React__default.createElement(MobileMenu, {
    parentRef: contentRef,
    channel: channel,
    hideMenu: () => {
      setShowMenu(false);
    },
    message: message,
    isReactionEnabled: isReactionEnabledInChannel,
    isByMe: isByMe,
    userId: userId,
    replyType: replyType,
    disabled: disabled,
    showRemove: showRemove,
    emojiContainer: emojiContainer,
    resendMessage: resendMessage,
    setQuoteMessage: setQuoteMessage,
    toggleReaction: toggleReaction,
    showEdit: showEdit
  }));
}

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