import { _ as __assign } from '../../chunks/bundle-CyKcXwxv.js';
import React__default from 'react';
import ThreadListItem from './ThreadListItem.js';
import { useThreadContext } from '../context.js';
import { compareMessagesForGrouping } from '../../Channel/utils/compareMessagesForGrouping.js';
import { useSendbirdStateContext } from '../../useSendbirdStateContext.js';
import { isSameDay } from 'date-fns';
import { MessageProvider } from '../../Message/context.js';
import { g as getCaseResolvedReplyType } from '../../chunks/bundle-By4qJA7N.js';
import '../../chunks/bundle-rAzWFbt-.js';
import '../../chunks/bundle-DAYMi6vw.js';
import '../../chunks/bundle-C_RTy-wB.js';
import '../../chunks/bundle-xzHlqm91.js';
import '../../ui/DateSeparator.js';
import '../../chunks/bundle-GXXt0WAx.js';
import '../../chunks/bundle-bz4PqMYo.js';
import '../../chunks/bundle-DQSHPBXl.js';
import '../../chunks/bundle-DIM08oup.js';
import '../../chunks/bundle-DCvGHvPz.js';
import '@sendbird/chat/groupChannel';
import '../../utils/message/getOutgoingMessageState.js';
import '../../chunks/bundle-BFKFmP-d.js';
import '../../chunks/bundle-vddg8rUR.js';
import '../../chunks/bundle-B43BrwWe.js';
import 'react-dom';
import '../../chunks/bundle-yFfkfO0O.js';
import '../../ui/IconButton.js';
import '../../ui/Button.js';
import '../../ui/Icon.js';
import '@sendbird/uikit-tools';
import '../../withSendbird.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-DVRTAl51.js';
import '../../ui/FileViewer.js';
import '../../chunks/bundle-BUD_vgZ5.js';
import '../../ui/ImageRenderer.js';
import '../../chunks/bundle-Dmj05jBl.js';
import '../../chunks/bundle-RRVvccZ1.js';
import '../../chunks/bundle-DKD6ybzd.js';
import '../../chunks/bundle-B5Xnb7gI.js';
import '../../chunks/bundle-N7XRO_Ma.js';
import '../../chunks/bundle-NEplso7H.js';
import '../../ui/MessageInput.js';
import '../../chunks/bundle-CdOhleNh.js';
import 'dompurify';
import '../../chunks/bundle-2Qim3Dap.js';
import '../../chunks/bundle-fX_liw7W.js';
import '../../chunks/bundle-rk3bNfCF.js';
import '../../chunks/bundle-CXmeegua.js';
import '../context/types.js';
import '../../ui/MessageItemReactionMenu.js';
import '../../ui/ReactionButton.js';
import '../../chunks/bundle-D91-xsQ4.js';
import '../../chunks/bundle-DO6Om5Ct.js';
import '../../ui/Loader.js';
import '../../chunks/bundle-BKYxwr2v.js';
import '../../chunks/bundle-DDXgauuR.js';
import '../../ui/EmojiReactions.js';
import '../../ui/ReactionBadge.js';
import '../../ui/BottomSheet.js';
import '../../ui/UserListItem.js';
import '../../chunks/bundle-DV19ISeX.js';
import '../../ui/MutedAvatarOverlay.js';
import '../../ui/Checkbox.js';
import '../../ui/UserProfile.js';
import '../../sendbirdSelectors.js';
import '../../chunks/bundle-BCRvYX9G.js';
import '../../ui/Tooltip.js';
import '../../ui/TooltipWrapper.js';
import '../../chunks/bundle-DmBEox5Y.js';
import '../../ui/MobileMenu.js';
import '../../chunks/bundle-DfMC2kfy.js';
import '@sendbird/chat/message';
import '../../chunks/bundle-D3wwnhPQ.js';
import '../../chunks/bundle-Zi-DQlYN.js';
import '../../chunks/bundle-B-ZON1no.js';
import '../../ui/OGMessageItemBody.js';
import '../../chunks/bundle-DK6h-KUk.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 '../../ui/PlaybackTime.js';
import '../../ui/ThumbnailMessageItemBody.js';
import '../../chunks/bundle-Cw9lWLKX.js';
import '../../ui/UnknownMessageItemBody.js';
import '../../ui/TemplateMessageItemBody.js';
import '../../chunks/bundle-BfPwsSYD.js';
import '../../ui/FallbackTemplateMessageItemBody.tsx.js';
import '../../ui/LoadingTemplateMessageItemBody.tsx.js';
import '../../ui/MessageFeedbackFailedModal.js';
import '../../chunks/bundle-zh5Jl1yd.js';
import '../../chunks/bundle-OK3khRCa.js';
import '../../Message/hooks/useDirtyGetMentions.js';
import '../../chunks/bundle-CGUnkt84.js';
import '../../chunks/bundle-15-msoxy.js';
import '../../chunks/bundle-8Xb4BgWU.js';
import '../../chunks/bundle-ByOQ0ql4.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 = useSendbirdStateContext().config;
    var userId = config.userId;
    var _c = useThreadContext(), 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, 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
