'use strict';

var React = require('react');
var UserProfileContext = require('../UserProfileContext-d993c96b.js');
var LocalizationContext = require('../LocalizationContext-8cc9717d.js');
var ui_Avatar = require('./Avatar.js');
var ui_MutedAvatarOverlay = require('./MutedAvatarOverlay.js');
var ui_Checkbox = require('./Checkbox.js');
var ui_UserProfile = require('./UserProfile.js');
var ui_ContextMenu = require('./ContextMenu.js');
var ui_Label = require('../index-35633fb6.js');
require('prop-types');
require('../stringSet-ce782136.js');
require('../index-d749c4c2.js');
require('./ImageRenderer.js');
require('./Icon.js');
require('../uuid-1eceb0c8.js');
require('../sendbirdSelectors.js');
require('../_rollupPluginBabelHelpers-acf412a3.js');
require('../topics-e24ef339.js');
require('../utils-5aa0708e.js');
require('./Button.js');
require('../useSendbirdStateContext.js');
require('../withSendbird.js');
require('react-dom');
require('./SortByRow.js');
require('../index-a91b85d9.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);

function UserListItem(_ref) {
  let {
    user,
    className,
    checked,
    checkBox,
    isOperator,
    disabled,
    disableMessaging,
    currentUser,
    action,
    onChange,
    avatarSize = '40px'
  } = _ref;
  const uniqueKey = user.userId;
  const actionRef = React__default["default"].useRef(null);
  const parentRef = React__default["default"].useRef(null);
  const avatarRef = React__default["default"].useRef(null);
  const {
    disableUserProfile,
    renderUserProfile
  } = React.useContext(UserProfileContext.UserProfileContext);
  const {
    stringSet
  } = React.useContext(LocalizationContext.LocalizationContext);
  return /*#__PURE__*/React__default["default"].createElement("div", {
    className: [...(Array.isArray(className) ? className : [className]), 'sendbird-user-list-item'].join(' '),
    ref: parentRef
  }, (user === null || user === void 0 ? void 0 : user.isMuted) && /*#__PURE__*/React__default["default"].createElement(ui_MutedAvatarOverlay, {
    height: 40,
    width: 40
  }), /*#__PURE__*/React__default["default"].createElement(ui_ContextMenu["default"], {
    menuTrigger: toggleDropdown => /*#__PURE__*/React__default["default"].createElement(ui_Avatar["default"], {
      className: "sendbird-user-list-item__avatar",
      ref: avatarRef,
      src: user.profileUrl,
      width: avatarSize,
      height: avatarSize,
      onClick: () => {
        if (!disableUserProfile) {
          toggleDropdown();
        }
      }
    }),
    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, {
      disableMessaging: disableMessaging,
      user: user,
      currentUserId: currentUser,
      onSuccess: closeDropdown
    }))
  }), /*#__PURE__*/React__default["default"].createElement(ui_Label.Label, {
    className: "sendbird-user-list-item__title",
    type: ui_Label.LabelTypography.SUBTITLE_1,
    color: ui_Label.LabelColors.ONBACKGROUND_1
  }, user.nickname || stringSet.NO_NAME, currentUser === user.userId && ' (You)'),
  // if there is now nickname, display userId
  !user.nickname && /*#__PURE__*/React__default["default"].createElement(ui_Label.Label, {
    className: "sendbird-user-list-item__subtitle",
    type: ui_Label.LabelTypography.CAPTION_3,
    color: ui_Label.LabelColors.ONBACKGROUND_2
  }, user.userId), checkBox && /*#__PURE__*/React__default["default"].createElement("label", {
    className: "sendbird-user-list-item__checkbox",
    htmlFor: uniqueKey
  }, /*#__PURE__*/React__default["default"].createElement(ui_Checkbox, {
    id: uniqueKey,
    checked: checked,
    disabled: disabled,
    onChange: event => onChange(event)
  })), isOperator && /*#__PURE__*/React__default["default"].createElement(ui_Label.Label, {
    className: ['sendbird-user-list-item__operator', checkBox ? 'checkbox' : ''].join(' '),
    type: ui_Label.LabelTypography.SUBTITLE_2,
    color: ui_Label.LabelColors.ONBACKGROUND_2
  }, "Operator"), action && /*#__PURE__*/React__default["default"].createElement("div", {
    className: "sendbird-user-list-item__action",
    ref: actionRef
  }, action({
    actionRef,
    parentRef
  })));
}

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