'use strict';

var _rollupPluginBabelHelpers = require('../_rollupPluginBabelHelpers-c5955c81.js');
var React = require('react');
var index$1 = require('../index-f65677b1.js');
var ui_Avatar = require('./Avatar.js');
var ui_UserProfile = require('./UserProfile.js');
var ui_MessageStatus = require('../index-900dd19f.js');
var ui_MessageItemMenu = require('./MessageItemMenu.js');
var ui_MessageItemReactionMenu = require('./MessageItemReactionMenu.js');
var ui_ContextMenu = require('./ContextMenu.js');
var ui_Label = require('../index-73643285.js');
var ui_EmojiReactions = require('./EmojiReactions.js');
var ui_AdminMessage = require('./AdminMessage.js');
var ui_TextMessageItemBody = require('./TextMessageItemBody.js');
var ui_FileMessageItemBody = require('./FileMessageItemBody.js');
var ui_ThumbnailMessageItemBody = require('./ThumbnailMessageItemBody.js');
var ui_OGMessageItemBody = require('./OGMessageItemBody.js');
var ui_UnknownMessageItemBody = require('./UnknownMessageItemBody.js');
var ui_QuoteMessage = require('./QuoteMessage.js');
var index = require('../index-f2146bae.js');
var UserProfileContext = require('../UserProfileContext-f068b0ba.js');
var LocalizationContext = require('../LocalizationContext-af96cf5f.js');
var useSendbirdStateContext = require('../useSendbirdStateContext.js');
var useLongPress = require('../useLongPress-d9deb354.js');
var ui_Icon = require('./Icon.js');
var ui_BottomSheet = require('./BottomSheet.js');
var ui_ImageRenderer = require('./ImageRenderer.js');
var ui_ReactionButton = require('./ReactionButton.js');
var MediaQueryContext = require('../MediaQueryContext-8ec3f647.js');
var ui_ThreadReplies = require('./ThreadReplies.js');
var _const = require('../const-6691e574.js');
var ui_VoiceMessageItemBody = require('./VoiceMessageItemBody.js');
require('../index-83d1d15e.js');
require('../uuid-0b4ed44c.js');
require('prop-types');
require('../sendbirdSelectors.js');
require('../topics-825e5d42.js');
require('../utils-d5176360.js');
require('./Button.js');
require('../stringSet-68748705.js');
require('./Loader.js');
require('../utils/message/getOutgoingMessageState.js');
require('../index-6cb4a530.js');
require('../index-4ee95667.js');
require('./IconButton.js');
require('../types-24accb8d.js');
require('react-dom');
require('./SortByRow.js');
require('./Tooltip.js');
require('./TooltipWrapper.js');
require('./ReactionBadge.js');
require('../tokenize-d86ab0c7.js');
require('../index-0b344bd7.js');
require('../index.module-9f5edc7b.js');
require('../Message/context.js');
require('./MentionLabel.js');
require('./LinkLabel.js');
require('../consts-bc27beff.js');
require('./TextButton.js');
require('../color-afeb8dc2.js');
require('../consts-a422c2f9.js');
require('../withSendbird.js');
require('../index-68c57136.js');
require('./ProgressBar.js');
require('../VoicePlayer/useVoicePlayer.js');
require('../index-9d518988.js');
require('../consts-a5382bc1.js');
require('../VoiceRecorder/context.js');
require('./PlaybackTime.js');

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

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

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
  } = LocalizationContext.useLocalization();
  const showMenuItemCopy = index.isUserMessage(message);
  const showMenuItemEdit = index.isUserMessage(message) && index.isSentMessage(message) && isByMe;
  const showMenuItemResend = index.isFailedMessage(message) && (message === null || message === void 0 ? void 0 : message.isResendable) && isByMe;
  const showMenuItemDelete = !index.isPendingMessage(message) && isByMe;
  const showMenuItemDownload = !index.isPendingMessage(message) && index.isFileMessage(message);
  const showMenuItemReply = replyType === 'QUOTE_REPLY' && !index.isFailedMessage(message) && !index.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["default"].createElement(ui_ContextMenu["default"], {
    isOpen: true,
    menuItems: () => {
      var _message$threadInfo;
      return /*#__PURE__*/React__default["default"].createElement(ui_ContextMenu.MenuItems, {
        className: "sendbird-message__mobile-context-menu",
        parentRef: parentRef,
        parentContainRef: parentRef,
        closeDropdown: hideMenu
      }, showMenuItemCopy && /*#__PURE__*/React__default["default"].createElement(ui_ContextMenu.MenuItem, {
        className: "sendbird-message__mobile-context-menu-item menu-item-copy",
        onClick: () => {
          hideMenu();
          index.copyToClipboard(message === null || message === void 0 ? void 0 : message.message);
        }
      }, /*#__PURE__*/React__default["default"].createElement(ui_Label.Label, {
        type: ui_Label.LabelTypography.SUBTITLE_1
      }, stringSet === null || stringSet === void 0 ? void 0 : stringSet.MESSAGE_MENU__COPY), /*#__PURE__*/React__default["default"].createElement(ui_Icon["default"], {
        type: ui_Icon.IconTypes.COPY,
        fillColor: ui_Icon.IconColors.PRIMARY,
        width: "24px",
        height: "24px"
      })), showMenuItemReply && /*#__PURE__*/React__default["default"].createElement(ui_ContextMenu.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["default"].createElement(ui_Label.Label, {
        type: ui_Label.LabelTypography.SUBTITLE_1
      }, stringSet.MESSAGE_MENU__REPLY), /*#__PURE__*/React__default["default"].createElement(ui_Icon["default"], {
        type: ui_Icon.IconTypes.REPLY,
        fillColor: ui_Icon.IconColors.PRIMARY,
        width: "24px",
        height: "24px"
      })), showMenuItemEdit && /*#__PURE__*/React__default["default"].createElement(ui_ContextMenu.MenuItem, {
        className: "sendbird-message__mobile-context-menu-item menu-item-edit",
        onClick: () => {
          hideMenu();
          showEdit(true);
        }
      }, /*#__PURE__*/React__default["default"].createElement(ui_Label.Label, {
        type: ui_Label.LabelTypography.SUBTITLE_1
      }, stringSet.MESSAGE_MENU__EDIT), /*#__PURE__*/React__default["default"].createElement(ui_Icon["default"], {
        type: ui_Icon.IconTypes.EDIT,
        fillColor: ui_Icon.IconColors.PRIMARY,
        width: "24px",
        height: "24px"
      })), showMenuItemResend && /*#__PURE__*/React__default["default"].createElement(ui_ContextMenu.MenuItem, {
        className: "sendbird-message__mobile-context-menu-item menu-item-resend",
        onClick: () => {
          hideMenu();
          resendMessage(message);
        }
      }, /*#__PURE__*/React__default["default"].createElement(ui_Label.Label, {
        type: ui_Label.LabelTypography.SUBTITLE_1
      }, stringSet.MESSAGE_MENU__RESEND), /*#__PURE__*/React__default["default"].createElement(ui_Icon["default"], {
        type: ui_Icon.IconTypes.REFRESH,
        fillColor: ui_Icon.IconColors.PRIMARY,
        width: "24px",
        height: "24px"
      })), showMenuItemDelete && /*#__PURE__*/React__default["default"].createElement(ui_ContextMenu.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["default"].createElement(ui_Label.Label, {
        type: ui_Label.LabelTypography.SUBTITLE_1
      }, stringSet.MESSAGE_MENU__DELETE), /*#__PURE__*/React__default["default"].createElement(ui_Icon["default"], {
        type: ui_Icon.IconTypes.DELETE,
        fillColor: ui_Icon.IconColors.PRIMARY,
        width: "24px",
        height: "24px"
      })), showMenuItemDownload && /*#__PURE__*/React__default["default"].createElement(ui_ContextMenu.MenuItem, {
        className: "sendbird-message__mobile-context-menu-item menu-item-save",
        onClick: () => {
          hideMenu();
        }
      }, /*#__PURE__*/React__default["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["default"].createElement(ui_Label.Label, {
        type: ui_Label.LabelTypography.SUBTITLE_1
      }, stringSet.MESSAGE_MENU__SAVE), /*#__PURE__*/React__default["default"].createElement(ui_Icon["default"], {
        type: ui_Icon.IconTypes.DOWNLOAD,
        fillColor: ui_Icon.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
  } = LocalizationContext.useLocalization();
  const showMenuItemCopy = index.isUserMessage(message);
  const showMenuItemEdit = index.isUserMessage(message) && index.isSentMessage(message) && isByMe;
  const showMenuItemResend = index.isFailedMessage(message) && (message === null || message === void 0 ? void 0 : message.isResendable) && isByMe;
  const showMenuItemDelete = !index.isPendingMessage(message) && isByMe;
  const showMenuItemDownload = !index.isPendingMessage(message) && index.isFileMessage(message);
  const showReaction = !index.isFailedMessage(message) && !index.isPendingMessage(message) && isReactionEnabled;
  const showMenuItemReply = replyType === 'QUOTE_REPLY' && !index.isFailedMessage(message) && !index.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] = React.useState(false);
  const emojis = index.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["default"].createElement(ui_BottomSheet, {
    onBackdropClick: hideMenu
  }, /*#__PURE__*/React__default["default"].createElement("div", {
    className: "sendbird-message__bottomsheet"
  }, showReaction && /*#__PURE__*/React__default["default"].createElement("div", {
    className: "sendbird-message__bottomsheet-reactions"
  }, /*#__PURE__*/React__default["default"].createElement("ul", {
    className: "sendbird-message__bottomsheet-reaction-bar"
  }, /*#__PURE__*/React__default["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["default"].createElement(ui_ReactionButton, {
      key: emoji.key,
      width: `${EMOJI_SIZE}px`,
      height: `${EMOJI_SIZE}px`,
      selected: isReacted,
      onClick: () => {
        hideMenu();
        toggleReaction(message, emoji.key, isReacted);
      }
    }, /*#__PURE__*/React__default["default"].createElement(ui_ImageRenderer, {
      url: (emoji === null || emoji === void 0 ? void 0 : emoji.url) || '',
      width: "28px",
      height: "28px",
      placeHolder: style => /*#__PURE__*/React__default["default"].createElement("div", {
        style: style
      }, /*#__PURE__*/React__default["default"].createElement(ui_Icon["default"], {
        type: ui_Icon.IconTypes.QUESTION,
        fillColor: ui_Icon.IconColors.ON_BACKGROUND_3,
        width: "28px",
        height: "28px"
      }))
    }));
  }), canShowMoreEmojis && !showEmojisOnly && /*#__PURE__*/React__default["default"].createElement(ui_ReactionButton, {
    key: "emoji_more",
    width: "38px",
    height: "38px",
    onClick: () => {
      setShowEmojisOnly(true);
    }
  }, /*#__PURE__*/React__default["default"].createElement(ui_ImageRenderer, {
    url: '',
    width: "28px",
    height: "28px",
    placeHolder: style => /*#__PURE__*/React__default["default"].createElement("div", {
      style: style
    }, /*#__PURE__*/React__default["default"].createElement(ui_Icon["default"], {
      type: ui_Icon.IconTypes.EMOJI_MORE,
      fillColor: ui_Icon.IconColors.ON_BACKGROUND_3,
      width: "28px",
      height: "28px"
    }))
  }))))), !showEmojisOnly && /*#__PURE__*/React__default["default"].createElement("div", {
    className: "sendbird-message__bottomsheet--actions"
  }, showMenuItemCopy && /*#__PURE__*/React__default["default"].createElement("div", {
    className: "sendbird-message__bottomsheet--action",
    onClick: () => {
      hideMenu();
      index.copyToClipboard(message === null || message === void 0 ? void 0 : message.message);
    }
  }, /*#__PURE__*/React__default["default"].createElement(ui_Icon["default"], {
    type: ui_Icon.IconTypes.COPY,
    fillColor: ui_Icon.IconColors.PRIMARY,
    width: "24px",
    height: "24px"
  }), /*#__PURE__*/React__default["default"].createElement(ui_Label.Label, {
    type: ui_Label.LabelTypography.SUBTITLE_1
  }, stringSet === null || stringSet === void 0 ? void 0 : stringSet.MESSAGE_MENU__COPY)), showMenuItemEdit && /*#__PURE__*/React__default["default"].createElement("div", {
    className: "sendbird-message__bottomsheet--action",
    onClick: () => {
      hideMenu();
      showEdit(true);
    }
  }, /*#__PURE__*/React__default["default"].createElement(ui_Icon["default"], {
    type: ui_Icon.IconTypes.EDIT,
    fillColor: ui_Icon.IconColors.PRIMARY,
    width: "24px",
    height: "24px"
  }), /*#__PURE__*/React__default["default"].createElement(ui_Label.Label, {
    type: ui_Label.LabelTypography.SUBTITLE_1
  }, stringSet === null || stringSet === void 0 ? void 0 : stringSet.MESSAGE_MENU__EDIT)), showMenuItemResend && /*#__PURE__*/React__default["default"].createElement("div", {
    className: "sendbird-message__bottomsheet--action",
    onClick: () => {
      hideMenu();
      resendMessage(message);
    }
  }, /*#__PURE__*/React__default["default"].createElement(ui_Icon["default"], {
    type: ui_Icon.IconTypes.REFRESH,
    fillColor: ui_Icon.IconColors.PRIMARY,
    width: "24px",
    height: "24px"
  }), /*#__PURE__*/React__default["default"].createElement(ui_Label.Label, {
    type: ui_Label.LabelTypography.SUBTITLE_1
  }, stringSet === null || stringSet === void 0 ? void 0 : stringSet.MESSAGE_MENU__RESEND)), showMenuItemReply && /*#__PURE__*/React__default["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["default"].createElement(ui_Icon["default"], {
    type: ui_Icon.IconTypes.REPLY,
    fillColor: disableReaction ? ui_Icon.IconColors.ON_BACKGROUND_3 : ui_Icon.IconColors.PRIMARY,
    width: "24px",
    height: "24px"
  }), /*#__PURE__*/React__default["default"].createElement(ui_Label.Label, {
    type: ui_Label.LabelTypography.SUBTITLE_1,
    color: disableReaction && ui_Label.LabelColors.ONBACKGROUND_4
  }, stringSet === null || stringSet === void 0 ? void 0 : stringSet.MESSAGE_MENU__REPLY)), showMenuItemDelete && /*#__PURE__*/React__default["default"].createElement("div", {
    className: "sendbird-message__bottomsheet--action",
    onClick: () => {
      hideMenu();
      showRemove(true);
    }
  }, /*#__PURE__*/React__default["default"].createElement(ui_Icon["default"], {
    type: ui_Icon.IconTypes.DELETE,
    fillColor: ui_Icon.IconColors.PRIMARY,
    width: "24px",
    height: "24px"
  }), /*#__PURE__*/React__default["default"].createElement(ui_Label.Label, {
    type: ui_Label.LabelTypography.SUBTITLE_1
  }, stringSet === null || stringSet === void 0 ? void 0 : stringSet.MESSAGE_MENU__DELETE)), showMenuItemDownload && /*#__PURE__*/React__default["default"].createElement("div", {
    className: "sendbird-message__bottomsheet--action",
    onClick: () => {
      hideMenu();
    }
  }, /*#__PURE__*/React__default["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["default"].createElement(ui_Icon["default"], {
    type: ui_Icon.IconTypes.DOWNLOAD,
    fillColor: ui_Icon.IconColors.PRIMARY,
    width: "24px",
    height: "24px"
  }), /*#__PURE__*/React__default["default"].createElement(ui_Label.Label, {
    type: ui_Label.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["default"].createElement(React__default["default"].Fragment, null, isReactionEnabled ? /*#__PURE__*/React__default["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["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 = index.getUIKitMessageTypes();
  const {
    dateLocale
  } = LocalizationContext.useLocalization();
  const {
    config
  } = (useSendbirdStateContext === null || useSendbirdStateContext === void 0 ? void 0 : useSendbirdStateContext()) || {};
  const {
    disableUserProfile,
    renderUserProfile
  } = React.useContext(UserProfileContext.UserProfileContext);
  const avatarRef = React.useRef(null);
  const contentRef = React.useRef(null);
  const {
    isMobile
  } = MediaQueryContext.useMediaQueryContext();
  const [showMenu, setShowMenu] = React.useState(false);
  const [mouseHover, setMouseHover] = React.useState(false);
  const [supposedHover, setSupposedHover] = React.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.useLongPress({
    onLongPress: () => {
      if (isMobile) {
        setShowMenu(true);
      }
    },
    onClick: () => {
      // @ts-ignore
      if (isMobile && index.isThumbnailMessage(message) && index.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["default"].createElement(ui_AdminMessage, {
      message: message
    });
  }
  return /*#__PURE__*/React__default["default"].createElement("div", {
    className: index.getClassName([className, 'sendbird-message-content', isByMeClassName]),
    onMouseOver: () => setMouseHover(true),
    onMouseLeave: () => setMouseHover(false)
  }, /*#__PURE__*/React__default["default"].createElement("div", {
    className: index.getClassName(['sendbird-message-content__left', isReactionEnabledClassName, isByMeClassName, useReplyingClassName])
  }, !isByMe && !chainBottom &&
  /*#__PURE__*/
  /** user profile */
  React__default["default"].createElement(ui_ContextMenu["default"], {
    menuTrigger: toggleDropdown => {
      var _channel$members, _channel$members$find, _message$sender2;
      return /*#__PURE__*/React__default["default"].createElement(ui_Avatar["default"], {
        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["default"].createElement(ui_ContextMenu.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["default"].createElement(ui_UserProfile, {
      user: message.sender,
      onSuccess: closeDropdown
    }))
  }), isByMe && !isMobile && /*#__PURE__*/React__default["default"].createElement("div", {
    className: index.getClassName(['sendbird-message-content-menu', isReactionEnabledClassName, supposedHoverClassName, isByMeClassName])
  }, /*#__PURE__*/React__default["default"].createElement(ui_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 === _const.ThreadReplySelectType.THREAD) {
        onReplyInThread({
          message
        });
      } else if (threadReplySelectType === _const.ThreadReplySelectType.PARENT) {
        scrollToMessage(message.parentMessage.createdAt, message.parentMessageId);
      }
    }
  }), isReactionEnabledInChannel && /*#__PURE__*/React__default["default"].createElement(ui_MessageItemReactionMenu, {
    className: "sendbird-message-content-menu__reaction-menu",
    message: message,
    userId: userId,
    spaceFromTrigger: {},
    emojiContainer: emojiContainer,
    toggleReaction: toggleReaction,
    setSupposedHover: setSupposedHover
  }))), /*#__PURE__*/React__default["default"].createElement("div", _rollupPluginBabelHelpers._extends({
    className: "sendbird-message-content__middle"
  }, isMobile ? _rollupPluginBabelHelpers._objectSpread2({}, longPress) : {}, {
    ref: contentRef
  }), !isByMe && !chainTop && !useReplying && /*#__PURE__*/React__default["default"].createElement(ui_Label.Label, {
    className: "sendbird-message-content__middle__sender-name",
    type: ui_Label.LabelTypography.CAPTION_2,
    color: ui_Label.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) || index.getSenderName(message)
  // TODO: Divide getting profileUrl logic to utils
  ), useReplying ? /*#__PURE__*/React__default["default"].createElement("div", {
    className: index.getClassName(['sendbird-message-content__middle__quote-message', isByMe ? 'outgoing' : 'incoming', useReplyingClassName])
  }, /*#__PURE__*/React__default["default"].createElement(ui_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 === _const.ThreadReplySelectType.THREAD) {
        onQuoteMessageClick === null || onQuoteMessageClick === void 0 ? void 0 : onQuoteMessageClick({
          message: message
        });
      }
      if ((replyType === 'QUOTE_REPLY' || replyType === 'THREAD' && threadReplySelectType === _const.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["default"].createElement("div", {
    className: index.getClassName(['sendbird-message-content__middle__body-container'])
  }, isByMe && !chainBottom && /*#__PURE__*/React__default["default"].createElement("div", {
    className: index.getClassName(['sendbird-message-content__middle__body-container__created-at', 'left', supposedHoverClassName])
  }, /*#__PURE__*/React__default["default"].createElement("div", {
    className: "sendbird-message-content__middle__body-container__created-at__component-container"
  }, /*#__PURE__*/React__default["default"].createElement(ui_MessageStatus.MessageStatus, {
    message: message,
    channel: channel
  }))), index.isTextMessage(message) && /*#__PURE__*/React__default["default"].createElement(ui_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
  }), index.isOGMessage(message) && /*#__PURE__*/React__default["default"].createElement(ui_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
  }), index.getUIKitMessageType(message) === messageTypes.FILE && /*#__PURE__*/React__default["default"].createElement(ui_FileMessageItemBody, {
    className: "sendbird-message-content__middle__message-item-body",
    message: message,
    isByMe: isByMe,
    mouseHover: mouseHover,
    isReactionEnabled: isReactionEnabledInChannel
  }), index.isVoiceMessage(message) && /*#__PURE__*/React__default["default"].createElement(ui_VoiceMessageItemBody.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
  }), index.isThumbnailMessage(message) && /*#__PURE__*/React__default["default"].createElement(ui_ThumbnailMessageItemBody, {
    className: "sendbird-message-content__middle__message-item-body",
    message: message,
    isByMe: isByMe,
    mouseHover: mouseHover,
    isReactionEnabled: isReactionEnabledInChannel,
    showFileViewer: showFileViewer
  }), index.getUIKitMessageType(message) === messageTypes.UNKNOWN && /*#__PURE__*/React__default["default"].createElement(ui_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["default"].createElement("div", {
    className: index.getClassName(['sendbird-message-content-reactions', !isByMe || index.isThumbnailMessage(message) || index.isOGMessage(message) ? '' : 'primary', mouseHover ? 'mouse-hover' : ''])
  }, /*#__PURE__*/React__default["default"].createElement(ui_EmojiReactions, {
    userId: userId,
    message: message,
    isByMe: isByMe,
    emojiContainer: emojiContainer,
    memberNicknamesMap: nicknamesMap,
    toggleReaction: toggleReaction
  })), !isByMe && !chainBottom && /*#__PURE__*/React__default["default"].createElement(ui_Label.Label, {
    className: index.getClassName(['sendbird-message-content__middle__body-container__created-at', 'right', supposedHoverClassName]),
    type: ui_Label.LabelTypography.CAPTION_3,
    color: ui_Label.LabelColors.ONBACKGROUND_2
  }, index$1.format((message === null || message === void 0 ? void 0 : message.createdAt) || 0, 'p', {
    locale: dateLocale
  }))), displayThreadReplies && /*#__PURE__*/React__default["default"].createElement(ui_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["default"].createElement("div", {
    className: index.getClassName(['sendbird-message-content__right', chainTopClassName, isReactionEnabledClassName, useReplyingClassName])
  }, !isByMe && !isMobile && /*#__PURE__*/React__default["default"].createElement("div", {
    className: index.getClassName(['sendbird-message-content-menu', chainTopClassName, supposedHoverClassName, isByMeClassName])
  }, isReactionEnabledInChannel && /*#__PURE__*/React__default["default"].createElement(ui_MessageItemReactionMenu, {
    className: "sendbird-message-content-menu__reaction-menu",
    message: message,
    userId: userId,
    spaceFromTrigger: {},
    emojiContainer: emojiContainer,
    toggleReaction: toggleReaction,
    setSupposedHover: setSupposedHover
  }), /*#__PURE__*/React__default["default"].createElement(ui_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 === _const.ThreadReplySelectType.THREAD) {
        onReplyInThread({
          message
        });
      } else if (threadReplySelectType === _const.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["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
  }));
}

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