import { _ as __assign } from '../../chunks/bundle-yl5d1NoZ.js';
import React__default from 'react';
import ThreadListItem from './ThreadListItem.js';
import { compareMessagesForGrouping } from '../../Channel/utils/compareMessagesForGrouping.js';
import { isSameDay } from 'date-fns';
import { MessageProvider } from '../../Message/context.js';
import { g as getCaseResolvedReplyType } from '../../chunks/bundle-DK3-aB7E.js';
import { u as useThread } from '../../chunks/bundle-a_zBi15q.js';
import { u as useSendbird } from '../../chunks/bundle-i_3w58Zd.js';
import { u as useLocalization } from '../../chunks/bundle-Del33VzI.js';
import '../../chunks/bundle-mGsud0ec.js';
import '../../chunks/bundle-fdEQfX2s.js';
import '../../chunks/bundle-BZGITC2g.js';
import '../../ui/DateSeparator.js';
import '../../chunks/bundle-Bokm7tQ9.js';
import '../../chunks/bundle-viBng0Kh.js';
import '../../chunks/bundle-C1dqPUnT.js';
import '../../chunks/bundle-D1OvmDcy.js';
import '../../chunks/bundle-CtQtfJlT.js';
import 'react-dom';
import '../../chunks/bundle-MlG9piGf.js';
import '../../chunks/bundle-DBhJIxHw.js';
import '../../ui/IconButton.js';
import '../../ui/Button.js';
import '../../ui/Icon.js';
import '../../chunks/bundle-DGh2T5IL.js';
import '../../chunks/bundle-BxzlMlCv.js';
import '../../chunks/bundle-vmZ9LoYK.js';
import '@sendbird/chat/groupChannel';
import '../../utils/message/getOutgoingMessageState.js';
import '../../chunks/bundle-DgosLQK9.js';
import '../../chunks/bundle-DEuCwnTn.js';
import '../../chunks/bundle-CqLLOVG5.js';
import '../../ui/FileViewer.js';
import '../../hooks/useModal.js';
import '../../chunks/bundle-BUYU9H94.js';
import '@sendbird/chat';
import '@sendbird/chat/openChannel';
import '../../chunks/bundle-CAEBoiEz.js';
import '../../ui/ImageRenderer.js';
import '../../chunks/bundle-Dl_v8XoN.js';
import '../../chunks/bundle-Ha1krmtK.js';
import '@sendbird/uikit-tools';
import '../../chunks/bundle-Coe_wsHL.js';
import '../../chunks/bundle-sf0POh6_.js';
import '../../chunks/bundle-BEx1sWnS.js';
import '../../chunks/bundle-BNtO7aXk.js';
import '../../ui/MessageInput.js';
import '../../chunks/bundle-CN_mZmg1.js';
import 'dompurify';
import '../../chunks/bundle-D6b2YGeE.js';
import '../../chunks/bundle-B6udMinl.js';
import '../../chunks/bundle-Cc1gzgza.js';
import '../../chunks/bundle-BwvurfUT.js';
import '../context/types.js';
import '../../chunks/bundle-Bch_Ry4S.js';
import '../../ui/SortByRow.js';
import '../../ui/MessageItemReactionMenu.js';
import '../../ui/ReactionButton.js';
import '../../chunks/bundle-Ba_cV-Zm.js';
import '../../chunks/bundle-2U8QpYXo.js';
import '../../ui/Loader.js';
import '../../chunks/bundle-BhhLSKSz.js';
import '../../chunks/bundle-Cl9rtdlj.js';
import '../../ui/EmojiReactions.js';
import '../../ui/ReactionBadge.js';
import '../../ui/BottomSheet.js';
import '../../ui/UserListItem.js';
import '../../chunks/bundle-B0s_McF0.js';
import '../../ui/MutedAvatarOverlay.js';
import '../../ui/Checkbox.js';
import '../../ui/UserProfile.js';
import '../../sendbirdSelectors.js';
import '../../chunks/bundle-BOykFtQ3.js';
import '../../ui/Tooltip.js';
import '../../ui/TooltipWrapper.js';
import '../../chunks/bundle-BSy5MmTl.js';
import '../../ui/MobileMenu.js';
import '../../chunks/bundle-HwtLrcpn.js';
import '@sendbird/chat/message';
import '../../chunks/bundle-CQ_-cyp9.js';
import '../../chunks/bundle-C8U5aHBw.js';
import '../../chunks/bundle-BdQWhaHB.js';
import '../../ui/OGMessageItemBody.js';
import '../../chunks/bundle-DcLgcUpC.js';
import '../../ui/MentionLabel.js';
import '../../ui/LinkLabel.js';
import '../../ui/TextMessageItemBody.js';
import '../../ui/FileMessageItemBody.js';
import '../../ui/TextButton.js';
import '../../ui/VoiceMessageItemBody.js';
import '../../ui/ProgressBar.js';
import '../../VoicePlayer/useVoicePlayer.js';
import '../../chunks/bundle-BrBLR_c-.js';
import '../../VoiceRecorder/context.js';
import '../../ui/PlaybackTime.js';
import '../../ui/ThumbnailMessageItemBody.js';
import '../../chunks/bundle-h6bAY7E9.js';
import '../../ui/UnknownMessageItemBody.js';
import '../../ui/TemplateMessageItemBody.js';
import '../../chunks/bundle-BJYztm64.js';
import '../../ui/FallbackTemplateMessageItemBody.tsx.js';
import '../../ui/LoadingTemplateMessageItemBody.tsx.js';
import '../../ui/MessageFeedbackFailedModal.js';
import '../../chunks/bundle-CzwYTfhQ.js';
import '../../chunks/bundle-BY2z9V57.js';
import '../../Message/hooks/useDirtyGetMentions.js';
import '../../chunks/bundle-CIQCAe1h.js';
import '../../chunks/bundle-DFni3Lhf.js';
import '../../chunks/bundle-CM73CDTO.js';
import '../../chunks/bundle-BmoSvBYM.js';

function ThreadList(_a) {
    var className = _a.className, _b = _a.renderMessage, renderMessage = _b === void 0 ? function (props) { return React__default.createElement(ThreadListItem, __assign({}, props)); } : _b, renderCustomSeparator = _a.renderCustomSeparator, scrollRef = _a.scrollRef, scrollBottom = _a.scrollBottom;
    var config = useSendbird().state.config;
    var stringSet = useLocalization().stringSet;
    var userId = config.userId;
    var _c = useThread().state, currentChannel = _c.currentChannel, allThreadMessages = _c.allThreadMessages, localThreadMessages = _c.localThreadMessages;
    return (React__default.createElement("div", { className: "sendbird-thread-list ".concat(className) },
        allThreadMessages.map(function (message, idx) {
            var _a;
            var isByMe = ((_a = message === null || message === void 0 ? void 0 : message.sender) === null || _a === void 0 ? void 0 : _a.userId) === userId;
            var prevMessage = allThreadMessages[idx - 1];
            var nextMessage = allThreadMessages[idx + 1];
            // eslint-disable-next-line no-constant-condition
            var _b = compareMessagesForGrouping(prevMessage, message, nextMessage, stringSet, currentChannel, getCaseResolvedReplyType(config.groupChannel.replyType).upperCase)
                , chainTop = _b[0], chainBottom = _b[1];
            var hasSeparator = !((prevMessage === null || prevMessage === void 0 ? void 0 : prevMessage.createdAt) > 0 && (isSameDay(message === null || message === void 0 ? void 0 : message.createdAt, prevMessage === null || prevMessage === void 0 ? void 0 : prevMessage.createdAt)));
            var handleScroll = function () {
                var current = scrollRef === null || scrollRef === void 0 ? void 0 : scrollRef.current;
                if (current && scrollBottom) {
                    var bottom = current.scrollHeight - current.scrollTop - current.offsetHeight;
                    if (scrollBottom < bottom) {
                        current.scrollTop += bottom - scrollBottom;
                    }
                }
            };
            return (React__default.createElement(MessageProvider, { message: message, isByMe: isByMe, key: message === null || message === void 0 ? void 0 : message.messageId }, renderMessage({
                message: message,
                chainTop: chainTop,
                chainBottom: chainBottom,
                hasSeparator: hasSeparator,
                renderCustomSeparator: renderCustomSeparator,
                handleScroll: handleScroll,
            })));
        }),
        localThreadMessages.map(function (message) {
            var _a;
            var isByMe = ((_a = message === null || message === void 0 ? void 0 : message.sender) === null || _a === void 0 ? void 0 : _a.userId) === userId;
            var handleScroll = function () {
                var current = scrollRef === null || scrollRef === void 0 ? void 0 : scrollRef.current;
                if (current) {
                    var bottom = current.scrollHeight - current.scrollTop - current.offsetHeight;
                    if (scrollBottom < bottom) {
                        current.scrollTop += bottom - scrollBottom;
                    }
                }
            };
            return (React__default.createElement(MessageProvider, { message: message, isByMe: isByMe, key: message === null || message === void 0 ? void 0 : message.messageId }, renderMessage({
                message: message,
                hasSeparator: false,
                renderCustomSeparator: renderCustomSeparator,
                handleScroll: handleScroll,
            })));
        })));
}

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