'use strict';

var React = require('react');
var LocalizationContext = require('../../LocalizationContext-8cc9717d.js');
var ui_Accordion = require('../../ui/Accordion.js');
var ui_Label = require('../../index-35633fb6.js');
var ui_Icon = require('../../ui/Icon.js');
var ui_Badge = require('../../ui/Badge.js');
var ui_Toggle = require('../../ui/Toggle.js');
var ui_Button = require('../../ui/Button.js');
var ui_IconButton = require('../../ui/IconButton.js');
var ui_ContextMenu = require('../../ui/ContextMenu.js');
var ChannelSettings_components_UserListItem = require('./UserListItem.js');
var ui_Modal = require('../../ui/Modal.js');
var ui_UserListItem = require('../../ui/UserListItem.js');
var ChannelSettings_context = require('../context.js');
var useSendbirdStateContext = require('../../useSendbirdStateContext.js');
var _rollupPluginBabelHelpers = require('../../_rollupPluginBabelHelpers-acf412a3.js');
var groupChannel = require('@sendbird/chat/groupChannel');
var MemberList = require('../../MemberList-073f16cc.js');
var utils = require('../../utils-5aa0708e.js');
require('../../stringSet-ce782136.js');
require('../../index-d749c4c2.js');
require('../../ui/AccordionGroup.js');
require('../../context-18074bb9.js');
require('prop-types');
require('react-dom');
require('../../ui/SortByRow.js');
require('../../uuid-1eceb0c8.js');
require('../../index-a91b85d9.js');
require('../../utils/message/getOutgoingMessageState.js');
require('../../UserProfileContext-d993c96b.js');
require('../../ui/Avatar.js');
require('../../ui/ImageRenderer.js');
require('../../ui/MutedAvatarOverlay.js');
require('../../ui/UserProfile.js');
require('../../sendbirdSelectors.js');
require('../../topics-e24ef339.js');
require('../../index-8029e07a.js');
require('../../MediaQueryContext-fad211ad.js');
require('../../ui/Checkbox.js');
require('../../withSendbird.js');

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

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

function OperatorsModal(_ref) {
  var _state$config;
  let {
    onCancel
  } = _ref;
  const [operators, setOperators] = React.useState([]);
  const [operatorQuery, setOperatorQuery] = React.useState(null);
  const {
    channel
  } = ChannelSettings_context.useChannelSettingsContext();
  const state = useSendbirdStateContext();
  const currentUserId = state === null || state === void 0 ? void 0 : (_state$config = state.config) === null || _state$config === void 0 ? void 0 : _state$config.userId;
  const {
    stringSet
  } = React.useContext(LocalizationContext.LocalizationContext);
  React.useEffect(() => {
    const operatorListQuery = channel === null || channel === void 0 ? void 0 : channel.createOperatorListQuery({
      limit: 20
    });
    operatorListQuery.next().then(operators => {
      setOperators(operators);
    });
    setOperatorQuery(operatorListQuery);
  }, []);
  return /*#__PURE__*/React__default["default"].createElement("div", null, /*#__PURE__*/React__default["default"].createElement(ui_Modal["default"], {
    isFullScreenOnMobile: true,
    hideFooter: true,
    titleText: stringSet.CHANNEL_SETTING__OPERATORS__TITLE_ALL,
    onCancel: onCancel
  }, /*#__PURE__*/React__default["default"].createElement("div", {
    className: "sendbird-more-members__popup-scroll",
    onScroll: e => {
      const {
        hasNext
      } = operatorQuery;
      const target = e.target;
      const fetchMore = target.clientHeight + target.scrollTop === target.scrollHeight;
      if (hasNext && fetchMore) {
        operatorQuery.next().then(o => {
          setOperators([...operators, ...o]);
        });
      }
    }
  }, operators.map(member => /*#__PURE__*/React__default["default"].createElement(ui_UserListItem, {
    currentUser: currentUserId,
    user: member,
    key: member.userId,
    action: _ref2 => {
      let {
        parentRef,
        actionRef
      } = _ref2;
      return (member === null || member === void 0 ? void 0 : member.userId) !== currentUserId && /*#__PURE__*/React__default["default"].createElement(ui_ContextMenu["default"], {
        menuTrigger: toggleDropdown => /*#__PURE__*/React__default["default"].createElement(ui_IconButton, {
          className: "sendbird-user-message__more__menu",
          width: "32px",
          height: "32px",
          onClick: toggleDropdown
        }, /*#__PURE__*/React__default["default"].createElement(ui_Icon["default"], {
          width: "24px",
          height: "24px",
          type: ui_Icon.IconTypes.MORE,
          fillColor: ui_Icon.IconColors.CONTENT_INVERSE
        })),
        menuItems: closeDropdown => /*#__PURE__*/React__default["default"].createElement(ui_ContextMenu.MenuItems, {
          parentContainRef: parentRef,
          parentRef: actionRef // for catching location(x, y) of MenuItems
          ,
          closeDropdown: closeDropdown,
          openLeft: true
        }, /*#__PURE__*/React__default["default"].createElement(ui_ContextMenu.MenuItem, {
          onClick: () => {
            channel === null || channel === void 0 ? void 0 : channel.removeOperators([member.userId]).then(() => {
              setOperators(operators.filter(_ref3 => {
                let {
                  userId
                } = _ref3;
                return userId !== member.userId;
              }));
            });
            closeDropdown();
          },
          dataSbId: "channel_setting_operator_context_menu_unregister_unregister_operator"
        }, stringSet.CHANNEL_SETTING__MODERATION__UNREGISTER_OPERATOR))
      });
    }
  })))));
}

function AddOperatorsModal(_ref) {
  let {
    onCancel,
    onSubmit
  } = _ref;
  const [members, setMembers] = React.useState([]);
  const [selectedMembers, setSelectedMembers] = React.useState({});
  const [memberQuery, setMemberQuery] = React.useState(null);
  const {
    stringSet
  } = React.useContext(LocalizationContext.LocalizationContext);
  const {
    channel
  } = ChannelSettings_context.useChannelSettingsContext();
  React.useEffect(() => {
    const memberListQuery = channel === null || channel === void 0 ? void 0 : channel.createMemberListQuery({
      operatorFilter: groupChannel.OperatorFilter.NONOPERATOR,
      limit: 20
    });
    memberListQuery.next().then(members => {
      setMembers(members);
    });
    setMemberQuery(memberListQuery);
  }, []);
  const selectedCount = Object.keys(selectedMembers).filter(m => selectedMembers[m]).length;
  return /*#__PURE__*/React__default["default"].createElement("div", null, /*#__PURE__*/React__default["default"].createElement(ui_Modal["default"], {
    isFullScreenOnMobile: true,
    type: ui_Button.ButtonTypes.PRIMARY,
    submitText: stringSet.CHANNEL_SETTING__OPERATORS__ADD_BUTTON,
    onCancel: onCancel,
    onSubmit: () => {
      const members = Object.keys(selectedMembers).filter(m => selectedMembers[m]);
      channel === null || channel === void 0 ? void 0 : channel.addOperators(members).then(() => {
        onSubmit(members);
      });
    },
    titleText: stringSet.CHANNEL_SETTING__MEMBERS__SELECT_TITLE
  }, /*#__PURE__*/React__default["default"].createElement(ui_Label.Label, {
    color: selectedCount > 0 ? ui_Label.LabelColors.PRIMARY : ui_Label.LabelColors.ONBACKGROUND_3,
    type: ui_Label.LabelTypography.CAPTION_1
  }, `${selectedCount} ${stringSet.MODAL__INVITE_MEMBER__SELECTED}`), /*#__PURE__*/React__default["default"].createElement("div", {
    className: "sendbird-more-members__popup-scroll",
    onScroll: e => {
      const {
        hasNext
      } = memberQuery;
      const target = e.target;
      const fetchMore = target.clientHeight + target.scrollTop === target.scrollHeight;
      if (hasNext && fetchMore) {
        memberQuery.next().then(o => {
          setMembers([...members, ...o]);
        });
      }
    }
  }, members.map(member => /*#__PURE__*/React__default["default"].createElement(ui_UserListItem, {
    checkBox: true,
    checked: selectedMembers[member.userId],
    isOperator: (member === null || member === void 0 ? void 0 : member.role) === 'operator',
    disabled: (member === null || member === void 0 ? void 0 : member.role) === 'operator',
    onChange: event => {
      const modifiedSelectedMembers = _rollupPluginBabelHelpers._objectSpread2(_rollupPluginBabelHelpers._objectSpread2({}, selectedMembers), {}, {
        [event.target.id]: event.target.checked
      });
      if (!event.target.checked) {
        delete modifiedSelectedMembers[event.target.id];
      }
      setSelectedMembers(modifiedSelectedMembers);
    },
    user: member,
    key: member.userId
  })))));
}

const OperatorList = () => {
  var _state$config;
  const [operators, setOperators] = React.useState([]);
  const [showMore, setShowMore] = React.useState(false);
  const [showAdd, setShowAdd] = React.useState(false);
  const [hasNext, setHasNext] = React.useState(false);
  const {
    stringSet
  } = React.useContext(LocalizationContext.LocalizationContext);
  const state = useSendbirdStateContext();
  const {
    channel
  } = ChannelSettings_context.useChannelSettingsContext();
  const userId = state === null || state === void 0 ? void 0 : (_state$config = state.config) === null || _state$config === void 0 ? void 0 : _state$config.userId;
  React.useEffect(() => {
    if (!channel) {
      setOperators([]);
      return;
    }
    const operatorListQuery = channel === null || channel === void 0 ? void 0 : channel.createOperatorListQuery({
      limit: 10
    });
    operatorListQuery.next().then(operators => {
      setOperators(operators);
      setHasNext(operatorListQuery.hasNext);
    });
  }, [channel]);
  const refreshList = React.useCallback(() => {
    if (!channel) {
      setOperators([]);
      return;
    }
    const operatorListQuery = channel === null || channel === void 0 ? void 0 : channel.createOperatorListQuery({
      limit: 10
    });
    operatorListQuery.next().then(operators => {
      setOperators(operators);
      setHasNext(operatorListQuery.hasNext);
    });
  }, [channel]);
  return /*#__PURE__*/React__default["default"].createElement(React__default["default"].Fragment, null, operators.map(operator => /*#__PURE__*/React__default["default"].createElement(ChannelSettings_components_UserListItem, {
    key: operator.userId,
    user: operator,
    currentUser: userId,
    action: _ref => {
      let {
        actionRef
      } = _ref;
      if ((operator === null || operator === void 0 ? void 0 : operator.userId) === userId) {
        return null;
      }
      return /*#__PURE__*/React__default["default"].createElement(ui_ContextMenu["default"], {
        menuTrigger: toggleDropdown => /*#__PURE__*/React__default["default"].createElement(ui_IconButton, {
          className: "sendbird-user-message__more__menu",
          width: "32px",
          height: "32px",
          onClick: toggleDropdown
        }, /*#__PURE__*/React__default["default"].createElement(ui_Icon["default"], {
          width: "24px",
          height: "24px",
          type: ui_Icon.IconTypes.MORE,
          fillColor: ui_Icon.IconColors.CONTENT_INVERSE
        })),
        menuItems: closeDropdown => /*#__PURE__*/React__default["default"].createElement(ui_ContextMenu.MenuItems, {
          parentRef: actionRef,
          closeDropdown: closeDropdown,
          openLeft: true
        }, /*#__PURE__*/React__default["default"].createElement(ui_ContextMenu.MenuItem, {
          onClick: () => {
            channel === null || channel === void 0 ? void 0 : channel.removeOperators([operator.userId]).then(() => {
              setOperators(operators.filter(_ref2 => {
                let {
                  userId
                } = _ref2;
                return userId !== operator.userId;
              }));
            });
            closeDropdown();
          },
          dataSbId: "channel_setting_operator_context_menu_unregister_operator"
        }, stringSet.CHANNEL_SETTING__MODERATION__UNREGISTER_OPERATOR))
      });
    }
  })), /*#__PURE__*/React__default["default"].createElement("div", {
    className: "sendbird-channel-settings-accordion__footer"
  }, /*#__PURE__*/React__default["default"].createElement(ui_Button["default"], {
    type: ui_Button.ButtonTypes.SECONDARY,
    size: ui_Button.ButtonSizes.SMALL,
    onClick: () => {
      setShowAdd(true);
    }
  }, stringSet.CHANNEL_SETTING__OPERATORS__TITLE_ADD), hasNext && /*#__PURE__*/React__default["default"].createElement(ui_Button["default"], {
    type: ui_Button.ButtonTypes.SECONDARY,
    size: ui_Button.ButtonSizes.SMALL,
    onClick: () => {
      setShowMore(true);
    }
  }, stringSet.CHANNEL_SETTING__OPERATORS__TITLE_ALL)), showMore && /*#__PURE__*/React__default["default"].createElement(OperatorsModal, {
    onCancel: () => {
      setShowMore(false);
      refreshList();
    }
  }), showAdd && /*#__PURE__*/React__default["default"].createElement(AddOperatorsModal, {
    onCancel: () => setShowAdd(false),
    onSubmit: () => {
      refreshList();
      setShowAdd(false);
    }
  }));
};

function BannedUsersModal(_ref) {
  let {
    onCancel
  } = _ref;
  const [members, setMembers] = React.useState([]);
  const [memberQuery, setMemberQuery] = React.useState(null);
  const {
    channel
  } = ChannelSettings_context.useChannelSettingsContext();
  const {
    stringSet
  } = LocalizationContext.useLocalization();
  React.useEffect(() => {
    const bannedUserListQuery = channel === null || channel === void 0 ? void 0 : channel.createBannedUserListQuery();
    bannedUserListQuery.next().then(users => {
      setMembers(users);
    });
    setMemberQuery(bannedUserListQuery);
  }, []);
  return /*#__PURE__*/React__default["default"].createElement("div", null, /*#__PURE__*/React__default["default"].createElement(ui_Modal["default"], {
    isFullScreenOnMobile: true,
    hideFooter: true,
    onCancel: () => onCancel(),
    onSubmit: utils.noop,
    titleText: stringSet.CHANNEL_SETTING__MUTED_MEMBERS__TITLE
  }, /*#__PURE__*/React__default["default"].createElement("div", {
    className: "sendbird-more-members__popup-scroll",
    onScroll: e => {
      const {
        hasNext
      } = memberQuery;
      const target = e.target;
      const fetchMore = target.clientHeight + target.scrollTop === target.scrollHeight;
      if (hasNext && fetchMore) {
        memberQuery.next().then(o => {
          setMembers([...members, ...o]);
        });
      }
    }
  }, members.map(member => /*#__PURE__*/React__default["default"].createElement(ui_UserListItem, {
    user: member,
    key: member.userId,
    action: _ref2 => {
      let {
        parentRef,
        actionRef
      } = _ref2;
      return /*#__PURE__*/React__default["default"].createElement(ui_ContextMenu["default"], {
        menuTrigger: toggleDropdown => /*#__PURE__*/React__default["default"].createElement(ui_IconButton, {
          className: "sendbird-user-message__more__menu",
          width: "32px",
          height: "32px",
          onClick: toggleDropdown
        }, /*#__PURE__*/React__default["default"].createElement(ui_Icon["default"], {
          width: "24px",
          height: "24px",
          type: ui_Icon.IconTypes.MORE,
          fillColor: ui_Icon.IconColors.CONTENT_INVERSE
        })),
        menuItems: closeDropdown => /*#__PURE__*/React__default["default"].createElement(ui_ContextMenu.MenuItems, {
          parentContainRef: parentRef,
          parentRef: actionRef // for catching location(x, y) of MenuItems
          ,
          closeDropdown: closeDropdown,
          openLeft: true
        }, /*#__PURE__*/React__default["default"].createElement(ui_ContextMenu.MenuItem, {
          onClick: () => {
            channel === null || channel === void 0 ? void 0 : channel.unbanUser(member).then(() => {
              closeDropdown();
              setMembers(members.filter(m => {
                return m.userId !== member.userId;
              }));
            });
          },
          dataSbId: "channel_setting_banned_user_context_menu_ban"
        }, stringSet.CHANNEL_SETTING__MODERATION__BAN))
      });
    }
  })))));
}

const BannedMemberList = () => {
  const [members, setMembers] = React.useState([]);
  const [hasNext, setHasNext] = React.useState(false);
  const [showModal, setShowModal] = React.useState(false);
  const {
    stringSet
  } = React.useContext(LocalizationContext.LocalizationContext);
  const {
    channel
  } = ChannelSettings_context.useChannelSettingsContext();
  const bannedUserListQueryParams = {
    limit: 10
  };
  React.useEffect(() => {
    if (!channel) {
      setMembers([]);
      return;
    }
    const bannedUserListQuery = channel === null || channel === void 0 ? void 0 : channel.createBannedUserListQuery(bannedUserListQueryParams);
    bannedUserListQuery.next().then(users => {
      setMembers(users);
      setHasNext(bannedUserListQuery.hasNext);
    });
  }, [channel]);
  const refreshList = React.useCallback(() => {
    if (!channel) {
      setMembers([]);
      return;
    }
    const bannedUserListQuery = channel === null || channel === void 0 ? void 0 : channel.createBannedUserListQuery(bannedUserListQueryParams);
    bannedUserListQuery.next().then(users => {
      setMembers(users);
      setHasNext(bannedUserListQuery.hasNext);
    });
  }, [channel]);
  return /*#__PURE__*/React__default["default"].createElement(React__default["default"].Fragment, null, members.map(member => /*#__PURE__*/React__default["default"].createElement(ChannelSettings_components_UserListItem, {
    key: member.userId,
    user: member,
    action: _ref => {
      let {
        actionRef,
        parentRef
      } = _ref;
      return /*#__PURE__*/React__default["default"].createElement(ui_ContextMenu["default"], {
        menuTrigger: toggleDropdown => /*#__PURE__*/React__default["default"].createElement(ui_IconButton, {
          className: "sendbird-user-message__more__menu",
          width: "32px",
          height: "32px",
          onClick: toggleDropdown
        }, /*#__PURE__*/React__default["default"].createElement(ui_Icon["default"], {
          width: "24px",
          height: "24px",
          type: ui_Icon.IconTypes.MORE,
          fillColor: ui_Icon.IconColors.CONTENT_INVERSE
        })),
        menuItems: closeDropdown => /*#__PURE__*/React__default["default"].createElement(ui_ContextMenu.MenuItems, {
          parentContainRef: parentRef,
          parentRef: actionRef // for catching location(x, y) of MenuItems
          ,
          closeDropdown: closeDropdown,
          openLeft: true
        }, /*#__PURE__*/React__default["default"].createElement(ui_ContextMenu.MenuItem, {
          onClick: () => {
            channel === null || channel === void 0 ? void 0 : channel.unbanUser(member).then(() => {
              closeDropdown();
              refreshList();
            });
          },
          dataSbId: "channel_setting_banned_user_context_menu_unban"
        }, stringSet.CHANNEL_SETTING__MODERATION__UNBAN))
      });
    }
  })), members && members.length === 0 && /*#__PURE__*/React__default["default"].createElement(ui_Label.Label, {
    className: "sendbird-channel-settings__empty-list",
    type: ui_Label.LabelTypography.SUBTITLE_2,
    color: ui_Label.LabelColors.ONBACKGROUND_3
  }, stringSet.CHANNEL_SETTING__MODERATION__EMPTY_BAN), hasNext && /*#__PURE__*/React__default["default"].createElement("div", {
    className: "sendbird-channel-settings-accordion__footer"
  }, /*#__PURE__*/React__default["default"].createElement(ui_Button["default"], {
    type: ui_Button.ButtonTypes.SECONDARY,
    size: ui_Button.ButtonSizes.SMALL,
    onClick: () => {
      setShowModal(true);
    }
  }, stringSet.CHANNEL_SETTING__MODERATION__ALL_BAN)), showModal && /*#__PURE__*/React__default["default"].createElement(BannedUsersModal, {
    onCancel: () => {
      setShowModal(false);
      refreshList();
    }
  }));
};

function MutedMembersModal(_ref) {
  var _state$config;
  let {
    onCancel
  } = _ref;
  const [members, setMembers] = React.useState([]);
  const [memberQuery, setMemberQuery] = React.useState(null);
  const {
    channel
  } = ChannelSettings_context.useChannelSettingsContext();
  const state = useSendbirdStateContext();
  const currentUser = state === null || state === void 0 ? void 0 : (_state$config = state.config) === null || _state$config === void 0 ? void 0 : _state$config.userId;
  const {
    stringSet
  } = LocalizationContext.useLocalization();
  React.useEffect(() => {
    const memberUserListQuery = channel === null || channel === void 0 ? void 0 : channel.createMemberListQuery({
      limit: 10,
      // @ts-ignore
      mutedMemberFilter: 'muted'
    });
    memberUserListQuery.next().then(members => {
      setMembers(members);
    });
    setMemberQuery(memberUserListQuery);
  }, []);
  return /*#__PURE__*/React__default["default"].createElement("div", null, /*#__PURE__*/React__default["default"].createElement(ui_Modal["default"], {
    isFullScreenOnMobile: true,
    hideFooter: true,
    onCancel: () => onCancel(),
    onSubmit: utils.noop,
    titleText: stringSet.CHANNEL_SETTING__MUTED_MEMBERS__TITLE
  }, /*#__PURE__*/React__default["default"].createElement("div", {
    className: "sendbird-more-members__popup-scroll",
    onScroll: e => {
      const {
        hasNext
      } = memberQuery;
      const target = e.target;
      const fetchMore = target.clientHeight + target.scrollTop === target.scrollHeight;
      if (hasNext && fetchMore) {
        memberQuery.next().then(o => {
          setMembers([...members, ...o]);
        });
      }
    }
  }, members.map(member => /*#__PURE__*/React__default["default"].createElement(ui_UserListItem, {
    currentUser: currentUser,
    user: member,
    key: member.userId,
    action: _ref2 => {
      let {
        actionRef,
        parentRef
      } = _ref2;
      return /*#__PURE__*/React__default["default"].createElement(ui_ContextMenu["default"], {
        menuTrigger: toggleDropdown => /*#__PURE__*/React__default["default"].createElement(ui_IconButton, {
          className: "sendbird-user-message__more__menu",
          width: "32px",
          height: "32px",
          onClick: toggleDropdown
        }, /*#__PURE__*/React__default["default"].createElement(ui_Icon["default"], {
          width: "24px",
          height: "24px",
          type: ui_Icon.IconTypes.MORE,
          fillColor: ui_Icon.IconColors.CONTENT_INVERSE
        })),
        menuItems: closeDropdown => /*#__PURE__*/React__default["default"].createElement(ui_ContextMenu.MenuItems, {
          parentContainRef: parentRef,
          parentRef: actionRef // for catching location(x, y) of MenuItems
          ,
          closeDropdown: closeDropdown,
          openLeft: true
        }, /*#__PURE__*/React__default["default"].createElement(ui_ContextMenu.MenuItem, {
          onClick: () => {
            channel === null || channel === void 0 ? void 0 : channel.unmuteUser(member).then(() => {
              closeDropdown();
              setMembers(members.filter(m => {
                return m.userId !== member.userId;
              }));
            });
          },
          dataSbId: "channel_setting_muted_member_context_menu_unmute"
        }, stringSet.CHANNEL_SETTING__MODERATION__UNMUTE))
      });
    }
  })))));
}

const MutedMemberList = () => {
  var _state$config;
  const [members, setMembers] = React.useState([]);
  const [hasNext, setHasNext] = React.useState(false);
  const [showModal, setShowModal] = React.useState(false);
  const {
    stringSet
  } = LocalizationContext.useLocalization();
  const {
    channel
  } = ChannelSettings_context.useChannelSettingsContext();
  const state = useSendbirdStateContext();
  const currentUser = state === null || state === void 0 ? void 0 : (_state$config = state.config) === null || _state$config === void 0 ? void 0 : _state$config.userId;
  React.useEffect(() => {
    if (!channel) {
      setMembers([]);
      return;
    }
    const memberUserListQuery = channel === null || channel === void 0 ? void 0 : channel.createMemberListQuery({
      limit: 10,
      // @ts-ignore
      mutedMemberFilter: 'muted'
    });
    memberUserListQuery.next().then(members => {
      setMembers(members);
      setHasNext(memberUserListQuery.hasNext);
    });
  }, [channel]);
  const refreshList = React.useCallback(() => {
    if (!channel) {
      setMembers([]);
      return;
    }
    const memberUserListQuery = channel === null || channel === void 0 ? void 0 : channel.createMemberListQuery({
      limit: 10,
      // @ts-ignore
      mutedMemberFilter: 'muted'
    });
    memberUserListQuery.next().then(members => {
      setMembers(members);
      setHasNext(memberUserListQuery.hasNext);
    });
  }, [channel]);
  return /*#__PURE__*/React__default["default"].createElement(React__default["default"].Fragment, null, members.map(member => /*#__PURE__*/React__default["default"].createElement(ChannelSettings_components_UserListItem, {
    key: member.userId,
    user: member,
    currentUser: currentUser,
    action: _ref => {
      let {
        actionRef,
        parentRef
      } = _ref;
      return /*#__PURE__*/React__default["default"].createElement(ui_ContextMenu["default"], {
        menuTrigger: toggleDropdown => /*#__PURE__*/React__default["default"].createElement(ui_IconButton, {
          className: "sendbird-user-message__more__menu",
          width: "32px",
          height: "32px",
          onClick: toggleDropdown
        }, /*#__PURE__*/React__default["default"].createElement(ui_Icon["default"], {
          width: "24px",
          height: "24px",
          type: ui_Icon.IconTypes.MORE,
          fillColor: ui_Icon.IconColors.CONTENT_INVERSE
        })),
        menuItems: closeDropdown => /*#__PURE__*/React__default["default"].createElement(ui_ContextMenu.MenuItems, {
          closeDropdown: closeDropdown,
          openLeft: true,
          parentContainRef: parentRef,
          parentRef: actionRef // for catching location(x, y) of MenuItems
        }, /*#__PURE__*/React__default["default"].createElement(ui_ContextMenu.MenuItem, {
          onClick: () => {
            channel === null || channel === void 0 ? void 0 : channel.unmuteUser(member).then(() => {
              refreshList();
              closeDropdown();
            });
          },
          dataSbId: "channel_setting_muted_member_context_menu_unmute"
        }, (stringSet === null || stringSet === void 0 ? void 0 : stringSet.CHANNEL_SETTING__UNMUTE) || stringSet.CHANNEL_SETTING__MODERATION__UNMUTE))
      });
    }
  })), members && members.length === 0 && /*#__PURE__*/React__default["default"].createElement(ui_Label.Label, {
    className: "sendbird-channel-settings__empty-list",
    type: ui_Label.LabelTypography.SUBTITLE_2,
    color: ui_Label.LabelColors.ONBACKGROUND_3
  }, stringSet.CHANNEL_SETTING__NO_UNMUTED), hasNext && /*#__PURE__*/React__default["default"].createElement("div", {
    className: "sendbird-channel-settings-accordion__footer"
  }, /*#__PURE__*/React__default["default"].createElement(ui_Button["default"], {
    type: ui_Button.ButtonTypes.SECONDARY,
    size: ui_Button.ButtonSizes.SMALL,
    onClick: () => {
      setShowModal(true);
    }
  }, stringSet.CHANNEL_SETTING__MUTED_MEMBERS__TITLE_ALL)), showModal && /*#__PURE__*/React__default["default"].createElement(MutedMembersModal, {
    onCancel: () => {
      setShowModal(false);
      refreshList();
    }
  }));
};

const kFormatter = num => {
  return Math.abs(num) > 999 ? `${(Math.abs(num) / 1000).toFixed(1)}K` : num;
};
function AdminPannel() {
  const [frozen, setFrozen] = React.useState(false);
  const {
    stringSet
  } = React.useContext(LocalizationContext.LocalizationContext);
  const {
    channel
  } = ChannelSettings_context.useChannelSettingsContext();

  // work around for
  // https://sendbird.slack.com/archives/G01290GCDCN/p1595922832000900
  // SDK bug - after frozen/unfrozen myRole becomes "none"
  React.useEffect(() => {
    setFrozen(channel === null || channel === void 0 ? void 0 : channel.isFrozen);
  }, [channel]);
  return /*#__PURE__*/React__default["default"].createElement(ui_Accordion.AccordionGroup, {
    className: "sendbird-channel-settings__operator"
  }, /*#__PURE__*/React__default["default"].createElement(ui_Accordion["default"], {
    className: "sendbird-channel-settings__operators-list",
    id: "operators",
    renderTitle: () => /*#__PURE__*/React__default["default"].createElement(React__default["default"].Fragment, null, /*#__PURE__*/React__default["default"].createElement(ui_Icon["default"], {
      type: ui_Icon.IconTypes.OPERATOR,
      fillColor: ui_Icon.IconColors.PRIMARY,
      width: 24,
      height: 24,
      className: "sendbird-channel-settings__accordion-icon"
    }), /*#__PURE__*/React__default["default"].createElement(ui_Label.Label, {
      type: ui_Label.LabelTypography.SUBTITLE_1,
      color: ui_Label.LabelColors.ONBACKGROUND_1
    }, stringSet.CHANNEL_SETTING__OPERATORS__TITLE)),
    renderContent: () => /*#__PURE__*/React__default["default"].createElement(React__default["default"].Fragment, null, /*#__PURE__*/React__default["default"].createElement(OperatorList, null))
  }), /*#__PURE__*/React__default["default"].createElement(ui_Accordion["default"], {
    className: "sendbird-channel-settings__members-list",
    id: "members",
    renderTitle: () => /*#__PURE__*/React__default["default"].createElement(React__default["default"].Fragment, null, /*#__PURE__*/React__default["default"].createElement(ui_Icon["default"], {
      type: ui_Icon.IconTypes.MEMBERS,
      fillColor: ui_Icon.IconColors.PRIMARY,
      width: 24,
      height: 24,
      className: "sendbird-channel-settings__accordion-icon"
    }), /*#__PURE__*/React__default["default"].createElement(ui_Label.Label, {
      type: ui_Label.LabelTypography.SUBTITLE_1,
      color: ui_Label.LabelColors.ONBACKGROUND_1
    }, stringSet.CHANNEL_SETTING__MEMBERS__TITLE), /*#__PURE__*/React__default["default"].createElement(ui_Badge, {
      count: kFormatter(channel === null || channel === void 0 ? void 0 : channel.memberCount)
    })),
    renderContent: () => /*#__PURE__*/React__default["default"].createElement(React__default["default"].Fragment, null, /*#__PURE__*/React__default["default"].createElement(MemberList.MemberList, null))
  }),
  // No muted members in broadcast channel
  !(channel !== null && channel !== void 0 && channel.isBroadcast) && /*#__PURE__*/React__default["default"].createElement(ui_Accordion["default"], {
    id: "mutedMembers",
    className: "sendbird-channel-settings__muted-members-list",
    renderTitle: () => /*#__PURE__*/React__default["default"].createElement(React__default["default"].Fragment, null, /*#__PURE__*/React__default["default"].createElement(ui_Icon["default"], {
      type: ui_Icon.IconTypes.MUTE,
      fillColor: ui_Icon.IconColors.PRIMARY,
      width: 24,
      height: 24,
      className: "sendbird-channel-settings__accordion-icon"
    }), /*#__PURE__*/React__default["default"].createElement(ui_Label.Label, {
      type: ui_Label.LabelTypography.SUBTITLE_1,
      color: ui_Label.LabelColors.ONBACKGROUND_1
    }, stringSet.CHANNEL_SETTING__MUTED_MEMBERS__TITLE)),
    renderContent: () => /*#__PURE__*/React__default["default"].createElement(React__default["default"].Fragment, null, /*#__PURE__*/React__default["default"].createElement(MutedMemberList, null))
  }), /*#__PURE__*/React__default["default"].createElement(ui_Accordion["default"], {
    className: "sendbird-channel-settings__banned-members-list",
    id: "bannedUsers",
    renderTitle: () => /*#__PURE__*/React__default["default"].createElement(React__default["default"].Fragment, null, /*#__PURE__*/React__default["default"].createElement(ui_Icon["default"], {
      type: ui_Icon.IconTypes.BAN,
      fillColor: ui_Icon.IconColors.PRIMARY,
      width: 24,
      height: 24,
      className: "sendbird-channel-settings__accordion-icon"
    }), /*#__PURE__*/React__default["default"].createElement(ui_Label.Label, {
      type: ui_Label.LabelTypography.SUBTITLE_1,
      color: ui_Label.LabelColors.ONBACKGROUND_1
    }, stringSet.CHANNEL_SETTING__BANNED_MEMBERS__TITLE)),
    renderContent: () => /*#__PURE__*/React__default["default"].createElement(React__default["default"].Fragment, null, /*#__PURE__*/React__default["default"].createElement(BannedMemberList, null))
  }),
  // cannot freeze broadcast channel
  !(channel !== null && channel !== void 0 && channel.isBroadcast) && /*#__PURE__*/React__default["default"].createElement("div", {
    className: "sendbird-channel-settings__freeze"
  }, /*#__PURE__*/React__default["default"].createElement(ui_Icon["default"], {
    type: ui_Icon.IconTypes.FREEZE,
    fillColor: ui_Icon.IconColors.PRIMARY,
    width: 24,
    height: 24,
    className: "sendbird-channel-settings__accordion-icon"
  }), /*#__PURE__*/React__default["default"].createElement(ui_Label.Label, {
    type: ui_Label.LabelTypography.SUBTITLE_1,
    color: ui_Label.LabelColors.ONBACKGROUND_1
  }, stringSet.CHANNEL_SETTING__FREEZE_CHANNEL), /*#__PURE__*/React__default["default"].createElement(ui_Toggle.Toggle, {
    className: "sendbird-channel-settings__frozen-icon",
    checked: frozen,
    onChange: () => {
      if (frozen) {
        channel === null || channel === void 0 ? void 0 : channel.unfreeze().then(() => {
          setFrozen(prev => !prev);
        });
      } else {
        channel === null || channel === void 0 ? void 0 : channel.freeze().then(() => {
          setFrozen(prev => !prev);
        });
      }
    }
  })));
}

module.exports = AdminPannel;
//# sourceMappingURL=ModerationPanel.js.map
