'use strict';

var _tslib = require('../../chunks/bundle-Dqor5-v9.js');
var React = require('react');
var Thread_components_ThreadListItem = require('./ThreadListItem.js');
var Thread_context = require('../context.js');
var Channel_utils_compareMessagesForGrouping = require('../../Channel/utils/compareMessagesForGrouping.js');
var useSendbirdStateContext = require('../../useSendbirdStateContext.js');
var dateFns = require('date-fns');
var Message_context = require('../../Message/context.js');
var resolvedReplyType = require('../../chunks/bundle-BczkNnAh.js');
require('../../chunks/bundle-CR--sdNU.js');
require('../../chunks/bundle-DRUCFhOE.js');
require('../../chunks/bundle-BmMxoxjN.js');
require('../../chunks/bundle-pG37uJy2.js');
require('../../ui/DateSeparator.js');
require('../../chunks/bundle-Bnhdg5Rm.js');
require('../../chunks/bundle-CY_gcwTl.js');
require('../../chunks/bundle-D3pbitJx.js');
require('../../chunks/bundle-dudJtubx.js');
require('../../chunks/bundle-slo-uj1z.js');
require('@sendbird/chat/groupChannel');
require('../../utils/message/getOutgoingMessageState.js');
require('../../chunks/bundle-BS4UAC4Z.js');
require('../../chunks/bundle-CXXt3nEF.js');
require('../../chunks/bundle-DXT1Y4Vj.js');
require('react-dom');
require('../../chunks/bundle-CTIC4U7B.js');
require('../../ui/IconButton.js');
require('../../ui/Button.js');
require('../../ui/Icon.js');
require('@sendbird/uikit-tools');
require('../../withSendbird.js');
require('css-vars-ponyfill');
require('@sendbird/chat');
require('../../chunks/bundle-DIZXTVPY.js');
require('@sendbird/chat/openChannel');
require('../../chunks/bundle-BbgSFL3H.js');
require('../../chunks/bundle-B6pik6Q8.js');
require('../../ui/SortByRow.js');
require('../../chunks/bundle-CAWSUNQl.js');
require('../../ui/FileViewer.js');
require('../../chunks/bundle-DWCO2Wap.js');
require('../../ui/ImageRenderer.js');
require('../../chunks/bundle-CT-nv6tW.js');
require('../../chunks/bundle-CaDCOzgc.js');
require('../../chunks/bundle-DVuxNfuC.js');
require('../../chunks/bundle-Drlp8Ng8.js');
require('../../chunks/bundle-BsNnhtXP.js');
require('../../chunks/bundle-DpraIGlW.js');
require('../../ui/MessageInput.js');
require('../../chunks/bundle-BEl3UJGv.js');
require('dompurify');
require('../../chunks/bundle-CULVYVIF.js');
require('../../chunks/bundle-CmCUchSm.js');
require('../../chunks/bundle-CpIO_wkc.js');
require('../../chunks/bundle-ClfGWuhE.js');
require('../context/types.js');
require('../../ui/MessageItemReactionMenu.js');
require('../../ui/ReactionButton.js');
require('../../chunks/bundle-BO9j61_n.js');
require('../../chunks/bundle-Dr-vmGCV.js');
require('../../ui/Loader.js');
require('../../chunks/bundle-BC_1hggZ.js');
require('../../chunks/bundle-BAzcsb-a.js');
require('../../ui/EmojiReactions.js');
require('../../ui/ReactionBadge.js');
require('../../ui/BottomSheet.js');
require('../../ui/UserListItem.js');
require('../../chunks/bundle-DJNCbN6b.js');
require('../../ui/MutedAvatarOverlay.js');
require('../../ui/Checkbox.js');
require('../../ui/UserProfile.js');
require('../../sendbirdSelectors.js');
require('../../chunks/bundle-DCgRyaAA.js');
require('../../ui/Tooltip.js');
require('../../ui/TooltipWrapper.js');
require('../../chunks/bundle-Dga4g-qj.js');
require('../../ui/MobileMenu.js');
require('../../chunks/bundle-3gzyJh9X.js');
require('@sendbird/chat/message');
require('../../chunks/bundle-B-dIVIVZ.js');
require('../../chunks/bundle-BHq4WpLg.js');
require('../../chunks/bundle-C9aPeBRQ.js');
require('../../ui/OGMessageItemBody.js');
require('../../chunks/bundle-DqM28K5U.js');
require('../../ui/MentionLabel.js');
require('../../ui/LinkLabel.js');
require('../../ui/TextMessageItemBody.js');
require('../../ui/FileMessageItemBody.js');
require('../../ui/TextButton.js');
require('../../ui/VoiceMessageItemBody.js');
require('../../ui/ProgressBar.js');
require('../../VoicePlayer/useVoicePlayer.js');
require('../../ui/PlaybackTime.js');
require('../../ui/ThumbnailMessageItemBody.js');
require('../../chunks/bundle-CoHU6Rcd.js');
require('../../ui/UnknownMessageItemBody.js');
require('../../ui/TemplateMessageItemBody.js');
require('../../chunks/bundle-DNFesnBP.js');
require('../../ui/FallbackTemplateMessageItemBody.tsx.js');
require('../../ui/LoadingTemplateMessageItemBody.tsx.js');
require('../../ui/MessageFeedbackFailedModal.js');
require('../../chunks/bundle-l_IgEt1J.js');
require('../../chunks/bundle-Bgh7aeqf.js');
require('../../Message/hooks/useDirtyGetMentions.js');
require('../../chunks/bundle-CiU8qct9.js');
require('../../chunks/bundle-DRHHz9fP.js');
require('../../chunks/bundle-ChtzQ4_G.js');
require('../../chunks/bundle-DCSdwR_f.js');

function _interopDefaultCompat (e) { return e && typeof e === 'object' && 'default' in e ? e : { default: e }; }

var React__default = /*#__PURE__*/_interopDefaultCompat(React);

function ThreadList(_a) {
    var className = _a.className, _b = _a.renderMessage, renderMessage = _b === void 0 ? function (props) { return React__default.default.createElement(Thread_components_ThreadListItem, _tslib.__assign({}, props)); } : _b, renderCustomSeparator = _a.renderCustomSeparator, scrollRef = _a.scrollRef, scrollBottom = _a.scrollBottom;
    var config = useSendbirdStateContext.useSendbirdStateContext().config;
    var userId = config.userId;
    var _c = Thread_context.useThreadContext(), currentChannel = _c.currentChannel, allThreadMessages = _c.allThreadMessages, localThreadMessages = _c.localThreadMessages;
    return (React__default.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 = Channel_utils_compareMessagesForGrouping.compareMessagesForGrouping(prevMessage, message, nextMessage, currentChannel, resolvedReplyType.getCaseResolvedReplyType(config.groupChannel.replyType).upperCase)
                , chainTop = _b[0], chainBottom = _b[1];
            var hasSeparator = !((prevMessage === null || prevMessage === void 0 ? void 0 : prevMessage.createdAt) > 0 && (dateFns.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.default.createElement(Message_context.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.default.createElement(Message_context.MessageProvider, { message: message, isByMe: isByMe, key: message === null || message === void 0 ? void 0 : message.messageId }, renderMessage({
                message: message,
                hasSeparator: false,
                renderCustomSeparator: renderCustomSeparator,
                handleScroll: handleScroll,
            })));
        })));
}

module.exports = ThreadList;
//# sourceMappingURL=ThreadList.js.map
