'use strict';

Object.defineProperty(exports, '__esModule', { value: true });

var React = require('react');
var LocalizationContext = require('../../LocalizationContext-bc6af64a.js');
var ui_Label = require('../../index-902525e0.js');
var ui_Icon = require('../../ui/Icon.js');
var OpenChannelSettings_context = require('../context.js');
var OpenChannelSettings_components_OpenChannelProfile = require('./OpenChannelProfile.js');
var ui_Modal = require('../../ui/Modal.js');
var useSendbirdStateContext = require('../../useSendbirdStateContext.js');
var OpenChannelSettings_components_ParticipantUI = require('../../index-9410b034.js');
var ui_Accordion = require('../../ui/Accordion.js');
var ui_Button = require('../../ui/Button.js');
var ui_ContextMenu = require('../../ui/ContextMenu.js');
var ui_IconButton = require('../../ui/IconButton.js');
var ui_UserListItem = require('../../ui/UserListItem.js');
var _rollupPluginBabelHelpers = require('../../_rollupPluginBabelHelpers-00480ba8.js');
var utils = require('../../utils-89c82b6d.js');
require('../../stringSet-812981b5.js');
require('../../index-c08c7ef8.js');
require('prop-types');
require('@sendbird/chat/openChannel');
require('../../UserProfileContext-268ad0d1.js');
require('../../uuid-43555bb8.js');
require('../../withSendbird.js');
require('../../ui/TextButton.js');
require('../../color-41ee42a1.js');
require('../../ui/OpenChannelAvatar.js');
require('../../ui/Avatar.js');
require('../../ui/ImageRenderer.js');
require('../../utils-631cf823.js');
require('./EditDetailsModal.js');
require('../../topics-623a82c5.js');
require('../../ui/Input.js');
require('react-dom');
require('../../index-09573a50.js');
require('../../MediaQueryContext-8be571f9.js');
require('../../context-1b39c79a.js');
require('../../ui/MutedAvatarOverlay.js');
require('../../ui/UserProfile.js');
require('../../sendbirdSelectors.js');
require('../../ui/AccordionGroup.js');
require('../../ui/SortByRow.js');
require('../../index-609a0bf5.js');
require('../../utils/message/getOutgoingMessageState.js');
require('../../ui/Checkbox.js');

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

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

function DeleteChannel() {
  var _globalState$config, _globalState$config2;
  const [showDeleteChannelModal, setShowDeleteChannelModal] = React.useState(false);
  const {
    stringSet
  } = React.useContext(LocalizationContext.LocalizationContext);
  const globalState = useSendbirdStateContext();
  const isOnline = globalState === null || globalState === void 0 ? void 0 : (_globalState$config = globalState.config) === null || _globalState$config === void 0 ? void 0 : _globalState$config.isOnline;
  const logger = globalState === null || globalState === void 0 ? void 0 : (_globalState$config2 = globalState.config) === null || _globalState$config2 === void 0 ? void 0 : _globalState$config2.logger;
  const {
    channel,
    onDeleteChannel
  } = OpenChannelSettings_context.useOpenChannelSettingsContext();
  const deleteChannel = () => {
    channel === null || channel === void 0 ? void 0 : channel.delete().then(response => {
      logger.info('OpenChannelSettings: Delete channel success', response);
      if (onDeleteChannel) {
        onDeleteChannel(channel);
      }
    }).catch(error => {
      logger.warning('OpenChannelSettings: Delete channel failed', error);
    });
  };
  return /*#__PURE__*/React__default["default"].createElement(React__default["default"].Fragment, null, /*#__PURE__*/React__default["default"].createElement("div", {
    className: `sendbird-openchannel-settings__panel-item
          sendbird-openchannel-settings__delete-channel
            ${!isOnline ? 'sendbird-openchannel-settings__panel-item__disabled' : ''}`,
    role: "button",
    tabIndex: 0,
    onKeyDown: () => {
      if (!isOnline) {
        return;
      }
      setShowDeleteChannelModal(true);
    },
    onClick: () => {
      if (!isOnline) {
        return;
      }
      setShowDeleteChannelModal(true);
    }
  }, /*#__PURE__*/React__default["default"].createElement(ui_Icon["default"], {
    type: ui_Icon.IconTypes.DELETE,
    fillColor: ui_Icon.IconColors.ERROR,
    className: ['sendbird-openchannel-settings__panel-icon-left', 'sendbird-openchannel-settings__panel-icon__delete'].join(' '),
    height: "24px",
    width: "24px"
  }), /*#__PURE__*/React__default["default"].createElement(ui_Label.Label, {
    type: ui_Label.LabelTypography.SUBTITLE_1,
    color: ui_Label.LabelColors.ONBACKGROUND_1
  }, stringSet.OPEN_CHANNEL_SETTINGS__DELETE_CHANNEL_PANEL)), showDeleteChannelModal && /*#__PURE__*/React__default["default"].createElement(ui_Modal["default"], {
    isFullScreenOnMobile: true,
    onCancel: () => {
      setShowDeleteChannelModal(false);
    },
    onSubmit: () => {
      deleteChannel();
    },
    titleText: stringSet.OPEN_CHANNEL_SETTINGS__DELETE_CHANNEL_TITLE,
    submitText: stringSet.OPEN_CHANNEL_SETTINGS__DELETE_CHANNEL_SUBMIT
  }, stringSet.OPEN_CHANNEL_SETTINGS__DELETE_CHANNEL_CONTEXT));
}

function OperatorListModal(_ref) {
  var _state$config;
  let {
    onCancel
  } = _ref;
  const [users, setUsers] = React.useState([]);
  const [operatorQuery, setOperatorQuery] = React.useState(null);
  const {
    channel
  } = OpenChannelSettings_context.useOpenChannelSettingsContext();
  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(participants => {
      setUsers(participants);
    });
    setOperatorQuery(operatorListQuery);
  }, []);
  return /*#__PURE__*/React__default["default"].createElement("div", null, /*#__PURE__*/React__default["default"].createElement(ui_Modal["default"], {
    hideFooter: true,
    isFullScreenOnMobile: true,
    titleText: stringSet.OPEN_CHANNEL_SETTINGS__OPERATORS__TITLE_ALL,
    onCancel: onCancel
  }, /*#__PURE__*/React__default["default"].createElement("div", {
    className: "sendbird-more-users__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 => {
          setUsers([...users, ...o]);
        });
      }
    }
  }, users.map(operator => /*#__PURE__*/React__default["default"].createElement(ui_UserListItem, {
    currentUser: currentUserId,
    user: operator,
    key: operator.userId,
    action: _ref2 => {
      let {
        parentRef,
        actionRef
      } = _ref2;
      return currentUserId !== (operator === null || operator === void 0 ? void 0 : operator.userId) ? /*#__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,
          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(() => {
              setUsers(users.filter(_ref3 => {
                let {
                  userId
                } = _ref3;
                return userId !== operator.userId;
              }));
            });
            closeDropdown();
          },
          dataSbId: "open_channel_setting_operator_context_menu_unregister_operator"
        }, stringSet.OPEN_CHANNEL_SETTING__MODERATION__UNREGISTER_OPERATOR))
      }) : null;
    }
  })))));
}

function AddOperatorsModal(_ref) {
  let {
    onCancel,
    onSubmit
  } = _ref;
  const [participants, setParticipants] = React.useState([]);
  const [selectedUsers, setSelectedUsers] = React.useState({});
  const [participantQuery, setParticipantQuery] = React.useState(null);
  const {
    stringSet
  } = React.useContext(LocalizationContext.LocalizationContext);
  const {
    channel
  } = OpenChannelSettings_context.useOpenChannelSettingsContext();
  React.useEffect(() => {
    const participantListQuery = channel === null || channel === void 0 ? void 0 : channel.createParticipantListQuery({
      limit: 20
    });
    participantListQuery.next().then(users => {
      setParticipants(users);
    });
    setParticipantQuery(participantListQuery);
  }, []);
  const selectedCount = Object.keys(selectedUsers).filter(m => selectedUsers[m]).length;
  return /*#__PURE__*/React__default["default"].createElement(React__default["default"].Fragment, 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 users = Object.keys(selectedUsers).filter(m => selectedUsers[m]);
      channel === null || channel === void 0 ? void 0 : channel.addOperators(users).then(() => {
        onSubmit(users);
      });
    },
    titleText: stringSet.OPEN_CHANNEL_CONVERSATION__SELECT_PARTICIPANTS
  }, /*#__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-users__popup-scroll",
    onScroll: e => {
      const {
        hasNext
      } = participantQuery;
      const target = e.target;
      const fetchMore = target.clientHeight + target.scrollTop === target.scrollHeight;
      if (hasNext && fetchMore) {
        participantQuery.next().then(o => {
          setParticipants([...participants, ...o]);
        });
      }
    }
  }, participants.map(participant => {
    const isOperator = channel !== null && channel !== void 0 && channel.operators.find(operator => (operator === null || operator === void 0 ? void 0 : operator.userId) === (participant === null || participant === void 0 ? void 0 : participant.userId)) ? true : false;
    return /*#__PURE__*/React__default["default"].createElement(ui_UserListItem, {
      checkBox: true,
      checked: selectedUsers[participant.userId] || isOperator,
      disabled: isOperator,
      isOperator: isOperator,
      onChange: event => {
        const modifiedSelectedUsers = _rollupPluginBabelHelpers._objectSpread2(_rollupPluginBabelHelpers._objectSpread2({}, selectedUsers), {}, {
          [event.target.id]: event.target.checked
        });
        if (!event.target.checked) {
          delete modifiedSelectedUsers[event.target.id];
        }
        setSelectedUsers(modifiedSelectedUsers);
      },
      user: participant,
      key: participant.userId
    });
  }))));
}

const OperatorList = () => {
  var _state$config, _channel$operators, _channel$operators2;
  const [showAdd, setShowAdd] = React.useState(false);
  const [showMore, setShowMore] = React.useState(false);
  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);
  const {
    channel
  } = OpenChannelSettings_context.useOpenChannelSettingsContext();
  return /*#__PURE__*/React__default["default"].createElement("div", null, channel === null || channel === void 0 ? void 0 : (_channel$operators = channel.operators) === null || _channel$operators === void 0 ? void 0 : _channel$operators.slice(0, 10).map(operator => /*#__PURE__*/React__default["default"].createElement(OpenChannelSettings_components_ParticipantUI.UserListItem, {
    key: operator.userId,
    user: operator,
    currentUser: currentUserId,
    action: _ref => {
      let {
        actionRef
      } = _ref;
      return currentUserId !== (operator === null || operator === void 0 ? void 0 : operator.userId) ? /*#__PURE__*/React__default["default"].createElement(ui_ContextMenu["default"], {
        menuTrigger: toggleDropdown => /*#__PURE__*/React__default["default"].createElement(ui_IconButton, {
          className: "sendbird-openchannel-operator-list__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(() => {
              closeDropdown();
            });
          },
          dataSbId: "open_channel_setting_operator_context_menu_unregister_operator"
        }, stringSet.OPEN_CHANNEL_SETTING__MODERATION__UNREGISTER_OPERATOR), /*#__PURE__*/React__default["default"].createElement(ui_ContextMenu.MenuItem, {
          onClick: () => {
            if (operator.isMuted) {
              channel === null || channel === void 0 ? void 0 : channel.unmuteUser(operator).then(() => {
                closeDropdown();
              });
            } else {
              channel === null || channel === void 0 ? void 0 : channel.muteUser(operator).then(() => {
                closeDropdown();
              });
            }
          },
          dataSbId: `open_channel_setting_operator_context_menu_${operator.isMuted ? 'unmute' : 'mute'}`
        }, operator.isMuted ? stringSet.OPEN_CHANNEL_SETTING__MODERATION__UNMUTE : stringSet.OPEN_CHANNEL_SETTING__MODERATION__MUTE), /*#__PURE__*/React__default["default"].createElement(ui_ContextMenu.MenuItem, {
          onClick: () => {
            channel === null || channel === void 0 ? void 0 : channel.banUser(operator).then(() => {
              closeDropdown();
            });
          },
          dataSbId: "open_channel_setting_operator_context_menu_ban"
        }, stringSet.OPEN_CHANNEL_SETTING__MODERATION__BAN))
      }) : null;
    }
  })), /*#__PURE__*/React__default["default"].createElement("div", {
    className: "sendbird-openchannel-operator-list__footer"
  }, /*#__PURE__*/React__default["default"].createElement(ui_Button["default"], {
    type: ui_Button.ButtonTypes.SECONDARY,
    size: ui_Button.ButtonSizes.SMALL,
    onClick: () => {
      setShowAdd(true);
    }
  }, stringSet.OPEN_CHANNEL_SETTINGS__OPERATORS__TITLE_ADD), (channel === null || channel === void 0 ? void 0 : (_channel$operators2 = channel.operators) === null || _channel$operators2 === void 0 ? void 0 : _channel$operators2.length) > 10 && /*#__PURE__*/React__default["default"].createElement(ui_Button["default"], {
    type: ui_Button.ButtonTypes.SECONDARY,
    size: ui_Button.ButtonSizes.SMALL,
    onClick: () => {
      setShowMore(true);
    }
  }, stringSet.OPEN_CHANNEL_SETTINGS__OPERATORS__TITLE_ALL)), showMore && /*#__PURE__*/React__default["default"].createElement(React__default["default"].Fragment, null, /*#__PURE__*/React__default["default"].createElement(OperatorListModal, {
    onCancel: () => {
      setShowMore(false);
    }
  })), showAdd && /*#__PURE__*/React__default["default"].createElement(React__default["default"].Fragment, null, /*#__PURE__*/React__default["default"].createElement(AddOperatorsModal, {
    onCancel: () => setShowAdd(false),
    onSubmit: () => {
      setShowAdd(false);
    }
  })));
};

function MutedParticipantsModal(_ref) {
  var _state$config;
  let {
    onCancel
  } = _ref;
  const [mutedUsers, setMutedUsers] = React.useState([]);
  const [userListQuery, setUserListQuery] = React.useState(null);
  const {
    channel
  } = OpenChannelSettings_context.useOpenChannelSettingsContext();
  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 mutedUserListQuery = channel === null || channel === void 0 ? void 0 : channel.createMutedUserListQuery({
      limit: 10
    });
    mutedUserListQuery.next().then(users => {
      setMutedUsers(users);
    });
    setUserListQuery(mutedUserListQuery);
  }, []);
  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.OPEN_CHANNEL_SETTINGS__MUTED_MEMBERS__TITLE
  }, /*#__PURE__*/React__default["default"].createElement("div", {
    className: "sendbird-more-members__popup-scroll",
    onScroll: e => {
      const {
        hasNext
      } = userListQuery;
      const target = e.target;
      const fetchMore = target.clientHeight + target.scrollTop === target.scrollHeight;
      if (hasNext && fetchMore) {
        userListQuery.next().then(o => {
          setMutedUsers([...mutedUsers, ...o]);
        });
      }
    }
  }, mutedUsers.map(mutedUser => /*#__PURE__*/React__default["default"].createElement(ui_UserListItem, {
    currentUser: currentUserId,
    user: mutedUser,
    key: mutedUser.userId,
    action: _ref2 => {
      let {
        actionRef
      } = _ref2;
      return (mutedUser === null || mutedUser === void 0 ? void 0 : mutedUser.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, {
          parentRef: actionRef,
          closeDropdown: closeDropdown,
          openLeft: true
        }, /*#__PURE__*/React__default["default"].createElement(ui_ContextMenu.MenuItem, {
          onClick: () => {
            channel === null || channel === void 0 ? void 0 : channel.unmuteUser(mutedUser).then(() => {
              closeDropdown();
              setMutedUsers(mutedUsers.filter(u => {
                return u.userId !== mutedUser.userId;
              }));
            });
          },
          dataSbId: "open_channel_setting_muted_member_context_menu_unmute"
        }, stringSet.OPEN_CHANNEL_SETTING__MODERATION__UNMUTE))
      }) : null;
    }
  })))));
}

const MutedParticipantList = () => {
  var _state$config;
  const [mutedUsers, setMutedUsers] = React.useState([]);
  const [hasNext, setHasNext] = React.useState(false);
  const [showModal, setShowModal] = React.useState(false);
  const {
    channel
  } = OpenChannelSettings_context.useOpenChannelSettingsContext();
  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(() => {
    if (!channel) {
      setMutedUsers([]);
      return;
    }
    const mutedUserListQuery = channel === null || channel === void 0 ? void 0 : channel.createMutedUserListQuery({
      limit: 10
    });
    mutedUserListQuery.next().then(members => {
      setMutedUsers(members);
      setHasNext(mutedUserListQuery.hasNext);
    });
  }, [channel]);
  const refreshList = React.useCallback(() => {
    if (!channel) {
      setMutedUsers([]);
      return;
    }
    const mutedUserListQuery = channel === null || channel === void 0 ? void 0 : channel.createMutedUserListQuery({
      limit: 10
    });
    mutedUserListQuery.next().then(members => {
      setMutedUsers(members);
      setHasNext(mutedUserListQuery.hasNext);
    });
  }, [channel]);
  return /*#__PURE__*/React__default["default"].createElement(React__default["default"].Fragment, null, mutedUsers.map(mutedUser => /*#__PURE__*/React__default["default"].createElement(OpenChannelSettings_components_ParticipantUI.UserListItem, {
    key: mutedUser.userId,
    user: mutedUser,
    currentUser: currentUserId,
    isOperator: channel === null || channel === void 0 ? void 0 : channel.isOperator(mutedUser.userId),
    action: _ref => {
      let {
        actionRef
      } = _ref;
      return (mutedUser === null || mutedUser === void 0 ? void 0 : mutedUser.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, {
          closeDropdown: closeDropdown,
          openLeft: true,
          parentRef: actionRef
        }, /*#__PURE__*/React__default["default"].createElement(ui_ContextMenu.MenuItem, {
          onClick: () => {
            channel === null || channel === void 0 ? void 0 : channel.unmuteUser(mutedUser).then(() => {
              refreshList();
              closeDropdown();
            });
          },
          dataSbId: "open_channel_setting_muted_member_context_menu_unmute"
        }, stringSet.OPEN_CHANNEL_SETTING__MODERATION__UNMUTE))
      }) : null;
    }
  })), mutedUsers && mutedUsers.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.OPEN_CHANNEL_SETTINGS__MUTED_MEMBERS__NO_ONE), hasNext && /*#__PURE__*/React__default["default"].createElement("div", {
    className: "sendbird-channel-settings-muted-participant-list__footer"
  }, /*#__PURE__*/React__default["default"].createElement(ui_Button["default"], {
    type: ui_Button.ButtonTypes.SECONDARY,
    size: ui_Button.ButtonSizes.SMALL,
    onClick: () => {
      setShowModal(true);
    }
  }, stringSet.OPEN_CHANNEL_SETTINGS__MUTED_MEMBERS__TITLE_ALL)), showModal && /*#__PURE__*/React__default["default"].createElement(MutedParticipantsModal, {
    onCancel: () => {
      setShowModal(false);
      refreshList();
    }
  }));
};

function BannedUsersModal(_ref) {
  var _state$config;
  let {
    onCancel
  } = _ref;
  const [bannedUsers, setBannedUsers] = React.useState([]);
  const [userListQuery, setUserListQuery] = React.useState(null);
  const {
    channel
  } = OpenChannelSettings_context.useOpenChannelSettingsContext();
  const state = useSendbirdStateContext();
  const {
    stringSet
  } = React.useContext(LocalizationContext.LocalizationContext);
  const currentUserId = state === null || state === void 0 ? void 0 : (_state$config = state.config) === null || _state$config === void 0 ? void 0 : _state$config.userId;
  React.useEffect(() => {
    const bannedUserListQuery = channel === null || channel === void 0 ? void 0 : channel.createBannedUserListQuery();
    bannedUserListQuery.next().then(users => {
      setBannedUsers(users);
    });
    setUserListQuery(bannedUserListQuery);
  }, []);
  return /*#__PURE__*/React__default["default"].createElement("div", null, /*#__PURE__*/React__default["default"].createElement(ui_Modal["default"], {
    hideFooter: true,
    isFullScreenOnMobile: true,
    onCancel: () => onCancel(),
    onSubmit: utils.noop,
    titleText: stringSet.OPEN_CHANNEL_SETTINGS__MUTED_MEMBERS__TITLE
  }, /*#__PURE__*/React__default["default"].createElement("div", {
    className: "sendbird-more-members__popup-scroll",
    onScroll: e => {
      const {
        hasNext
      } = userListQuery;
      const target = e.target;
      const fetchMore = target.clientHeight + target.scrollTop === target.scrollHeight;
      if (hasNext && fetchMore) {
        userListQuery.next().then(o => {
          setBannedUsers([...bannedUsers, ...o]);
        });
      }
    }
  }, bannedUsers.map(bannedUser => /*#__PURE__*/React__default["default"].createElement(ui_UserListItem, {
    user: bannedUser,
    key: bannedUser.userId,
    action: _ref2 => {
      let {
        actionRef
      } = _ref2;
      return (bannedUser === null || bannedUser === void 0 ? void 0 : bannedUser.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, {
          parentRef: actionRef,
          closeDropdown: closeDropdown,
          openLeft: true
        }, /*#__PURE__*/React__default["default"].createElement(ui_ContextMenu.MenuItem, {
          onClick: () => {
            channel === null || channel === void 0 ? void 0 : channel.unbanUser(bannedUser).then(() => {
              closeDropdown();
              setBannedUsers(bannedUsers.filter(u => {
                return u.userId !== bannedUser.userId;
              }));
            });
          },
          dataSbId: "open_channel_setting_banned_user_context_menu_unban"
        }, stringSet.OPEN_CHANNEL_SETTING__MODERATION__UNBAN))
      }) : null;
    }
  })))));
}

const BannedUserList = () => {
  var _state$config;
  const [bannedUsers, setBannedUsers] = React.useState([]);
  const [hasNext, setHasNext] = React.useState(false);
  const [showModal, setShowModal] = React.useState(false);
  const {
    channel
  } = OpenChannelSettings_context.useOpenChannelSettingsContext();
  const state = useSendbirdStateContext();
  const {
    stringSet
  } = React.useContext(LocalizationContext.LocalizationContext);
  const currentUserId = 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) {
      setBannedUsers([]);
      return;
    }
    const bannedUserListQuery = channel === null || channel === void 0 ? void 0 : channel.createBannedUserListQuery();
    bannedUserListQuery.next().then(users => {
      setBannedUsers(users);
      setHasNext(bannedUserListQuery.hasNext);
    });
  }, [channel]);
  const refreshList = React.useCallback(() => {
    if (!channel) {
      setBannedUsers([]);
      return;
    }
    const bannedUserListQuery = channel === null || channel === void 0 ? void 0 : channel.createBannedUserListQuery();
    bannedUserListQuery.next().then(users => {
      setBannedUsers(users);
      setHasNext(bannedUserListQuery.hasNext);
    });
  }, [channel]);
  return /*#__PURE__*/React__default["default"].createElement(React__default["default"].Fragment, null, bannedUsers.map(bannedUser => /*#__PURE__*/React__default["default"].createElement(OpenChannelSettings_components_ParticipantUI.UserListItem, {
    key: bannedUser.userId,
    user: bannedUser,
    isOperator: channel === null || channel === void 0 ? void 0 : channel.isOperator(bannedUser.userId),
    action: _ref => {
      let {
        actionRef
      } = _ref;
      return (bannedUser === null || bannedUser === void 0 ? void 0 : bannedUser.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, {
          parentRef: actionRef,
          closeDropdown: closeDropdown,
          openLeft: true
        }, /*#__PURE__*/React__default["default"].createElement(ui_ContextMenu.MenuItem, {
          onClick: () => {
            channel === null || channel === void 0 ? void 0 : channel.unbanUser(bannedUser).then(() => {
              closeDropdown();
              refreshList();
            });
          },
          dataSbId: "open_channel_setting_banned_user_context_menu_unban"
        }, stringSet.OPEN_CHANNEL_SETTING__MODERATION__UNBAN))
      }) : null;
    }
  })), bannedUsers && bannedUsers.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.OPEN_CHANNEL_SETTINGS__BANNED_MEMBERS__NO_ONE), hasNext && /*#__PURE__*/React__default["default"].createElement("div", {
    className: "sendbird-channel-settings-banned-user-list__footer"
  }, /*#__PURE__*/React__default["default"].createElement(ui_Button["default"], {
    type: ui_Button.ButtonTypes.SECONDARY,
    size: ui_Button.ButtonSizes.SMALL,
    onClick: () => {
      setShowModal(true);
    }
  }, stringSet.OPEN_CHANNEL_SETTINGS__BANNED_MEMBERS__TITLE_ALL)), showModal && /*#__PURE__*/React__default["default"].createElement(BannedUsersModal, {
    onCancel: () => {
      setShowModal(false);
      refreshList();
    }
  }));
};

const copyToClipboard = text => {
  // @ts-ignore: Unreachable code error
  if (window.clipboardData && window.clipboardData.setData) {
    // Internet Explorer-specific code path to prevent textarea being shown while dialog is visible.
    // @ts-ignore: Unreachable code error
    return window.clipboardData.setData('Text', text);
  }
  if (document.queryCommandSupported && document.queryCommandSupported('copy')) {
    const textarea = document.createElement('textarea');
    textarea.textContent = text;
    textarea.style.position = 'fixed'; // Prevent scrolling to bottom of page in Microsoft Edge.
    document.body.appendChild(textarea);
    textarea.select();
    try {
      return document.execCommand('copy'); // Security exception may be thrown by some browsers.
    } catch (ex) {
      return false;
    } finally {
      document.body.removeChild(textarea);
    }
  }
  return false;
};
const OperatorUI = _ref => {
  let {
    renderChannelProfile
  } = _ref;
  const {
    stringSet
  } = React.useContext(LocalizationContext.LocalizationContext);
  const {
    onCloseClick,
    channel
  } = OpenChannelSettings_context.useOpenChannelSettingsContext();
  return /*#__PURE__*/React__default["default"].createElement(React__default["default"].Fragment, null, /*#__PURE__*/React__default["default"].createElement("div", {
    className: "sendbird-openchannel-settings__header"
  }, /*#__PURE__*/React__default["default"].createElement(ui_Label.Label, {
    type: ui_Label.LabelTypography.H_2,
    color: ui_Label.LabelColors.ONBACKGROUND_1
  }, stringSet.CHANNEL_SETTING__HEADER__TITLE), /*#__PURE__*/React__default["default"].createElement(ui_Icon["default"], {
    className: "sendbird-openchannel-settings__close-icon",
    type: ui_Icon.IconTypes.CLOSE,
    height: "24px",
    width: "24px",
    onClick: () => {
      onCloseClick();
    }
  })), /*#__PURE__*/React__default["default"].createElement("div", {
    className: "sendbird-openchannel-settings__profile"
  }, (renderChannelProfile === null || renderChannelProfile === void 0 ? void 0 : renderChannelProfile()) || /*#__PURE__*/React__default["default"].createElement(OpenChannelSettings_components_OpenChannelProfile, null)), /*#__PURE__*/React__default["default"].createElement("div", {
    className: "sendbird-openchannel-settings__url"
  }, /*#__PURE__*/React__default["default"].createElement(ui_Icon["default"], {
    className: "sendbird-openchannel-settings__copy-icon",
    type: ui_Icon.IconTypes.COPY,
    height: "22px",
    width: "22px",
    onClick: () => {
      copyToClipboard(channel === null || channel === void 0 ? void 0 : channel.url);
    }
  }), /*#__PURE__*/React__default["default"].createElement(ui_Label.Label, {
    className: "sendbird-openchannel-settings__url-label",
    type: ui_Label.LabelTypography.CAPTION_2,
    color: ui_Label.LabelColors.ONBACKGROUND_2
  }, stringSet.OPEN_CHANNEL_SETTINGS__OPERATOR_URL), /*#__PURE__*/React__default["default"].createElement(ui_Label.Label, {
    className: "sendbird-openchannel-settings__url-value",
    type: ui_Label.LabelTypography.SUBTITLE_2
  }, channel === null || channel === void 0 ? void 0 : channel.url)), /*#__PURE__*/React__default["default"].createElement(ui_Accordion.AccordionGroup, null, /*#__PURE__*/React__default["default"].createElement(ui_Accordion["default"], {
    className: "sendbird-openchannel-settings__operators-list",
    id: "operators",
    renderTitle: () => /*#__PURE__*/React__default["default"].createElement(React__default["default"].Fragment, null, /*#__PURE__*/React__default["default"].createElement(ui_Icon["default"], {
      className: "sendbird-openchannel-settings__operator-accordion-icon",
      type: ui_Icon.IconTypes.OPERATOR,
      fillColor: ui_Icon.IconColors.PRIMARY,
      width: "24px",
      height: "24px"
    }), /*#__PURE__*/React__default["default"].createElement(ui_Label.Label, {
      type: ui_Label.LabelTypography.SUBTITLE_1,
      color: ui_Label.LabelColors.ONBACKGROUND_1
    }, stringSet.OPEN_CHANNEL_SETTINGS__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__operators-list",
    id: "participants",
    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-openchannel-settings__operator-accordion-icon"
    }), /*#__PURE__*/React__default["default"].createElement(ui_Label.Label, {
      type: ui_Label.LabelTypography.SUBTITLE_1,
      color: ui_Label.LabelColors.ONBACKGROUND_1
    }, stringSet.OPEN_CHANNEL_SETTINGS__PARTICIPANTS_ACCORDION_TITLE)),
    renderContent: () => /*#__PURE__*/React__default["default"].createElement(React__default["default"].Fragment, null, /*#__PURE__*/React__default["default"].createElement(OpenChannelSettings_components_ParticipantUI.ParticipantList, {
      isOperatorView: true
    }))
  }), /*#__PURE__*/React__default["default"].createElement(ui_Accordion["default"], {
    className: "sendbird-channel-settings__operators-list",
    id: "mutedMembers",
    renderTitle: () => /*#__PURE__*/React__default["default"].createElement(React__default["default"].Fragment, null, /*#__PURE__*/React__default["default"].createElement(ui_Icon["default"], {
      className: "sendbird-openchannel-settings__operator-accordion-icon",
      type: ui_Icon.IconTypes.MUTE,
      fillColor: ui_Icon.IconColors.PRIMARY,
      width: "24px",
      height: "24px"
    }), /*#__PURE__*/React__default["default"].createElement(ui_Label.Label, {
      type: ui_Label.LabelTypography.SUBTITLE_1,
      color: ui_Label.LabelColors.ONBACKGROUND_1
    }, stringSet.OPEN_CHANNEL_SETTINGS__MUTED_MEMBERS__TITLE)),
    renderContent: () => /*#__PURE__*/React__default["default"].createElement(React__default["default"].Fragment, null, /*#__PURE__*/React__default["default"].createElement(MutedParticipantList, null))
  }), /*#__PURE__*/React__default["default"].createElement(ui_Accordion["default"], {
    className: "sendbird-channel-settings__operators-list",
    id: "bannedUsers",
    renderTitle: () => /*#__PURE__*/React__default["default"].createElement(React__default["default"].Fragment, null, /*#__PURE__*/React__default["default"].createElement(ui_Icon["default"], {
      className: "sendbird-openchannel-settings__operator-accordion-icon",
      type: ui_Icon.IconTypes.BAN,
      fillColor: ui_Icon.IconColors.PRIMARY,
      width: "24px",
      height: "24px"
    }), /*#__PURE__*/React__default["default"].createElement(ui_Label.Label, {
      type: ui_Label.LabelTypography.SUBTITLE_1,
      color: ui_Label.LabelColors.ONBACKGROUND_1
    }, stringSet.OPEN_CHANNEL_SETTINGS__BANNED_MEMBERS__TITLE)),
    renderContent: () => /*#__PURE__*/React__default["default"].createElement(React__default["default"].Fragment, null, /*#__PURE__*/React__default["default"].createElement(BannedUserList, null))
  })), /*#__PURE__*/React__default["default"].createElement(DeleteChannel, null));
};

exports.OperatorUI = OperatorUI;
exports.copyToClipboard = copyToClipboard;
exports["default"] = OperatorUI;
//# sourceMappingURL=OperatorUI.js.map
