'use strict';

var React = require('react');
var LocalizationContext = require('../../LocalizationContext-44d2f61b.js');
var UserProfileContext = require('../../UserProfileContext-9d843d68.js');
var ui_Avatar = require('../../ui/Avatar.js');
var ui_MutedAvatarOverlay = require('../../ui/MutedAvatarOverlay.js');
var ui_Label = require('../../index-2bfd366f.js');
var ui_UserProfile = require('../../ui/UserProfile.js');
var ui_ContextMenu = require('../../ui/ContextMenu.js');
require('../../stringSet-7aebf034.js');
require('../../index-88e8fdfa.js');
require('prop-types');
require('../../ui/ImageRenderer.js');
require('../../ui/Icon.js');
require('../../uuid-dee74248.js');
require('../../sendbirdSelectors.js');
require('../../_rollupPluginBabelHelpers-21ae158b.js');
require('../../topics-373d2156.js');
require('../../utils-6a748c02.js');
require('../../ui/Button.js');
require('../../useSendbirdStateContext.js');
require('../../withSendbird.js');
require('react-dom');
require('../../ui/SortByRow.js');
require('../../index-1b3c69da.js');
require('../../utils/message/getOutgoingMessageState.js');

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

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

const UserListItem = _ref => {
  let {
    user,
    className,
    currentUser,
    action
  } = _ref;
  const actionRef = React.useRef(null);
  const parentRef = React.useRef(null);
  const avatarRef = React.useRef(null);
  const {
    stringSet
  } = React.useContext(LocalizationContext.LocalizationContext);
  const {
    disableUserProfile,
    renderUserProfile
  } = React.useContext(UserProfileContext.UserProfileContext);
  const injectingClassNames = Array.isArray(className) ? className : [className];
  return /*#__PURE__*/React__default["default"].createElement("div", {
    ref: parentRef,
    className: ['sendbird-user-list-item--small', ...injectingClassNames].join(' ')
  }, /*#__PURE__*/React__default["default"].createElement(ui_ContextMenu["default"], {
    menuTrigger: toggleDropdown => /*#__PURE__*/React__default["default"].createElement(React__default["default"].Fragment, null, /*#__PURE__*/React__default["default"].createElement(ui_Avatar["default"], {
      onClick: () => {
        if (!disableUserProfile) {
          toggleDropdown();
        }
      },
      ref: avatarRef,
      className: "sendbird-user-list-item--small__avatar",
      src: user.profileUrl,
      width: 24,
      height: 24
    }), user.isMuted && /*#__PURE__*/React__default["default"].createElement(ui_MutedAvatarOverlay, null)),
    menuItems: closeDropdown => /*#__PURE__*/React__default["default"].createElement(ui_ContextMenu.MenuItems, {
      openLeft: true,
      parentRef: avatarRef
      // for catching location(x, y) of MenuItems
      ,
      parentContainRef: avatarRef
      // for toggling more options(menus & reactions)
      ,
      closeDropdown: closeDropdown,
      style: {
        paddingTop: '0px',
        paddingBottom: '0px'
      }
    }, renderUserProfile ? renderUserProfile({
      user,
      currentUserId: currentUser,
      close: closeDropdown
    }) : /*#__PURE__*/React__default["default"].createElement(ui_UserProfile, {
      user: user,
      currentUserId: currentUser,
      onSuccess: closeDropdown
    }))
  }), /*#__PURE__*/React__default["default"].createElement(ui_Label.Label, {
    className: "sendbird-user-list-item--small__title",
    type: ui_Label.LabelTypography.SUBTITLE_1,
    color: ui_Label.LabelColors.ONBACKGROUND_1
  }, user.nickname || stringSet.NO_NAME, currentUser === user.userId && stringSet.CHANNEL_SETTING__MEMBERS__YOU),
  // if there is now nickname, display userId
  !user.nickname && /*#__PURE__*/React__default["default"].createElement(ui_Label.Label, {
    className: "sendbird-user-list-item--small__subtitle",
    type: ui_Label.LabelTypography.CAPTION_3,
    color: ui_Label.LabelColors.ONBACKGROUND_2
  }, user.userId), user.role === 'operator' && /*#__PURE__*/React__default["default"].createElement(ui_Label.Label, {
    className: "sendbird-user-list-item--small__operator",
    type: ui_Label.LabelTypography.SUBTITLE_2,
    color: ui_Label.LabelColors.ONBACKGROUND_2
  }, stringSet.CHANNEL_SETTING__MEMBERS__OPERATOR), action && /*#__PURE__*/React__default["default"].createElement("div", {
    ref: actionRef,
    className: "sendbird-user-list-item--small__action"
  }, action({
    actionRef,
    parentRef
  })));
};

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