import { _ as __assign, a as __awaiter, b as __generator } from '../../chunks/bundle-CyKcXwxv.js';
import React__default from 'react';
import { useGroupChannelListContext } from '../context.js';
import { G as GroupChannelListUIView } from '../../chunks/bundle-CcWfMa1Q.js';
import { GroupChannelPreviewAction } from './GroupChannelPreviewAction.js';
import { useSendbirdStateContext } from '../../useSendbirdStateContext.js';
import { GroupChannelListItem } from './GroupChannelListItem.js';
import { AddGroupChannel } from './AddGroupChannel.js';
import { n as noop } from '../../chunks/bundle-B43BrwWe.js';
import '@sendbird/chat/groupChannel';
import '@sendbird/uikit-tools';
import '../../chunks/bundle-DV19ISeX.js';
import '../../withSendbird.js';
import '../../chunks/bundle-DIM08oup.js';
import '../../chunks/bundle-DCvGHvPz.js';
import '../../utils/message/getOutgoingMessageState.js';
import '../../chunks/bundle-BFKFmP-d.js';
import '../../chunks/bundle-DAYMi6vw.js';
import '../../chunks/bundle-vddg8rUR.js';
import 'react-dom';
import '../../chunks/bundle-C_RTy-wB.js';
import '../../chunks/bundle-xzHlqm91.js';
import '../../chunks/bundle-yFfkfO0O.js';
import '../../ui/IconButton.js';
import '../../ui/Button.js';
import '../../chunks/bundle-bz4PqMYo.js';
import '../../ui/Icon.js';
import 'css-vars-ponyfill';
import '@sendbird/chat';
import '../../chunks/bundle-BUQ58hWb.js';
import '@sendbird/chat/openChannel';
import '../../chunks/bundle-CKwMZR9c.js';
import '../../chunks/bundle-Bien0gJP.js';
import '../../ui/SortByRow.js';
import '../../chunks/bundle-B87P9-w-.js';
import './GroupChannelListHeader.js';
import '../../chunks/bundle-BUD_vgZ5.js';
import '../../ui/ImageRenderer.js';
import '../../chunks/bundle-Dmj05jBl.js';
import '../../ui/Header.js';
import '../../ui/TextButton.js';
import '../../chunks/bundle-GXXt0WAx.js';
import '../../EditUserProfile.js';
import '../../EditUserProfile/context.js';
import '../../EditUserProfile/components/EditUserProfileUI.js';
import '../../chunks/bundle-BDfBsHee.js';
import '../../ui/Input.js';
import '../../ui/PlaceHolder.js';
import '../../ui/Loader.js';
import '../../chunks/bundle-B5c51qyk.js';
import '../../chunks/bundle-15-msoxy.js';
import '@sendbird/chat/message';
import '../../chunks/bundle-DCJ4e4g-.js';
import '../../chunks/bundle-DO6Om5Ct.js';
import '../../chunks/bundle-rAzWFbt-.js';
import '../../chunks/bundle-BKYxwr2v.js';
import '../../chunks/bundle-DDXgauuR.js';
import '../../chunks/bundle-B86EF4ka.js';
import '../../chunks/bundle-D91-xsQ4.js';
import '../../GroupChannel/components/TypingIndicator.js';
import '../../ui/Badge.js';
import '../../ui/ChannelAvatar.js';
import '../../chunks/bundle-DjLWD266.js';
import '../../ui/MentionUserLabel.js';
import '../../chunks/bundle-2Qim3Dap.js';
import '../../chunks/bundle-CXmeegua.js';
import '../../chunks/bundle-BrmSWqY4.js';
import '../../CreateChannel.js';
import '../../CreateChannel/components/CreateChannelUI.js';
import '../../chunks/bundle-DCCHCDuH.js';
import '../../sendbirdSelectors.js';
import '../../chunks/bundle-BCRvYX9G.js';
import '../../CreateChannel/components/InviteUsers.js';
import '../../ui/UserListItem.js';
import '../../ui/MutedAvatarOverlay.js';
import '../../ui/Checkbox.js';
import '../../ui/UserProfile.js';
import '../../CreateChannel/components/SelectChannelType.js';

var GroupChannelListUI = function (props) {
    var renderHeader = props.renderHeader, renderChannelPreview = props.renderChannelPreview, renderPlaceHolderError = props.renderPlaceHolderError, renderPlaceHolderLoading = props.renderPlaceHolderLoading, renderPlaceHolderEmptyList = props.renderPlaceHolderEmptyList;
    var _a = useGroupChannelListContext(), onChannelSelect = _a.onChannelSelect, onThemeChange = _a.onThemeChange, allowProfileEdit = _a.allowProfileEdit, typingChannelUrls = _a.typingChannelUrls, groupChannels = _a.groupChannels, initialized = _a.initialized, selectedChannelUrl = _a.selectedChannelUrl, loadMore = _a.loadMore, onUserProfileUpdated = _a.onUserProfileUpdated, scrollRef = _a.scrollRef;
    var _b = useSendbirdStateContext(), stores = _b.stores, config = _b.config;
    var logger = config.logger, isOnline = config.isOnline;
    var sdk = stores.sdkStore.sdk;
    var renderListItem = function (renderProps) {
        var channel = renderProps.item, index = renderProps.index;
        var itemProps = {
            channel: channel,
            tabIndex: index,
            isSelected: channel.url === selectedChannelUrl,
            isTyping: typingChannelUrls.includes(channel.url),
            renderChannelAction: function (props) { return React__default.createElement(GroupChannelPreviewAction, __assign({}, props)); },
            onClick: function () {
                if (isOnline || (sdk === null || sdk === void 0 ? void 0 : sdk.isCacheEnabled)) {
                    logger.info('ChannelList: Clicked on channel:', channel);
                    onChannelSelect(channel);
                }
                else {
                    logger.warning('ChannelList: Inactivated clicking channel item during offline.');
                }
            },
            onLeaveChannel: function () {
                return __awaiter(this, void 0, void 0, function () {
                    return __generator(this, function (_a) {
                        switch (_a.label) {
                            case 0:
                                logger.info('ChannelList: Leaving channel', channel);
                                return [4 /*yield*/, channel.leave()];
                            case 1:
                                _a.sent();
                                logger.info('ChannelList: Leaving channel success');
                                return [2 /*return*/];
                        }
                    });
                });
            },
        };
        if (renderChannelPreview) {
            return (React__default.createElement("div", { key: channel.url, onClick: itemProps.onClick }, renderChannelPreview(itemProps)));
        }
        return React__default.createElement(GroupChannelListItem, __assign({ key: channel.url }, itemProps));
    };
    return (React__default.createElement(GroupChannelListUIView, { renderHeader: renderHeader, renderChannel: renderListItem, renderPlaceHolderError: renderPlaceHolderError, renderPlaceHolderLoading: renderPlaceHolderLoading, renderPlaceHolderEmptyList: renderPlaceHolderEmptyList, onChangeTheme: onThemeChange !== null && onThemeChange !== void 0 ? onThemeChange : noop, allowProfileEdit: allowProfileEdit, onUserProfileUpdated: onUserProfileUpdated !== null && onUserProfileUpdated !== void 0 ? onUserProfileUpdated : noop, channels: groupChannels, onLoadMore: loadMore, initialized: initialized, renderAddChannel: function () { return React__default.createElement(AddGroupChannel, null); }, scrollRef: scrollRef }));
};

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