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 { w as isPendingMessage, v as isFailedMessage, j as getClassName, y as getEmojiListAll } from '../index-dbe0e004.js';
import '../_rollupPluginBabelHelpers-b2d9bfc5.js';
import 'react-dom';
import './SortByRow.js';
import '../uuid-48baadaf.js';
import '../index-4111594a.js';
import 'prop-types';
import '../stringSet-1f18348a.js';
import '../utils/message/getOutgoingMessageState.js';

function MessageItemReactionMenu(_ref) {
  let {
    className,
    message,
    userId,
    spaceFromTrigger = {},
    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);
          }
        }, /*#__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
