import { _ as __assign } from '../../chunks/bundle-yl5d1NoZ.js';
import React__default, { useState, useContext, useEffect, useMemo } from 'react';
import { O as OperatorList, M as MutedMemberList, B as BannedUserList } from '../../chunks/bundle-DP--Jqg5.js';
import { M as MemberList } from '../../chunks/bundle-g_iPnYTz.js';
import { L as LocalizationContext } from '../../chunks/bundle-Del33VzI.js';
import { IconColors, IconTypes } from '../../ui/Icon.js';
import Badge from '../../ui/Badge.js';
import { Toggle } from '../../ui/Toggle.js';
import { a as LabelTypography, b as LabelColors } from '../../chunks/bundle-viBng0Kh.js';
import { MenuItemAction } from '../components/ChannelSettingsMenuItem.js';
import { u as useChannelSettings } from '../../chunks/bundle-CvsU5rx0.js';
import '../../chunks/bundle-0vQ6L6RB.js';
import '@sendbird/chat';
import '@sendbird/chat/openChannel';
import '../../chunks/bundle-i_3w58Zd.js';
import '../../chunks/bundle-BUYU9H94.js';
import '../../chunks/bundle-CqLLOVG5.js';
import '@sendbird/chat/groupChannel';
import '../../chunks/bundle-Bch_Ry4S.js';
import 'react-dom';
import '../../chunks/bundle-MlG9piGf.js';
import '../../ui/SortByRow.js';
import '../../chunks/bundle-DGh2T5IL.js';
import '../../ui/IconButton.js';
import '../../chunks/bundle-vmZ9LoYK.js';
import '../../utils/message/getOutgoingMessageState.js';
import '../../chunks/bundle-DgosLQK9.js';
import '../../chunks/bundle-DEuCwnTn.js';
import '../../chunks/bundle-fdEQfX2s.js';
import '../../ui/Button.js';
import '../../ui/UserListItem.js';
import '../../chunks/bundle-B0s_McF0.js';
import '../../chunks/bundle-CAEBoiEz.js';
import '../../ui/ImageRenderer.js';
import '../../chunks/bundle-Dl_v8XoN.js';
import '../../ui/MutedAvatarOverlay.js';
import '../../ui/Checkbox.js';
import '../../ui/UserProfile.js';
import '../../sendbirdSelectors.js';
import '../../chunks/bundle-BOykFtQ3.js';
import '../../chunks/bundle-CtQtfJlT.js';
import '../../chunks/bundle-DBhJIxHw.js';
import '../../chunks/bundle-BGCu7v8M.js';
import '../../chunks/bundle-DFni3Lhf.js';
import '@sendbird/chat/message';
import '@sendbird/uikit-tools';
import '../../chunks/bundle-CMi8r50C.js';
import '../../chunks/bundle-C1dqPUnT.js';
import '../../chunks/bundle-BZGITC2g.js';
import '../../chunks/bundle-CM73CDTO.js';

var kFormatter = function (num) {
    return Math.abs(num) > 999
        ? "".concat((Math.abs(num) / 1000).toFixed(1), "K")
        : num;
};
var commonIconProps = {
    fillColor: IconColors.PRIMARY,
    width: 24,
    height: 24,
    className: 'sendbird-channel-settings__accordion-icon',
};
var commonLabelProps = {
    type: LabelTypography.SUBTITLE_1,
    color: LabelColors.ONBACKGROUND_1,
};
var useMenuItems = function () {
    var _a = useState(false), frozen = _a[0], setFrozen = _a[1];
    var stringSet = useContext(LocalizationContext).stringSet;
    var _b = useChannelSettings().state, channel = _b.channel, renderUserListItem = _b.renderUserListItem;
    // work around for
    // https://sendbird.slack.com/archives/G01290GCDCN/p1595922832000900
    // SDK bug - after frozen/unfrozen myRole becomes "none"
    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 useMemo(function () { return ({
        operator: {
            operators: {
                icon: __assign(__assign({}, commonIconProps), { type: IconTypes.OPERATOR }),
                label: __assign(__assign({}, commonLabelProps), { children: stringSet.CHANNEL_SETTING__OPERATORS__TITLE }),
                accordionComponent: function () { return React__default.createElement(OperatorList, { renderUserListItem: renderUserListItem }); },
            },
            allUsers: {
                icon: __assign(__assign({}, commonIconProps), { type: IconTypes.MEMBERS }),
                label: __assign(__assign({}, commonLabelProps), { children: stringSet.CHANNEL_SETTING__MEMBERS__TITLE }),
                rightComponent: function (props) { return (React__default.createElement("div", { className: "sendbird-channel-settings__members" },
                    React__default.createElement(Badge, { count: (channel === null || channel === void 0 ? void 0 : channel.memberCount) ? kFormatter(channel.memberCount) : '' }),
                    React__default.createElement(MenuItemAction, __assign({}, props)))); },
                accordionComponent: function () { return React__default.createElement(MemberList, { renderUserListItem: renderUserListItem }); },
            },
            mutedUsers: {
                icon: __assign(__assign({}, commonIconProps), { type: IconTypes.MUTE }),
                label: __assign(__assign({}, commonLabelProps), { children: stringSet.CHANNEL_SETTING__MUTED_MEMBERS__TITLE }),
                accordionComponent: function () { return React__default.createElement(MutedMemberList, { renderUserListItem: renderUserListItem }); },
            },
            bannedUsers: {
                icon: __assign(__assign({}, commonIconProps), { type: IconTypes.BAN }),
                label: __assign(__assign({}, commonLabelProps), { children: stringSet.CHANNEL_SETTING__BANNED_MEMBERS__TITLE }),
                accordionComponent: function () { return React__default.createElement(BannedUserList, { renderUserListItem: renderUserListItem }); },
            },
            freezeChannel: {
                hideMenu: channel === null || channel === void 0 ? void 0 : channel.isBroadcast,
                icon: __assign(__assign({}, commonIconProps), { type: IconTypes.FREEZE }),
                label: __assign(__assign({}, commonLabelProps), { children: stringSet.CHANNEL_SETTING__FREEZE_CHANNEL }),
                rightComponent: function () { return React__default.createElement(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: __assign(__assign({}, commonIconProps), { type: IconTypes.MEMBERS }),
                label: __assign(__assign({}, commonLabelProps), { children: stringSet.CHANNEL_SETTING__MEMBERS__TITLE }),
                rightComponent: function (props) { return (React__default.createElement("div", { className: "sendbird-channel-settings__members" },
                    React__default.createElement(Badge, { count: (channel === null || channel === void 0 ? void 0 : channel.memberCount) ? kFormatter(channel.memberCount) : '' }),
                    React__default.createElement(MenuItemAction, __assign({}, props)))); },
                accordionComponent: function () { return React__default.createElement(MemberList, { renderUserListItem: renderUserListItem }); },
            },
        }
    }); }, [channel === null || channel === void 0 ? void 0 : channel.url, frozen]);
};

export { useMenuItems as default, useMenuItems };
//# sourceMappingURL=useMenuList.js.map
