import { _ as __assign } from '../../chunks/bundle-B8Grfnrx.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-B5_aP8LE.js';
import { u as useThread } from '../../chunks/bundle-CVS5Kfg_.js';
import { u as useSendbird } from '../../chunks/bundle-I25ah_Bv.js';
import { u as useLocalization } from '../../chunks/bundle-l_QLKq1Y.js';
import '../../chunks/bundle-Dy1IZ181.js';
import '../../chunks/bundle-DYBTopZK.js';
import '../../chunks/bundle-BYOddwmS.js';
import '../../ui/DateSeparator.js';
import '../../chunks/bundle-DED6q4Ti.js';
import '../../chunks/bundle-HspRRkmy.js';
import '../../chunks/bundle-Y2KBbxRr.js';
import '../../chunks/bundle-D6CBeFkE.js';
import '../../chunks/bundle-LnGQMQVt.js';
import 'react-dom';
import '../../chunks/bundle-CDcu1I4f.js';
import '../../chunks/bundle-yKqHFFfz.js';
import '../../ui/IconButton.js';
import '../../ui/Button.js';
import '../../ui/Icon.js';
import '../../chunks/bundle-CTkGIdt8.js';
import '../../chunks/bundle-DDZn5buS.js';
import '../../chunks/bundle-CgLhYjm5.js';
import '@sendbird/chat/groupChannel';
import '../../utils/message/getOutgoingMessageState.js';
import '../../chunks/bundle-BTxw_tIt.js';
import '../../chunks/bundle-De-3zaYV.js';
import '../../chunks/bundle-Ob7Cw3V-.js';
import '../../ui/FileViewer.js';
import '../../hooks/useModal.js';
import '../../chunks/bundle-C4OmfIXk.js';
import '@sendbird/chat';
import '@sendbird/chat/openChannel';
import '../../chunks/bundle-DgFzcADJ.js';
import '../../ui/ImageRenderer.js';
import '../../chunks/bundle-C_ngoQD_.js';
import '../../chunks/bundle-DgpfIrde.js';
import '@sendbird/uikit-tools';
import '../../chunks/bundle-WJtiC3BL.js';
import '../../chunks/bundle-CF8V-ET_.js';
import '../../chunks/bundle-BciLDE6M.js';
import '../../chunks/bundle-DXneAdAp.js';
import '../../ui/MessageInput.js';
import '../../chunks/bundle-DwLTEVMK.js';
import 'dompurify';
import '../../chunks/bundle-Dp_oW1ks.js';
import '../../chunks/bundle-Cn2czFA-.js';
import '../../chunks/bundle-4w9Y7uxA.js';
import '../../chunks/bundle-DT1VcdMs.js';
import '../context/types.js';
import '../../chunks/bundle-QCH8CZT8.js';
import '../../ui/SortByRow.js';
import '../../ui/MessageItemReactionMenu.js';
import '../../ui/ReactionButton.js';
import '../../chunks/bundle-CJmXP56m.js';
import '../../chunks/bundle-Dd7rgmeQ.js';
import '../../ui/Loader.js';
import '../../chunks/bundle-Dhf37wzM.js';
import '../../chunks/bundle-C8TP-mjp.js';
import '../../ui/EmojiReactions.js';
import '../../ui/ReactionBadge.js';
import '../../ui/BottomSheet.js';
import '../../ui/UserListItem.js';
import '../../chunks/bundle-BYqblmEM.js';
import '../../ui/MutedAvatarOverlay.js';
import '../../ui/Checkbox.js';
import '../../ui/UserProfile.js';
import '../../sendbirdSelectors.js';
import '../../chunks/bundle--1cImOGd.js';
import '../../ui/Tooltip.js';
import '../../ui/TooltipWrapper.js';
import '../../chunks/bundle-C6Hk5xTT.js';
import '../../ui/MobileMenu.js';
import '../../chunks/bundle-BFJ4ctRk.js';
import '@sendbird/chat/message';
import '../../chunks/bundle-CQAiZVNS.js';
import '../../chunks/bundle-CFXaZ31h.js';
import '../../chunks/bundle-CEE3GJSk.js';
import '../../ui/OGMessageItemBody.js';
import '../../chunks/bundle-Do9UFGCD.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-zOZq2Vpt.js';
import '../../VoiceRecorder/context.js';
import '../../ui/PlaybackTime.js';
import '../../ui/ThumbnailMessageItemBody.js';
import '../../chunks/bundle-tFnb24Id.js';
import '../../ui/UnknownMessageItemBody.js';
import '../../ui/TemplateMessageItemBody.js';
import '../../chunks/bundle-CwHldvb8.js';
import '../../ui/FallbackTemplateMessageItemBody.tsx.js';
import '../../ui/LoadingTemplateMessageItemBody.tsx.js';
import '../../ui/MessageFeedbackFailedModal.js';
import '../../chunks/bundle-D8xAej93.js';
import '../../chunks/bundle-BfEYq-V8.js';
import '../../Message/hooks/useDirtyGetMentions.js';
import '../../chunks/bundle-BCGcsRu2.js';
import '../../chunks/bundle-D_tSqvX6.js';
import '../../chunks/bundle-Djq12iSf.js';
import '../../chunks/bundle-C5Pz6wMm.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
