import { _ as __assign } from '../../chunks/bundle-BL7mChau.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-RylnBRDU.js';
import '../../chunks/bundle-C_D936HH.js';
import '../../chunks/bundle-Cj_Dxz14.js';
import '../../chunks/bundle-CfVl8s4A.js';
import '../../chunks/bundle-DQaFQR2q.js';
import '../../ui/DateSeparator.js';
import '../../chunks/bundle-CE4y6Xvr.js';
import '../../chunks/bundle-BoHJWlEb.js';
import '../../chunks/bundle-1-0JQWq1.js';
import '../../chunks/bundle-PPnIQFif.js';
import '../../chunks/bundle-ca6IMmD9.js';
import '@sendbird/chat/groupChannel';
import '../../utils/message/getOutgoingMessageState.js';
import '../../chunks/bundle-RX4SHzNN.js';
import '../../chunks/bundle-DOfvZYT8.js';
import '../../chunks/bundle-c8Tan9dw.js';
import 'react-dom';
import '../../chunks/bundle-Bvh73TsV.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-0P_11xTV.js';
import '@sendbird/chat/openChannel';
import '../../chunks/bundle-hFyf4W91.js';
import '../../chunks/bundle-BjZ9zlI7.js';
import '../../ui/SortByRow.js';
import '../../chunks/bundle-BzWcA5Xa.js';
import '../../ui/FileViewer.js';
import '../../chunks/bundle-BLuTnfAP.js';
import '../../ui/ImageRenderer.js';
import '../../chunks/bundle-BJvmAi6P.js';
import '../../chunks/bundle-BcIO-0xx.js';
import '../../chunks/bundle-DF63zrqA.js';
import '../../chunks/bundle-BJrhV7Sh.js';
import '../../chunks/bundle-T1C3QunC.js';
import '../../chunks/bundle-DV0yjj9U.js';
import '../../ui/MessageInput.js';
import '../../chunks/bundle-CbEx5Qjw.js';
import 'dompurify';
import '../../chunks/bundle-Cdm9wGwJ.js';
import '../../chunks/bundle-SJt9ZQEH.js';
import '../../chunks/bundle-DuBNYf2a.js';
import '../../chunks/bundle-095SzdU2.js';
import '../context/types.js';
import '../../ui/MessageItemReactionMenu.js';
import '../../ui/ReactionButton.js';
import '../../chunks/bundle-C-LUJN0d.js';
import '../../chunks/bundle-DoOtjsD6.js';
import '../../ui/Loader.js';
import '../../chunks/bundle-t2omiCx_.js';
import '../../chunks/bundle-Dp-XZCMz.js';
import '../../ui/EmojiReactions.js';
import '../../ui/ReactionBadge.js';
import '../../ui/BottomSheet.js';
import '../../ui/UserListItem.js';
import '../../chunks/bundle-BtIszx7q.js';
import '../../ui/MutedAvatarOverlay.js';
import '../../ui/Checkbox.js';
import '../../ui/UserProfile.js';
import '../../sendbirdSelectors.js';
import '../../chunks/bundle-CmhRN4oW.js';
import '../../ui/Tooltip.js';
import '../../ui/TooltipWrapper.js';
import '../../chunks/bundle-aYvfY-N_.js';
import '../../ui/MobileMenu.js';
import '../../chunks/bundle-soq1E3t_.js';
import '@sendbird/chat/message';
import '../../chunks/bundle-D_QsLmvl.js';
import '../../chunks/bundle-CUUWmJ_6.js';
import '../../chunks/bundle-B2nb7Hq5.js';
import '../../ui/OGMessageItemBody.js';
import '../../chunks/bundle-bXE_2h0x.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-CECAPCv8.js';
import '../../ui/UnknownMessageItemBody.js';
import '../../ui/TemplateMessageItemBody.js';
import '../../chunks/bundle-BOMfyn_j.js';
import '../../ui/FallbackTemplateMessageItemBody.tsx.js';
import '../../ui/LoadingTemplateMessageItemBody.tsx.js';
import '../../ui/MessageFeedbackFailedModal.js';
import '../../chunks/bundle-B-ayf7rn.js';
import '../../chunks/bundle-BJmbDN9Q.js';
import '../../Message/hooks/useDirtyGetMentions.js';
import '../../chunks/bundle-DdoNWf4m.js';
import '../../chunks/bundle-BOZOvKGQ.js';
import '../../chunks/bundle-DblmzU3b.js';
import '../../chunks/bundle-Cf9I1_PI.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
