import React__default, { useState, useContext, useEffect, useCallback } from 'react';
import { a as LocalizationContext } from '../../LocalizationContext-426f3d58.js';
import { L as Label, a as LabelTypography, b as LabelColors } from '../../index-4105bc4d.js';
import Icon, { IconTypes, IconColors } from '../../ui/Icon.js';
import { useOpenChannelSettingsContext } from '../context.js';
import ChannelProfile from './OpenChannelProfile.js';
import Modal from '../../ui/Modal.js';
import useSendbirdStateContext from '../../useSendbirdStateContext.js';
import { U as UserListItem$1, P as ParticipantList } from '../../index-e3135090.js';
import Accordion, { AccordionGroup } from '../../ui/Accordion.js';
import Button, { ButtonTypes, ButtonSizes } from '../../ui/Button.js';
import ContextMenu, { MenuItems, MenuItem } from '../../ui/ContextMenu.js';
import IconButton from '../../ui/IconButton.js';
import UserListItem from '../../ui/UserListItem.js';
import { _ as _objectSpread2 } from '../../_rollupPluginBabelHelpers-a69fd1ce.js';
import { n as noop } from '../../utils-4bf6e4e6.js';
import '../../stringSet-a62108b2.js';
import '../../index-90420b99.js';
import 'prop-types';
import '@sendbird/chat/openChannel';
import '../../UserProfileContext-a59f0533.js';
import '../../uuid-2e8efc75.js';
import '../../withSendbird.js';
import '../../ui/TextButton.js';
import '../../color-e708f53d.js';
import '../../ui/OpenChannelAvatar.js';
import '../../ui/Avatar.js';
import '../../ui/ImageRenderer.js';
import '../../utils-20147203.js';
import './EditDetailsModal.js';
import '../../topics-247fcf3a.js';
import '../../ui/Input.js';
import 'react-dom';
import '../../index-3e548496.js';
import '../../MediaQueryContext-b531adc9.js';
import '../../context-e98c1042.js';
import '../../ui/MutedAvatarOverlay.js';
import '../../ui/UserProfile.js';
import '../../sendbirdSelectors.js';
import '../../ui/AccordionGroup.js';
import '../../ui/SortByRow.js';
import '../../index-f83f0aac.js';
import '../../utils/message/getOutgoingMessageState.js';
import '../../ui/Checkbox.js';

function DeleteChannel() {
  var _globalState$config, _globalState$config2;
  const [showDeleteChannelModal, setShowDeleteChannelModal] = useState(false);
  const {
    stringSet
  } = useContext(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
  } = 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.createElement(React__default.Fragment, null, /*#__PURE__*/React__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.createElement(Icon, {
    type: IconTypes.DELETE,
    fillColor: IconColors.ERROR,
    className: ['sendbird-openchannel-settings__panel-icon-left', 'sendbird-openchannel-settings__panel-icon__delete'].join(' '),
    height: "24px",
    width: "24px"
  }), /*#__PURE__*/React__default.createElement(Label, {
    type: LabelTypography.SUBTITLE_1,
    color: LabelColors.ONBACKGROUND_1
  }, stringSet.OPEN_CHANNEL_SETTINGS__DELETE_CHANNEL_PANEL)), showDeleteChannelModal && /*#__PURE__*/React__default.createElement(Modal, {
    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] = useState([]);
  const [operatorQuery, setOperatorQuery] = useState(null);
  const {
    channel
  } = 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
  } = useContext(LocalizationContext);
  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.createElement("div", null, /*#__PURE__*/React__default.createElement(Modal, {
    hideFooter: true,
    isFullScreenOnMobile: true,
    titleText: stringSet.OPEN_CHANNEL_SETTINGS__OPERATORS__TITLE_ALL,
    onCancel: onCancel
  }, /*#__PURE__*/React__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.createElement(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.createElement(ContextMenu, {
        menuTrigger: toggleDropdown => /*#__PURE__*/React__default.createElement(IconButton, {
          className: "sendbird-user-message__more__menu",
          width: "32px",
          height: "32px",
          onClick: toggleDropdown
        }, /*#__PURE__*/React__default.createElement(Icon, {
          width: "24px",
          height: "24px",
          type: IconTypes.MORE,
          fillColor: IconColors.CONTENT_INVERSE
        })),
        menuItems: closeDropdown => /*#__PURE__*/React__default.createElement(MenuItems, {
          parentContainRef: parentRef,
          parentRef: actionRef,
          closeDropdown: closeDropdown,
          openLeft: true
        }, /*#__PURE__*/React__default.createElement(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] = useState([]);
  const [selectedUsers, setSelectedUsers] = useState({});
  const [participantQuery, setParticipantQuery] = useState(null);
  const {
    stringSet
  } = useContext(LocalizationContext);
  const {
    channel
  } = useOpenChannelSettingsContext();
  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.createElement(React__default.Fragment, null, /*#__PURE__*/React__default.createElement(Modal, {
    isFullScreenOnMobile: true,
    type: 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.createElement(Label, {
    color: selectedCount > 0 ? LabelColors.PRIMARY : LabelColors.ONBACKGROUND_3,
    type: LabelTypography.CAPTION_1
  }, `${selectedCount} ${stringSet.MODAL__INVITE_MEMBER__SELECTED}`), /*#__PURE__*/React__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.createElement(UserListItem, {
      checkBox: true,
      checked: selectedUsers[participant.userId] || isOperator,
      disabled: isOperator,
      isOperator: isOperator,
      onChange: event => {
        const modifiedSelectedUsers = _objectSpread2(_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] = useState(false);
  const [showMore, setShowMore] = 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
  } = useContext(LocalizationContext);
  const {
    channel
  } = useOpenChannelSettingsContext();
  return /*#__PURE__*/React__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.createElement(UserListItem$1, {
    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.createElement(ContextMenu, {
        menuTrigger: toggleDropdown => /*#__PURE__*/React__default.createElement(IconButton, {
          className: "sendbird-openchannel-operator-list__menu",
          width: "32px",
          height: "32px",
          onClick: toggleDropdown
        }, /*#__PURE__*/React__default.createElement(Icon, {
          width: "24px",
          height: "24px",
          type: IconTypes.MORE,
          fillColor: IconColors.CONTENT_INVERSE
        })),
        menuItems: closeDropdown => /*#__PURE__*/React__default.createElement(MenuItems, {
          parentRef: actionRef,
          closeDropdown: closeDropdown,
          openLeft: true
        }, /*#__PURE__*/React__default.createElement(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.createElement(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.createElement(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.createElement("div", {
    className: "sendbird-openchannel-operator-list__footer"
  }, /*#__PURE__*/React__default.createElement(Button, {
    type: ButtonTypes.SECONDARY,
    size: 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.createElement(Button, {
    type: ButtonTypes.SECONDARY,
    size: ButtonSizes.SMALL,
    onClick: () => {
      setShowMore(true);
    }
  }, stringSet.OPEN_CHANNEL_SETTINGS__OPERATORS__TITLE_ALL)), showMore && /*#__PURE__*/React__default.createElement(React__default.Fragment, null, /*#__PURE__*/React__default.createElement(OperatorListModal, {
    onCancel: () => {
      setShowMore(false);
    }
  })), showAdd && /*#__PURE__*/React__default.createElement(React__default.Fragment, null, /*#__PURE__*/React__default.createElement(AddOperatorsModal, {
    onCancel: () => setShowAdd(false),
    onSubmit: () => {
      setShowAdd(false);
    }
  })));
};

function MutedParticipantsModal(_ref) {
  var _state$config;
  let {
    onCancel
  } = _ref;
  const [mutedUsers, setMutedUsers] = useState([]);
  const [userListQuery, setUserListQuery] = useState(null);
  const {
    channel
  } = 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
  } = useContext(LocalizationContext);
  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.createElement("div", null, /*#__PURE__*/React__default.createElement(Modal, {
    isFullScreenOnMobile: true,
    hideFooter: true,
    onCancel: () => onCancel(),
    onSubmit: noop,
    titleText: stringSet.OPEN_CHANNEL_SETTINGS__MUTED_MEMBERS__TITLE
  }, /*#__PURE__*/React__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.createElement(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.createElement(ContextMenu, {
        menuTrigger: toggleDropdown => /*#__PURE__*/React__default.createElement(IconButton, {
          className: "sendbird-user-message__more__menu",
          width: "32px",
          height: "32px",
          onClick: toggleDropdown
        }, /*#__PURE__*/React__default.createElement(Icon, {
          width: "24px",
          height: "24px",
          type: IconTypes.MORE,
          fillColor: IconColors.CONTENT_INVERSE
        })),
        menuItems: closeDropdown => /*#__PURE__*/React__default.createElement(MenuItems, {
          parentRef: actionRef,
          closeDropdown: closeDropdown,
          openLeft: true
        }, /*#__PURE__*/React__default.createElement(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] = useState([]);
  const [hasNext, setHasNext] = useState(false);
  const [showModal, setShowModal] = useState(false);
  const {
    channel
  } = 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
  } = useContext(LocalizationContext);
  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 = 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.createElement(React__default.Fragment, null, mutedUsers.map(mutedUser => /*#__PURE__*/React__default.createElement(UserListItem$1, {
    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.createElement(ContextMenu, {
        menuTrigger: toggleDropdown => /*#__PURE__*/React__default.createElement(IconButton, {
          className: "sendbird-user-message__more__menu",
          width: "32px",
          height: "32px",
          onClick: toggleDropdown
        }, /*#__PURE__*/React__default.createElement(Icon, {
          width: "24px",
          height: "24px",
          type: IconTypes.MORE,
          fillColor: IconColors.CONTENT_INVERSE
        })),
        menuItems: closeDropdown => /*#__PURE__*/React__default.createElement(MenuItems, {
          closeDropdown: closeDropdown,
          openLeft: true,
          parentRef: actionRef
        }, /*#__PURE__*/React__default.createElement(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.createElement(Label, {
    className: "sendbird-channel-settings__empty-list",
    type: LabelTypography.SUBTITLE_2,
    color: LabelColors.ONBACKGROUND_3
  }, stringSet.OPEN_CHANNEL_SETTINGS__MUTED_MEMBERS__NO_ONE), hasNext && /*#__PURE__*/React__default.createElement("div", {
    className: "sendbird-channel-settings-muted-participant-list__footer"
  }, /*#__PURE__*/React__default.createElement(Button, {
    type: ButtonTypes.SECONDARY,
    size: ButtonSizes.SMALL,
    onClick: () => {
      setShowModal(true);
    }
  }, stringSet.OPEN_CHANNEL_SETTINGS__MUTED_MEMBERS__TITLE_ALL)), showModal && /*#__PURE__*/React__default.createElement(MutedParticipantsModal, {
    onCancel: () => {
      setShowModal(false);
      refreshList();
    }
  }));
};

function BannedUsersModal(_ref) {
  var _state$config;
  let {
    onCancel
  } = _ref;
  const [bannedUsers, setBannedUsers] = useState([]);
  const [userListQuery, setUserListQuery] = useState(null);
  const {
    channel
  } = useOpenChannelSettingsContext();
  const state = useSendbirdStateContext();
  const {
    stringSet
  } = useContext(LocalizationContext);
  const currentUserId = state === null || state === void 0 ? void 0 : (_state$config = state.config) === null || _state$config === void 0 ? void 0 : _state$config.userId;
  useEffect(() => {
    const bannedUserListQuery = channel === null || channel === void 0 ? void 0 : channel.createBannedUserListQuery();
    bannedUserListQuery.next().then(users => {
      setBannedUsers(users);
    });
    setUserListQuery(bannedUserListQuery);
  }, []);
  return /*#__PURE__*/React__default.createElement("div", null, /*#__PURE__*/React__default.createElement(Modal, {
    hideFooter: true,
    isFullScreenOnMobile: true,
    onCancel: () => onCancel(),
    onSubmit: noop,
    titleText: stringSet.OPEN_CHANNEL_SETTINGS__MUTED_MEMBERS__TITLE
  }, /*#__PURE__*/React__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.createElement(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.createElement(ContextMenu, {
        menuTrigger: toggleDropdown => /*#__PURE__*/React__default.createElement(IconButton, {
          className: "sendbird-user-message__more__menu",
          width: "32px",
          height: "32px",
          onClick: toggleDropdown
        }, /*#__PURE__*/React__default.createElement(Icon, {
          width: "24px",
          height: "24px",
          type: IconTypes.MORE,
          fillColor: IconColors.CONTENT_INVERSE
        })),
        menuItems: closeDropdown => /*#__PURE__*/React__default.createElement(MenuItems, {
          parentRef: actionRef,
          closeDropdown: closeDropdown,
          openLeft: true
        }, /*#__PURE__*/React__default.createElement(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] = useState([]);
  const [hasNext, setHasNext] = useState(false);
  const [showModal, setShowModal] = useState(false);
  const {
    channel
  } = useOpenChannelSettingsContext();
  const state = useSendbirdStateContext();
  const {
    stringSet
  } = useContext(LocalizationContext);
  const currentUserId = state === null || state === void 0 ? void 0 : (_state$config = state.config) === null || _state$config === void 0 ? void 0 : _state$config.userId;
  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 = 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.createElement(React__default.Fragment, null, bannedUsers.map(bannedUser => /*#__PURE__*/React__default.createElement(UserListItem$1, {
    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.createElement(ContextMenu, {
        menuTrigger: toggleDropdown => /*#__PURE__*/React__default.createElement(IconButton, {
          className: "sendbird-user-message__more__menu",
          width: "32px",
          height: "32px",
          onClick: toggleDropdown
        }, /*#__PURE__*/React__default.createElement(Icon, {
          width: "24px",
          height: "24px",
          type: IconTypes.MORE,
          fillColor: IconColors.CONTENT_INVERSE
        })),
        menuItems: closeDropdown => /*#__PURE__*/React__default.createElement(MenuItems, {
          parentRef: actionRef,
          closeDropdown: closeDropdown,
          openLeft: true
        }, /*#__PURE__*/React__default.createElement(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.createElement(Label, {
    className: "sendbird-channel-settings__empty-list",
    type: LabelTypography.SUBTITLE_2,
    color: LabelColors.ONBACKGROUND_3
  }, stringSet.OPEN_CHANNEL_SETTINGS__BANNED_MEMBERS__NO_ONE), hasNext && /*#__PURE__*/React__default.createElement("div", {
    className: "sendbird-channel-settings-banned-user-list__footer"
  }, /*#__PURE__*/React__default.createElement(Button, {
    type: ButtonTypes.SECONDARY,
    size: ButtonSizes.SMALL,
    onClick: () => {
      setShowModal(true);
    }
  }, stringSet.OPEN_CHANNEL_SETTINGS__BANNED_MEMBERS__TITLE_ALL)), showModal && /*#__PURE__*/React__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
  } = useContext(LocalizationContext);
  const {
    onCloseClick,
    channel
  } = useOpenChannelSettingsContext();
  return /*#__PURE__*/React__default.createElement(React__default.Fragment, null, /*#__PURE__*/React__default.createElement("div", {
    className: "sendbird-openchannel-settings__header"
  }, /*#__PURE__*/React__default.createElement(Label, {
    type: LabelTypography.H_2,
    color: LabelColors.ONBACKGROUND_1
  }, stringSet.CHANNEL_SETTING__HEADER__TITLE), /*#__PURE__*/React__default.createElement(Icon, {
    className: "sendbird-openchannel-settings__close-icon",
    type: IconTypes.CLOSE,
    height: "24px",
    width: "24px",
    onClick: () => {
      onCloseClick();
    }
  })), /*#__PURE__*/React__default.createElement("div", {
    className: "sendbird-openchannel-settings__profile"
  }, (renderChannelProfile === null || renderChannelProfile === void 0 ? void 0 : renderChannelProfile()) || /*#__PURE__*/React__default.createElement(ChannelProfile, null)), /*#__PURE__*/React__default.createElement("div", {
    className: "sendbird-openchannel-settings__url"
  }, /*#__PURE__*/React__default.createElement(Icon, {
    className: "sendbird-openchannel-settings__copy-icon",
    type: IconTypes.COPY,
    height: "22px",
    width: "22px",
    onClick: () => {
      copyToClipboard(channel === null || channel === void 0 ? void 0 : channel.url);
    }
  }), /*#__PURE__*/React__default.createElement(Label, {
    className: "sendbird-openchannel-settings__url-label",
    type: LabelTypography.CAPTION_2,
    color: LabelColors.ONBACKGROUND_2
  }, stringSet.OPEN_CHANNEL_SETTINGS__OPERATOR_URL), /*#__PURE__*/React__default.createElement(Label, {
    className: "sendbird-openchannel-settings__url-value",
    type: LabelTypography.SUBTITLE_2
  }, channel === null || channel === void 0 ? void 0 : channel.url)), /*#__PURE__*/React__default.createElement(AccordionGroup, null, /*#__PURE__*/React__default.createElement(Accordion, {
    className: "sendbird-openchannel-settings__operators-list",
    id: "operators",
    renderTitle: () => /*#__PURE__*/React__default.createElement(React__default.Fragment, null, /*#__PURE__*/React__default.createElement(Icon, {
      className: "sendbird-openchannel-settings__operator-accordion-icon",
      type: IconTypes.OPERATOR,
      fillColor: IconColors.PRIMARY,
      width: "24px",
      height: "24px"
    }), /*#__PURE__*/React__default.createElement(Label, {
      type: LabelTypography.SUBTITLE_1,
      color: LabelColors.ONBACKGROUND_1
    }, stringSet.OPEN_CHANNEL_SETTINGS__OPERATORS_TITLE)),
    renderContent: () => /*#__PURE__*/React__default.createElement(React__default.Fragment, null, /*#__PURE__*/React__default.createElement(OperatorList, null))
  }), /*#__PURE__*/React__default.createElement(Accordion, {
    className: "sendbird-channel-settings__operators-list",
    id: "participants",
    renderTitle: () => /*#__PURE__*/React__default.createElement(React__default.Fragment, null, /*#__PURE__*/React__default.createElement(Icon, {
      type: IconTypes.MEMBERS,
      fillColor: IconColors.PRIMARY,
      width: 24,
      height: 24,
      className: "sendbird-openchannel-settings__operator-accordion-icon"
    }), /*#__PURE__*/React__default.createElement(Label, {
      type: LabelTypography.SUBTITLE_1,
      color: LabelColors.ONBACKGROUND_1
    }, stringSet.OPEN_CHANNEL_SETTINGS__PARTICIPANTS_ACCORDION_TITLE)),
    renderContent: () => /*#__PURE__*/React__default.createElement(React__default.Fragment, null, /*#__PURE__*/React__default.createElement(ParticipantList, {
      isOperatorView: true
    }))
  }), /*#__PURE__*/React__default.createElement(Accordion, {
    className: "sendbird-channel-settings__operators-list",
    id: "mutedMembers",
    renderTitle: () => /*#__PURE__*/React__default.createElement(React__default.Fragment, null, /*#__PURE__*/React__default.createElement(Icon, {
      className: "sendbird-openchannel-settings__operator-accordion-icon",
      type: IconTypes.MUTE,
      fillColor: IconColors.PRIMARY,
      width: "24px",
      height: "24px"
    }), /*#__PURE__*/React__default.createElement(Label, {
      type: LabelTypography.SUBTITLE_1,
      color: LabelColors.ONBACKGROUND_1
    }, stringSet.OPEN_CHANNEL_SETTINGS__MUTED_MEMBERS__TITLE)),
    renderContent: () => /*#__PURE__*/React__default.createElement(React__default.Fragment, null, /*#__PURE__*/React__default.createElement(MutedParticipantList, null))
  }), /*#__PURE__*/React__default.createElement(Accordion, {
    className: "sendbird-channel-settings__operators-list",
    id: "bannedUsers",
    renderTitle: () => /*#__PURE__*/React__default.createElement(React__default.Fragment, null, /*#__PURE__*/React__default.createElement(Icon, {
      className: "sendbird-openchannel-settings__operator-accordion-icon",
      type: IconTypes.BAN,
      fillColor: IconColors.PRIMARY,
      width: "24px",
      height: "24px"
    }), /*#__PURE__*/React__default.createElement(Label, {
      type: LabelTypography.SUBTITLE_1,
      color: LabelColors.ONBACKGROUND_1
    }, stringSet.OPEN_CHANNEL_SETTINGS__BANNED_MEMBERS__TITLE)),
    renderContent: () => /*#__PURE__*/React__default.createElement(React__default.Fragment, null, /*#__PURE__*/React__default.createElement(BannedUserList, null))
  })), /*#__PURE__*/React__default.createElement(DeleteChannel, null));
};

export { OperatorUI, copyToClipboard, OperatorUI as default };
//# sourceMappingURL=OperatorUI.js.map
