import React__default, { useRef } from 'react';
import ContextMenu, { EmojiListItems } from './ContextMenu.js';
import Icon, { IconTypes, IconColors } from './Icon.js';
import IconButton from './IconButton.js';
import ImageRenderer from './ImageRenderer.js';
import ReactionButton from './ReactionButton.js';
import { E as isPendingMessage, D as isFailedMessage, h as getClassName, G as getEmojiListAll } from '../index-f83f0aac.js';
import '../_rollupPluginBabelHelpers-a69fd1ce.js';
import 'react-dom';
import './SortByRow.js';
import '../uuid-2e8efc75.js';
import '../index-4105bc4d.js';
import 'prop-types';
import '../stringSet-a62108b2.js';
import '../utils/message/getOutgoingMessageState.js';
import '../useLongPress-c0ba590c.js';
import '../MediaQueryContext-b531adc9.js';
import '../utils-4bf6e4e6.js';

function MessageItemReactionMenu(_ref) {
  let {
    className,
    message,
    userId,
    spaceFromTrigger = {
      x: 0,
      y: 0
    },
    emojiContainer,
    toggleReaction,
    setSupposedHover
  } = _ref;
  const triggerRef = useRef(null);
  const containerRef = useRef(null);
  if (isPendingMessage(message) || isFailedMessage(message)) {
    return null;
  }
  return /*#__PURE__*/React__default.createElement("div", {
    className: getClassName([className, 'sendbird-message-item-reaction-menu']),
    ref: containerRef
  }, /*#__PURE__*/React__default.createElement(ContextMenu, {
    menuTrigger: toggleDropdown => /*#__PURE__*/React__default.createElement(IconButton, {
      className: "sendbird-message-item-reaction-menu__trigger",
      ref: triggerRef,
      width: "32px",
      height: "32px",
      onClick: () => {
        toggleDropdown();
        setSupposedHover(true);
      },
      onBlur: () => {
        setSupposedHover(false);
      }
    }, /*#__PURE__*/React__default.createElement(Icon, {
      className: "sendbird-message-item-reaction-menu__trigger__icon",
      type: IconTypes.EMOJI_MORE,
      fillColor: IconColors.CONTENT_INVERSE,
      width: "24px",
      height: "24px"
    })),
    menuItems: close => {
      const closeDropdown = () => {
        close();
        setSupposedHover(false);
      };
      return /*#__PURE__*/React__default.createElement(EmojiListItems, {
        parentRef: triggerRef,
        parentContainRef: containerRef,
        closeDropdown: closeDropdown,
        spaceFromTrigger: spaceFromTrigger
      }, getEmojiListAll(emojiContainer).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: "36px",
          height: "36px",
          selected: isReacted,
          onClick: () => {
            closeDropdown();
            toggleReaction(message, emoji.key, isReacted);
          },
          dataSbId: `ui_emoji_reactions_menu_${emoji.key}`
        }, /*#__PURE__*/React__default.createElement(ImageRenderer, {
          url: 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"
          }))
        }));
      }));
    }
  }));
}

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