'use strict';

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

var _tslib = require('../../chunks/bundle-Dqor5-v9.js');
var React = require('react');
var MutedMemberList = require('../../chunks/bundle-CQMwvyEi.js');
var MemberList = require('../../chunks/bundle-wgw5fXTW.js');
var LocalizationContext = require('../../chunks/bundle-BmMxoxjN.js');
var ui_Icon = require('../../ui/Icon.js');
var ui_Badge = require('../../ui/Badge.js');
var ui_Toggle = require('../../ui/Toggle.js');
var ui_Label = require('../../chunks/bundle-CY_gcwTl.js');
var ChannelSettings_context = require('../context.js');
var ChannelSettings_components_ChannelSettingsMenuItem = require('../components/ChannelSettingsMenuItem.js');
require('../../ui/Button.js');
require('../../chunks/bundle-PGvCxwe4.js');
require('@sendbird/chat');
require('@sendbird/chat/openChannel');
require('../../useSendbirdStateContext.js');
require('../../withSendbird.js');
require('../../chunks/bundle-B6pik6Q8.js');
require('react-dom');
require('../../chunks/bundle-DXT1Y4Vj.js');
require('../../ui/SortByRow.js');
require('../../chunks/bundle-DIZXTVPY.js');
require('../../ui/IconButton.js');
require('../../chunks/bundle-slo-uj1z.js');
require('@sendbird/chat/groupChannel');
require('../../utils/message/getOutgoingMessageState.js');
require('../../chunks/bundle-BS4UAC4Z.js');
require('../../chunks/bundle-DRUCFhOE.js');
require('../../chunks/bundle-CXXt3nEF.js');
require('../../ui/UserListItem.js');
require('@sendbird/uikit-tools');
require('../../chunks/bundle-dudJtubx.js');
require('../../chunks/bundle-CTIC4U7B.js');
require('css-vars-ponyfill');
require('../../chunks/bundle-BbgSFL3H.js');
require('../../chunks/bundle-DJNCbN6b.js');
require('../../chunks/bundle-DWCO2Wap.js');
require('../../ui/ImageRenderer.js');
require('../../chunks/bundle-CT-nv6tW.js');
require('../../ui/MutedAvatarOverlay.js');
require('../../ui/Checkbox.js');
require('../../ui/UserProfile.js');
require('../../sendbirdSelectors.js');
require('../../chunks/bundle-DCgRyaAA.js');
require('../../chunks/bundle-BCfjcyQ0.js');
require('../../chunks/bundle-DRHHz9fP.js');
require('@sendbird/chat/message');
require('../../chunks/bundle-D-MC1CM2.js');
require('../../chunks/bundle-pG37uJy2.js');
require('../../chunks/bundle-DCSdwR_f.js');

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

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

var kFormatter = function (num) {
    return Math.abs(num) > 999
        ? "".concat((Math.abs(num) / 1000).toFixed(1), "K")
        : num;
};
var commonIconProps = {
    fillColor: ui_Icon.IconColors.PRIMARY,
    width: 24,
    height: 24,
    className: 'sendbird-channel-settings__accordion-icon',
};
var commonLabelProps = {
    type: ui_Label.LabelTypography.SUBTITLE_1,
    color: ui_Label.LabelColors.ONBACKGROUND_1,
};
var useMenuItems = function () {
    var _a = React.useState(false), frozen = _a[0], setFrozen = _a[1];
    var stringSet = React.useContext(LocalizationContext.LocalizationContext).stringSet;
    var _b = ChannelSettings_context.useChannelSettingsContext(), channel = _b.channel, renderUserListItem = _b.renderUserListItem;
    // work around for
    // https://sendbird.slack.com/archives/G01290GCDCN/p1595922832000900
    // SDK bug - after frozen/unfrozen myRole becomes "none"
    React.useEffect(function () {
        var _a;
        setFrozen((_a = channel === null || channel === void 0 ? void 0 : channel.isFrozen) !== null && _a !== void 0 ? _a : false);
    }, [channel === null || channel === void 0 ? void 0 : channel.isFrozen]);
    return React.useMemo(function () { return ({
        operator: {
            operators: {
                icon: _tslib.__assign(_tslib.__assign({}, commonIconProps), { type: ui_Icon.IconTypes.OPERATOR }),
                label: _tslib.__assign(_tslib.__assign({}, commonLabelProps), { children: stringSet.CHANNEL_SETTING__OPERATORS__TITLE }),
                accordionComponent: function () { return React__default.default.createElement(MutedMemberList.OperatorList, { renderUserListItem: renderUserListItem }); },
            },
            allUsers: {
                icon: _tslib.__assign(_tslib.__assign({}, commonIconProps), { type: ui_Icon.IconTypes.MEMBERS }),
                label: _tslib.__assign(_tslib.__assign({}, commonLabelProps), { children: stringSet.CHANNEL_SETTING__MEMBERS__TITLE }),
                rightComponent: function (props) { return (React__default.default.createElement("div", { className: "sendbird-channel-settings__members" },
                    React__default.default.createElement(ui_Badge, { count: (channel === null || channel === void 0 ? void 0 : channel.memberCount) ? kFormatter(channel.memberCount) : '' }),
                    React__default.default.createElement(ChannelSettings_components_ChannelSettingsMenuItem.MenuItemAction, _tslib.__assign({}, props)))); },
                accordionComponent: function () { return React__default.default.createElement(MemberList.MemberList, { renderUserListItem: renderUserListItem }); },
            },
            mutedUsers: {
                icon: _tslib.__assign(_tslib.__assign({}, commonIconProps), { type: ui_Icon.IconTypes.MUTE }),
                label: _tslib.__assign(_tslib.__assign({}, commonLabelProps), { children: stringSet.CHANNEL_SETTING__MUTED_MEMBERS__TITLE }),
                accordionComponent: function () { return React__default.default.createElement(MutedMemberList.MutedMemberList, { renderUserListItem: renderUserListItem }); },
            },
            bannedUsers: {
                icon: _tslib.__assign(_tslib.__assign({}, commonIconProps), { type: ui_Icon.IconTypes.BAN }),
                label: _tslib.__assign(_tslib.__assign({}, commonLabelProps), { children: stringSet.CHANNEL_SETTING__BANNED_MEMBERS__TITLE }),
                accordionComponent: function () { return React__default.default.createElement(MutedMemberList.BannedUserList, { renderUserListItem: renderUserListItem }); },
            },
            freezeChannel: {
                hideMenu: channel === null || channel === void 0 ? void 0 : channel.isBroadcast,
                icon: _tslib.__assign(_tslib.__assign({}, commonIconProps), { type: ui_Icon.IconTypes.FREEZE }),
                label: _tslib.__assign(_tslib.__assign({}, commonLabelProps), { children: stringSet.CHANNEL_SETTING__FREEZE_CHANNEL }),
                rightComponent: function () { return React__default.default.createElement(ui_Toggle.Toggle, { className: "sendbird-channel-settings__frozen-icon", checked: frozen, onChange: function () {
                        if (frozen) {
                            channel === null || channel === void 0 ? void 0 : channel.unfreeze().then(function () {
                                setFrozen(function (prev) { return !prev; });
                            });
                        }
                        else {
                            channel === null || channel === void 0 ? void 0 : channel.freeze().then(function () {
                                setFrozen(function (prev) { return !prev; });
                            });
                        }
                    } }); },
            },
        },
        nonOperator: {
            allUsers: {
                icon: _tslib.__assign(_tslib.__assign({}, commonIconProps), { type: ui_Icon.IconTypes.MEMBERS }),
                label: _tslib.__assign(_tslib.__assign({}, commonLabelProps), { children: stringSet.CHANNEL_SETTING__MEMBERS__TITLE }),
                rightComponent: function (props) { return (React__default.default.createElement("div", { className: "sendbird-channel-settings__members" },
                    React__default.default.createElement(ui_Badge, { count: (channel === null || channel === void 0 ? void 0 : channel.memberCount) ? kFormatter(channel.memberCount) : '' }),
                    React__default.default.createElement(ChannelSettings_components_ChannelSettingsMenuItem.MenuItemAction, _tslib.__assign({}, props)))); },
                accordionComponent: function () { return React__default.default.createElement(MemberList.MemberList, { renderUserListItem: renderUserListItem }); },
            },
        }
    }); }, [channel === null || channel === void 0 ? void 0 : channel.url, frozen]);
};

exports.default = useMenuItems;
exports.useMenuItems = useMenuItems;
//# sourceMappingURL=useMenuList.js.map
