import React__default, { useState, useContext, useEffect, useCallback } from 'react';
import { a as LocalizationContext, u as useLocalization } from '../../LocalizationContext-1701e5c8.js';
import Accordion, { AccordionGroup } from '../../ui/Accordion.js';
import { L as Label, b as LabelColors, a as LabelTypography } from '../../index-f50d7ab0.js';
import Icon, { IconTypes, IconColors } from '../../ui/Icon.js';
import Badge from '../../ui/Badge.js';
import { Toggle } from '../../ui/Toggle.js';
import Button, { ButtonTypes, ButtonSizes } from '../../ui/Button.js';
import IconButton from '../../ui/IconButton.js';
import ContextMenu, { MenuItems, MenuItem } from '../../ui/ContextMenu.js';
import UserListItem$1 from './UserListItem.js';
import Modal from '../../ui/Modal.js';
import UserListItem from '../../ui/UserListItem.js';
import { useChannelSettingsContext } from '../context.js';
import useSendbirdStateContext from '../../useSendbirdStateContext.js';
import { _ as _objectSpread2 } from '../../_rollupPluginBabelHelpers-cc035350.js';
import { OperatorFilter } from '@sendbird/chat/groupChannel';
import { M as MemberList } from '../../MemberList-415d00a9.js';
import { n as noop } from '../../utils-05aa9060.js';
import '../../stringSet-e9bb0333.js';
import '../../index-ff8f2f61.js';
import '../../ui/AccordionGroup.js';
import '../../context-b513d868.js';
import 'prop-types';
import 'react-dom';
import '../../ui/SortByRow.js';
import '../../uuid-8b344dd2.js';
import '../../index-99ab01f6.js';
import '../../utils/message/getOutgoingMessageState.js';
import '../../UserProfileContext-74e9a128.js';
import '../../ui/Avatar.js';
import '../../ui/ImageRenderer.js';
import '../../ui/MutedAvatarOverlay.js';
import '../../ui/UserProfile.js';
import '../../sendbirdSelectors.js';
import '../../topics-0b30f52b.js';
import '../../index-44c86e58.js';
import '../../MediaQueryContext-e5b401d0.js';
import '../../ui/Checkbox.js';
import '../../withSendbird.js';

function OperatorsModal(_ref) {
  var _state$config;
  let {
    onCancel
  } = _ref;
  const [operators, setOperators] = useState([]);
  const [operatorQuery, setOperatorQuery] = useState(null);
  const {
    channel
  } = 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
  } = useContext(LocalizationContext);
  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.createElement("div", null, /*#__PURE__*/React__default.createElement(Modal, {
    isFullScreenOnMobile: true,
    hideFooter: true,
    titleText: stringSet.CHANNEL_SETTING__OPERATORS__TITLE_ALL,
    onCancel: onCancel
  }, /*#__PURE__*/React__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.createElement(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.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 // for catching location(x, y) of MenuItems
          ,
          closeDropdown: closeDropdown,
          openLeft: true
        }, /*#__PURE__*/React__default.createElement(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] = useState([]);
  const [selectedMembers, setSelectedMembers] = useState({});
  const [memberQuery, setMemberQuery] = useState(null);
  const {
    stringSet
  } = useContext(LocalizationContext);
  const {
    channel
  } = useChannelSettingsContext();
  useEffect(() => {
    const memberListQuery = channel === null || channel === void 0 ? void 0 : channel.createMemberListQuery({
      operatorFilter: 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.createElement("div", null, /*#__PURE__*/React__default.createElement(Modal, {
    isFullScreenOnMobile: true,
    type: 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.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-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.createElement(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 = _objectSpread2(_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] = useState([]);
  const [showMore, setShowMore] = useState(false);
  const [showAdd, setShowAdd] = useState(false);
  const [hasNext, setHasNext] = useState(false);
  const {
    stringSet
  } = useContext(LocalizationContext);
  const state = useSendbirdStateContext();
  const {
    channel
  } = useChannelSettingsContext();
  const userId = state === null || state === void 0 ? void 0 : (_state$config = state.config) === null || _state$config === void 0 ? void 0 : _state$config.userId;
  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 = 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.createElement(React__default.Fragment, null, operators.map(operator => /*#__PURE__*/React__default.createElement(UserListItem$1, {
    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.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.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.createElement("div", {
    className: "sendbird-channel-settings-accordion__footer"
  }, /*#__PURE__*/React__default.createElement(Button, {
    type: ButtonTypes.SECONDARY,
    size: ButtonSizes.SMALL,
    onClick: () => {
      setShowAdd(true);
    }
  }, stringSet.CHANNEL_SETTING__OPERATORS__TITLE_ADD), hasNext && /*#__PURE__*/React__default.createElement(Button, {
    type: ButtonTypes.SECONDARY,
    size: ButtonSizes.SMALL,
    onClick: () => {
      setShowMore(true);
    }
  }, stringSet.CHANNEL_SETTING__OPERATORS__TITLE_ALL)), showMore && /*#__PURE__*/React__default.createElement(OperatorsModal, {
    onCancel: () => {
      setShowMore(false);
      refreshList();
    }
  }), showAdd && /*#__PURE__*/React__default.createElement(AddOperatorsModal, {
    onCancel: () => setShowAdd(false),
    onSubmit: () => {
      refreshList();
      setShowAdd(false);
    }
  }));
};

function BannedUsersModal(_ref) {
  let {
    onCancel
  } = _ref;
  const [members, setMembers] = useState([]);
  const [memberQuery, setMemberQuery] = useState(null);
  const {
    channel
  } = useChannelSettingsContext();
  const {
    stringSet
  } = useLocalization();
  useEffect(() => {
    const bannedUserListQuery = channel === null || channel === void 0 ? void 0 : channel.createBannedUserListQuery();
    bannedUserListQuery.next().then(users => {
      setMembers(users);
    });
    setMemberQuery(bannedUserListQuery);
  }, []);
  return /*#__PURE__*/React__default.createElement("div", null, /*#__PURE__*/React__default.createElement(Modal, {
    isFullScreenOnMobile: true,
    hideFooter: true,
    onCancel: () => onCancel(),
    onSubmit: noop,
    titleText: stringSet.CHANNEL_SETTING__MUTED_MEMBERS__TITLE
  }, /*#__PURE__*/React__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.createElement(UserListItem, {
    user: member,
    key: member.userId,
    action: _ref2 => {
      let {
        parentRef,
        actionRef
      } = _ref2;
      return /*#__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 // for catching location(x, y) of MenuItems
          ,
          closeDropdown: closeDropdown,
          openLeft: true
        }, /*#__PURE__*/React__default.createElement(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] = useState([]);
  const [hasNext, setHasNext] = useState(false);
  const [showModal, setShowModal] = useState(false);
  const {
    stringSet
  } = useContext(LocalizationContext);
  const {
    channel
  } = useChannelSettingsContext();
  const bannedUserListQueryParams = {
    limit: 10
  };
  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 = 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.createElement(React__default.Fragment, null, members.map(member => /*#__PURE__*/React__default.createElement(UserListItem$1, {
    key: member.userId,
    user: member,
    action: _ref => {
      let {
        actionRef,
        parentRef
      } = _ref;
      return /*#__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 // for catching location(x, y) of MenuItems
          ,
          closeDropdown: closeDropdown,
          openLeft: true
        }, /*#__PURE__*/React__default.createElement(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.createElement(Label, {
    className: "sendbird-channel-settings__empty-list",
    type: LabelTypography.SUBTITLE_2,
    color: LabelColors.ONBACKGROUND_3
  }, stringSet.CHANNEL_SETTING__MODERATION__EMPTY_BAN), hasNext && /*#__PURE__*/React__default.createElement("div", {
    className: "sendbird-channel-settings-accordion__footer"
  }, /*#__PURE__*/React__default.createElement(Button, {
    type: ButtonTypes.SECONDARY,
    size: ButtonSizes.SMALL,
    onClick: () => {
      setShowModal(true);
    }
  }, stringSet.CHANNEL_SETTING__MODERATION__ALL_BAN)), showModal && /*#__PURE__*/React__default.createElement(BannedUsersModal, {
    onCancel: () => {
      setShowModal(false);
      refreshList();
    }
  }));
};

function MutedMembersModal(_ref) {
  var _state$config;
  let {
    onCancel
  } = _ref;
  const [members, setMembers] = useState([]);
  const [memberQuery, setMemberQuery] = useState(null);
  const {
    channel
  } = 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
  } = useLocalization();
  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.createElement("div", null, /*#__PURE__*/React__default.createElement(Modal, {
    isFullScreenOnMobile: true,
    hideFooter: true,
    onCancel: () => onCancel(),
    onSubmit: noop,
    titleText: stringSet.CHANNEL_SETTING__MUTED_MEMBERS__TITLE
  }, /*#__PURE__*/React__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.createElement(UserListItem, {
    currentUser: currentUser,
    user: member,
    key: member.userId,
    action: _ref2 => {
      let {
        actionRef,
        parentRef
      } = _ref2;
      return /*#__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 // for catching location(x, y) of MenuItems
          ,
          closeDropdown: closeDropdown,
          openLeft: true
        }, /*#__PURE__*/React__default.createElement(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] = useState([]);
  const [hasNext, setHasNext] = useState(false);
  const [showModal, setShowModal] = useState(false);
  const {
    stringSet
  } = useLocalization();
  const {
    channel
  } = 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;
  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 = 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.createElement(React__default.Fragment, null, members.map(member => /*#__PURE__*/React__default.createElement(UserListItem$1, {
    key: member.userId,
    user: member,
    currentUser: currentUser,
    action: _ref => {
      let {
        actionRef,
        parentRef
      } = _ref;
      return /*#__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,
          parentContainRef: parentRef,
          parentRef: actionRef // for catching location(x, y) of MenuItems
        }, /*#__PURE__*/React__default.createElement(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.createElement(Label, {
    className: "sendbird-channel-settings__empty-list",
    type: LabelTypography.SUBTITLE_2,
    color: LabelColors.ONBACKGROUND_3
  }, stringSet.CHANNEL_SETTING__NO_UNMUTED), hasNext && /*#__PURE__*/React__default.createElement("div", {
    className: "sendbird-channel-settings-accordion__footer"
  }, /*#__PURE__*/React__default.createElement(Button, {
    type: ButtonTypes.SECONDARY,
    size: ButtonSizes.SMALL,
    onClick: () => {
      setShowModal(true);
    }
  }, stringSet.CHANNEL_SETTING__MUTED_MEMBERS__TITLE_ALL)), showModal && /*#__PURE__*/React__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] = useState(false);
  const {
    stringSet
  } = useContext(LocalizationContext);
  const {
    channel
  } = useChannelSettingsContext();

  // work around for
  // https://sendbird.slack.com/archives/G01290GCDCN/p1595922832000900
  // SDK bug - after frozen/unfrozen myRole becomes "none"
  useEffect(() => {
    setFrozen(channel === null || channel === void 0 ? void 0 : channel.isFrozen);
  }, [channel]);
  return /*#__PURE__*/React__default.createElement(AccordionGroup, {
    className: "sendbird-channel-settings__operator"
  }, /*#__PURE__*/React__default.createElement(Accordion, {
    className: "sendbird-channel-settings__operators-list",
    id: "operators",
    renderTitle: () => /*#__PURE__*/React__default.createElement(React__default.Fragment, null, /*#__PURE__*/React__default.createElement(Icon, {
      type: IconTypes.OPERATOR,
      fillColor: IconColors.PRIMARY,
      width: 24,
      height: 24,
      className: "sendbird-channel-settings__accordion-icon"
    }), /*#__PURE__*/React__default.createElement(Label, {
      type: LabelTypography.SUBTITLE_1,
      color: LabelColors.ONBACKGROUND_1
    }, stringSet.CHANNEL_SETTING__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__members-list",
    id: "members",
    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-channel-settings__accordion-icon"
    }), /*#__PURE__*/React__default.createElement(Label, {
      type: LabelTypography.SUBTITLE_1,
      color: LabelColors.ONBACKGROUND_1
    }, stringSet.CHANNEL_SETTING__MEMBERS__TITLE), /*#__PURE__*/React__default.createElement(Badge, {
      count: kFormatter(channel === null || channel === void 0 ? void 0 : channel.memberCount)
    })),
    renderContent: () => /*#__PURE__*/React__default.createElement(React__default.Fragment, null, /*#__PURE__*/React__default.createElement(MemberList, null))
  }),
  // No muted members in broadcast channel
  !(channel !== null && channel !== void 0 && channel.isBroadcast) && /*#__PURE__*/React__default.createElement(Accordion, {
    id: "mutedMembers",
    className: "sendbird-channel-settings__muted-members-list",
    renderTitle: () => /*#__PURE__*/React__default.createElement(React__default.Fragment, null, /*#__PURE__*/React__default.createElement(Icon, {
      type: IconTypes.MUTE,
      fillColor: IconColors.PRIMARY,
      width: 24,
      height: 24,
      className: "sendbird-channel-settings__accordion-icon"
    }), /*#__PURE__*/React__default.createElement(Label, {
      type: LabelTypography.SUBTITLE_1,
      color: LabelColors.ONBACKGROUND_1
    }, stringSet.CHANNEL_SETTING__MUTED_MEMBERS__TITLE)),
    renderContent: () => /*#__PURE__*/React__default.createElement(React__default.Fragment, null, /*#__PURE__*/React__default.createElement(MutedMemberList, null))
  }), /*#__PURE__*/React__default.createElement(Accordion, {
    className: "sendbird-channel-settings__banned-members-list",
    id: "bannedUsers",
    renderTitle: () => /*#__PURE__*/React__default.createElement(React__default.Fragment, null, /*#__PURE__*/React__default.createElement(Icon, {
      type: IconTypes.BAN,
      fillColor: IconColors.PRIMARY,
      width: 24,
      height: 24,
      className: "sendbird-channel-settings__accordion-icon"
    }), /*#__PURE__*/React__default.createElement(Label, {
      type: LabelTypography.SUBTITLE_1,
      color: LabelColors.ONBACKGROUND_1
    }, stringSet.CHANNEL_SETTING__BANNED_MEMBERS__TITLE)),
    renderContent: () => /*#__PURE__*/React__default.createElement(React__default.Fragment, null, /*#__PURE__*/React__default.createElement(BannedMemberList, null))
  }),
  // cannot freeze broadcast channel
  !(channel !== null && channel !== void 0 && channel.isBroadcast) && /*#__PURE__*/React__default.createElement("div", {
    className: "sendbird-channel-settings__freeze"
  }, /*#__PURE__*/React__default.createElement(Icon, {
    type: IconTypes.FREEZE,
    fillColor: IconColors.PRIMARY,
    width: 24,
    height: 24,
    className: "sendbird-channel-settings__accordion-icon"
  }), /*#__PURE__*/React__default.createElement(Label, {
    type: LabelTypography.SUBTITLE_1,
    color: LabelColors.ONBACKGROUND_1
  }, stringSet.CHANNEL_SETTING__FREEZE_CHANNEL), /*#__PURE__*/React__default.createElement(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);
        });
      }
    }
  })));
}

export { AdminPannel as default };
//# sourceMappingURL=ModerationPanel.js.map
