'use strict';

Object.defineProperty(exports, '__esModule', { value: true });

var _tslib = require('../../chunks/bundle-Conb-pOy.js');
var React = require('react');
var uikitTools = require('@sendbird/uikit-tools');
var index = require('../../chunks/bundle-fYxs1lss.js');
var types = require('../../chunks/bundle-BS4GiQtn.js');
var ui_PlaceHolder = require('../../ui/PlaceHolder.js');
var ui_Icon = require('../../ui/Icon.js');
var GroupChannel_components_Message = require('./Message.js');
var GroupChannel_components_UnreadCount = require('./UnreadCount.js');
var LocalizationContext = require('../../chunks/bundle-DPDyqKIJ.js');
var ui_Label = require('../../chunks/bundle-zgmRG2KL.js');
var utils = require('../../chunks/bundle-CkQrhwR6.js');
var MediaQueryContext = require('../../chunks/bundle-Fv6PNPGZ.js');
var GroupChannel_components_FrozenNotification = require('./FrozenNotification.js');
var consts = require('../../chunks/bundle-Cfh78Xnm.js');
var ui_TypingIndicatorBubble = require('../../ui/TypingIndicatorBubble.js');
var Channel_utils_getMessagePartsInfo = require('../../Channel/utils/getMessagePartsInfo.js');
var Message_context = require('../../Message/context.js');
var utils$2 = require('../../chunks/bundle-PVDrKOjZ.js');
var utils$1 = require('../../chunks/bundle-B78tdF27.js');
var GroupChannelProvider = require('../../chunks/bundle-C0RMVFg8.js');
var useSendbird = require('../../chunks/bundle-Bq15P9qk.js');
require('@sendbird/chat/groupChannel');
require('../../utils/message/getOutgoingMessageState.js');
require('../../chunks/bundle-DAdgL6r8.js');
require('../../chunks/bundle-Dobj18FB.js');
require('../../chunks/bundle-CVJwHwWn.js');
require('../../ui/Loader.js');
require('../../chunks/bundle-BbrBawlX.js');
require('../../chunks/bundle-Cyl6_qLo.js');
require('../../chunks/bundle-CPoi7VvJ.js');
require('../../chunks/bundle-CHAKEXIJ.js');
require('../../chunks/bundle-BLz2EOZ5.js');
require('../../Message/hooks/useDirtyGetMentions.js');
require('../../ui/DateSeparator.js');
require('../../chunks/bundle-DurllD3r.js');
require('../../ui/MessageInput.js');
require('../../chunks/bundle-Bomzwcdt.js');
require('../../ui/IconButton.js');
require('../../ui/Button.js');
require('../../chunks/bundle-VKi81862.js');
require('dompurify');
require('../../chunks/bundle-DHuNGmIj.js');
require('../../chunks/bundle-2PCdBxVA.js');
require('../../chunks/bundle-BkgFGPs_.js');
require('../../chunks/bundle-CzkEKbFB.js');
require('../../chunks/bundle-B19RHFpR.js');
require('@sendbird/chat');
require('@sendbird/chat/openChannel');
require('../../ui/MessageContent.js');
require('../../chunks/bundle-DO5FgbkI.js');
require('../../chunks/bundle-ptQgj0WJ.js');
require('../../chunks/bundle-DQaXgp8o.js');
require('../../chunks/bundle-Y-wq3CF0.js');
require('../../chunks/bundle-DGV1BX0m.js');
require('react-dom');
require('../../ui/SortByRow.js');
require('../../chunks/bundle-t8BQsgL5.js');
require('../../ui/MessageItemReactionMenu.js');
require('../../ui/ImageRenderer.js');
require('../../ui/ReactionButton.js');
require('../../chunks/bundle-C5p82xwC.js');
require('../../ui/EmojiReactions.js');
require('../../ui/ReactionBadge.js');
require('../../ui/BottomSheet.js');
require('../../hooks/useModal.js');
require('../../chunks/bundle-DZlJeh0V.js');
require('../../ui/UserListItem.js');
require('../../chunks/bundle-Bnb8seJF.js');
require('../../chunks/bundle-B7KG10z2.js');
require('../../chunks/bundle-C99t7tzf.js');
require('../../ui/MutedAvatarOverlay.js');
require('../../ui/Checkbox.js');
require('../../ui/UserProfile.js');
require('../../sendbirdSelectors.js');
require('../../chunks/bundle-dUH189qO.js');
require('../../ui/Tooltip.js');
require('../../ui/TooltipWrapper.js');
require('../../chunks/bundle-CXbYckbN.js');
require('../../ui/AdminMessage.js');
require('../../ui/QuoteMessage.js');
require('../../chunks/bundle-D9d0Qum8.js');
require('@sendbird/chat/message');
require('../../ui/MobileMenu.js');
require('../../ui/ThreadReplies.js');
require('../../chunks/bundle-DYon6O60.js');
require('../../ui/OGMessageItemBody.js');
require('../../chunks/bundle-CX7K4z2J.js');
require('../../ui/MentionLabel.js');
require('../../ui/LinkLabel.js');
require('../../ui/TextMessageItemBody.js');
require('../../ui/FileMessageItemBody.js');
require('../../ui/TextButton.js');
require('../../chunks/bundle-KzwW_H6y.js');
require('../../ui/FileViewer.js');
require('../../chunks/bundle-Yq_R9TAN.js');
require('../../ui/VoiceMessageItemBody.js');
require('../../ui/ProgressBar.js');
require('../../VoicePlayer/useVoicePlayer.js');
require('../../chunks/bundle-BHp3N9Mz.js');
require('../../VoiceRecorder/context.js');
require('../../ui/PlaybackTime.js');
require('../../ui/ThumbnailMessageItemBody.js');
require('../../ui/UnknownMessageItemBody.js');
require('../../ui/TemplateMessageItemBody.js');
require('../../chunks/bundle-Bt1qvip8.js');
require('../../ui/FallbackTemplateMessageItemBody.tsx.js');
require('../../ui/LoadingTemplateMessageItemBody.tsx.js');
require('../../ui/MessageFeedbackFailedModal.js');
require('../../ui/FeedbackIconButton.js');
require('../../ui/MobileFeedbackMenu.js');
require('../../ui/MessageFeedbackModal.js');
require('../../ui/Input.js');
require('../../chunks/bundle-BwwNS3QS.js');
require('./SuggestedReplies.js');
require('../../chunks/bundle-B7tlFbQZ.js');
require('./FileViewer.js');
require('../../chunks/bundle-8juyGk3c.js');
require('../../chunks/bundle-19BZVS4G.js');
require('../../chunks/bundle-BPUhuptz.js');
require('../../chunks/bundle-CxArG0ag.js');
require('./RemoveMessageModal.js');
require('../../chunks/bundle-COgAaDxc.js');
require('../../chunks/bundle-B2b-r84m.js');
require('../../Channel/utils/compareMessagesForGrouping.js');

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

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

var UnreadCount = function (_a) {
    var _b = _a.className, className = _b === void 0 ? '' : _b, _c = _a.count, count = _c === void 0 ? 0 : _c, onClick = _a.onClick, _d = _a.isFrozenChannel, isFrozenChannel = _d === void 0 ? false : _d;
    var stringSet = React.useContext(LocalizationContext.LocalizationContext).stringSet;
    var unreadMessageCountText = React.useMemo(function () {
        if (count === 1) {
            return stringSet.CHANNEL__MESSAGE_LIST__NOTIFICATION__UNREAD_MESSAGE;
        }
        else if (count > 1) {
            return stringSet.CHANNEL__MESSAGE_LIST__NOTIFICATION__UNREAD_MESSAGE_S;
        }
    }, [count]);
    return (React__default.default.createElement("div", { className: utils.classnames(count < 1 ? 'sendbird-unread-floating-button--hide' : 'sendbird-unread-floating-button', isFrozenChannel && 'sendbird-unread-floating-button--below-frozen', className), "data-testid": "sendbird-notification" },
        React__default.default.createElement(ui_Label.Label, { className: "sendbird-unread-floating-button__text", testID: "sendbird-notification__text", color: ui_Label.LabelColors.ONCONTENT_1, type: ui_Label.LabelTypography.CAPTION_2 }, "".concat(count > 99 ? '99+' : count, " "),
            unreadMessageCountText),
        React__default.default.createElement(ui_Icon.default, { width: "24px", height: "24px", type: ui_Icon.IconTypes.FLOATING_BUTTON_CLOSE, fillColor: ui_Icon.IconColors.CONTENT, onClick: onClick })));
};

var NewMessageCount = function (_a) {
    var _b = _a.className, className = _b === void 0 ? '' : _b, _c = _a.count, count = _c === void 0 ? 0 : _c, onClick = _a.onClick;
    var stringSet = React.useContext(LocalizationContext.LocalizationContext).stringSet;
    var isMobile = MediaQueryContext.useMediaQueryContext().isMobile;
    var newMessageCountText = React.useMemo(function () {
        if (count === 1) {
            return stringSet.CHANNEL__MESSAGE_LIST__NOTIFICATION__NEW_MESSAGE;
        }
        else if (count > 1) {
            return stringSet.CHANNEL__MESSAGE_LIST__NOTIFICATION__NEW_MESSAGE_S;
        }
    }, [count]);
    return (React__default.default.createElement("div", { className: utils.classnames(count < 1 ? 'sendbird-new-message-floating-button--hide' : 'sendbird-new-message-floating-button', className), "data-testid": "sendbird-new-message-notification", onClick: onClick },
        React__default.default.createElement(ui_Label.Label, { className: "sendbird-new-message-floating-button__text", testID: "sendbird-new-message-notification__text", color: ui_Label.LabelColors.ONCONTENT_1, type: ui_Label.LabelTypography.CAPTION_2 }, "".concat(count > 99 ? '99+' : count, " "),
            newMessageCountText),
        !isMobile && (React__default.default.createElement(ui_Icon.default, { width: "24px", height: "24px", type: ui_Icon.IconTypes.CHEVRON_DOWN, fillColor: ui_Icon.IconColors.PRIMARY }))));
};

var InfiniteList = React.forwardRef(function (props, listRef) {
    var messages = props.messages, renderMessage = props.renderMessage, scrollPositionRef = props.scrollPositionRef, scrollDistanceFromBottomRef = props.scrollDistanceFromBottomRef, onLoadPrevious = props.onLoadPrevious, onLoadNext = props.onLoadNext, _a = props.loadThreshold, loadThreshold = _a === void 0 ? 0.05 : _a, typingIndicator = props.typingIndicator, _b = props.onScrollPosition, onScrollPosition = _b === void 0 ? utils.noop : _b, initDeps = props.initDeps;
    var isFetching = React__default.default.useRef(false);
    var direction = React__default.default.useRef();
    var oldScrollTop = React.useRef(0);
    // SideEffect: scroll to bottom on initialized
    React.useLayoutEffect(function () {
        if (listRef.current) {
            listRef.current.scrollTop = listRef.current.scrollHeight;
        }
    }, initDeps);
    // SideEffect: keep scroll position
    React.useLayoutEffect(function () {
        if (listRef.current) {
            if (direction.current === 'top') {
                listRef.current.scrollTop = listRef.current.scrollHeight - scrollPositionRef.current;
            }
            if (direction.current === 'bottom') {
                listRef.current.scrollTop = oldScrollTop.current;
            }
            direction.current = undefined;
        }
    }, [listRef.current, messages.length]);
    var handleScroll = React.useCallback(function () { return _tslib.__awaiter(void 0, void 0, void 0, function () {
        var list, threshold;
        return _tslib.__generator(this, function (_a) {
            switch (_a.label) {
                case 0:
                    if (!listRef.current)
                        return [2 /*return*/];
                    list = listRef.current;
                    onScrollPosition(getReachedStatus(list));
                    scrollPositionRef.current = list.scrollHeight - list.scrollTop;
                    scrollDistanceFromBottomRef.current = scrollPositionRef.current - list.clientHeight;
                    oldScrollTop.current = list.scrollTop;
                    if (isFetching.current)
                        return [2 /*return*/];
                    threshold = list.clientHeight * Math.min(Math.max(0, loadThreshold), 1);
                    if (!(list.scrollTop <= threshold)) return [3 /*break*/, 2];
                    isFetching.current = true;
                    direction.current = 'top';
                    return [4 /*yield*/, onLoadPrevious()];
                case 1:
                    _a.sent();
                    isFetching.current = false;
                    return [3 /*break*/, 5];
                case 2:
                    if (!(list.scrollHeight - list.scrollTop - list.clientHeight <= threshold)) return [3 /*break*/, 4];
                    isFetching.current = true;
                    direction.current = 'bottom';
                    return [4 /*yield*/, onLoadNext()];
                case 3:
                    _a.sent();
                    isFetching.current = false;
                    return [3 /*break*/, 5];
                case 4:
                    direction.current = undefined;
                    _a.label = 5;
                case 5: return [2 /*return*/];
            }
        });
    }); }, [messages.length]);
    return (React__default.default.createElement("div", { className: "sendbird-conversation__scroll-container" },
        React__default.default.createElement("div", { className: "sendbird-conversation__padding" }),
        React__default.default.createElement("div", { ref: listRef, className: "sendbird-conversation__messages-padding", "data-testid": "sendbird-message-list-container", onScroll: handleScroll },
            messages.map(function (message, index) { return renderMessage({ message: message, index: index }); }),
            typingIndicator)));
});
function getReachedStatus(element) {
    if (utils$1.isAboutSame(element.scrollTop, 0, consts.SCROLL_BUFFER)) {
        return 'top';
    }
    if (utils$1.isAboutSame(element.scrollHeight, element.clientHeight + element.scrollTop, consts.SCROLL_BUFFER)) {
        return 'bottom';
    }
    return 'middle';
}

var MessageList = function (props) {
    var _a, _b, _c, _d, _e;
    var _f = props.className, className = _f === void 0 ? '' : _f;
    var _g = utils.deleteNullish(props), _h = _g.renderMessage, renderMessage = _h === void 0 ? function (props) { return React__default.default.createElement(GroupChannel_components_Message.Message, _tslib.__assign({}, props)); } : _h, renderMessageContent = _g.renderMessageContent, renderSuggestedReplies = _g.renderSuggestedReplies, renderCustomSeparator = _g.renderCustomSeparator, _j = _g.renderPlaceholderLoader, renderPlaceholderLoader = _j === void 0 ? function () { return React__default.default.createElement(ui_PlaceHolder.default, { type: ui_PlaceHolder.PlaceHolderTypes.LOADING }); } : _j, _k = _g.renderPlaceholderEmpty, renderPlaceholderEmpty = _k === void 0 ? function () { return React__default.default.createElement(ui_PlaceHolder.default, { className: "sendbird-conversation__no-messages", type: ui_PlaceHolder.PlaceHolderTypes.NO_MESSAGES }); } : _k, _l = _g.renderFrozenNotification, renderFrozenNotification = _l === void 0 ? function () { return React__default.default.createElement(GroupChannel_components_FrozenNotification.FrozenNotification, { className: "sendbird-conversation__messages__notification" }); } : _l;
    var _m = GroupChannelProvider.useGroupChannel(), _o = _m.state, channelUrl = _o.channelUrl, hasNext = _o.hasNext, loading = _o.loading, messages = _o.messages, newMessages = _o.newMessages, isScrollBottomReached = _o.isScrollBottomReached, isMessageGroupingEnabled = _o.isMessageGroupingEnabled, currentChannel = _o.currentChannel, replyType = _o.replyType, scrollPubSub = _o.scrollPubSub, loadNext = _o.loadNext, loadPrevious = _o.loadPrevious, resetNewMessages = _o.resetNewMessages, scrollRef = _o.scrollRef, scrollPositionRef = _o.scrollPositionRef, scrollDistanceFromBottomRef = _o.scrollDistanceFromBottomRef, markAsUnreadSourceRef = _o.markAsUnreadSourceRef, readState = _o.readState, _p = _m.actions, scrollToBottom = _p.scrollToBottom, setIsScrollBottomReached = _p.setIsScrollBottomReached, markAsReadAll = _p.markAsReadAll, markAsUnread = _p.markAsUnread;
    var _q = useSendbird.useSendbird(), state = _q.state, enableMarkAsUnread = _q.state.config.groupChannel.enableMarkAsUnread;
    var stringSet = LocalizationContext.useLocalization().stringSet;
    var _r = React.useState(), unreadSinceDate = _r[0], setUnreadSinceDate = _r[1];
    var _s = React.useState(false), showUnreadCount = _s[0], setShowUnreadCount = _s[1];
    var isInitializedRef = React.useRef(false);
    var separatorMessageRef = React.useRef(undefined);
    var isUnreadMessageExistInChannel = React.useRef(false);
    // Find the first unread message
    var firstUnreadMessage = React.useMemo(function () {
        if (!enableMarkAsUnread || !isInitializedRef.current || messages.length === 0 || readState === 'read') {
            return undefined;
        }
        if (readState === 'unread') {
            separatorMessageRef.current = undefined;
            isUnreadMessageExistInChannel.current = true;
        }
        var myLastRead = currentChannel.myLastRead;
        var willFindMessageCreatedAt = myLastRead + 1;
        // 조건 1: 정확히 myLastRead + 1인 메시지 찾기
        var exactMatchMessage = messages.find(function (message) { return message.createdAt === willFindMessageCreatedAt; });
        if (exactMatchMessage) {
            return exactMatchMessage;
        }
        // 조건 2: myLastRead + 1보다 큰 첫 번째 메시지 찾기 (Admin 메시지 제외)
        return messages.find(function (message) { return message.createdAt > willFindMessageCreatedAt && !index.isAdminMessage(message); });
    }, [messages, currentChannel === null || currentChannel === void 0 ? void 0 : currentChannel.myLastRead, readState]);
    React.useEffect(function () {
        var _a;
        if ((currentChannel === null || currentChannel === void 0 ? void 0 : currentChannel.url) && loading) {
            // done get channel and messages
            setShowUnreadCount((currentChannel === null || currentChannel === void 0 ? void 0 : currentChannel.unreadMessageCount) > 0);
            isInitializedRef.current = true;
            isUnreadMessageExistInChannel.current = ((_a = currentChannel === null || currentChannel === void 0 ? void 0 : currentChannel.lastMessage) === null || _a === void 0 ? void 0 : _a.createdAt) > (currentChannel === null || currentChannel === void 0 ? void 0 : currentChannel.myLastRead);
        }
    }, [currentChannel === null || currentChannel === void 0 ? void 0 : currentChannel.url, loading]);
    React.useEffect(function () {
        if (!isInitializedRef.current)
            return;
        if (!enableMarkAsUnread) {
            // backward compatibility
            if (isScrollBottomReached) {
                setUnreadSinceDate(undefined);
            }
            else {
                setUnreadSinceDate(new Date());
            }
        }
        else if (isScrollBottomReached) {
            if ((markAsUnreadSourceRef === null || markAsUnreadSourceRef === void 0 ? void 0 : markAsUnreadSourceRef.current) !== 'manual') {
                if ((currentChannel === null || currentChannel === void 0 ? void 0 : currentChannel.unreadMessageCount) > 0) {
                    if (separatorMessageRef.current || !isUnreadMessageExistInChannel.current) {
                        // called markAsReadAll as after the first unread message is displayed
                        markAsReadAll(currentChannel);
                    }
                }
            }
        }
    }, [isScrollBottomReached]);
    var checkDisplayedNewMessageSeparator = React.useCallback(function (isNewMessageSeparatorVisible) {
        if (!isInitializedRef.current || !firstUnreadMessage)
            return;
        if (isNewMessageSeparatorVisible && (currentChannel === null || currentChannel === void 0 ? void 0 : currentChannel.unreadMessageCount) > 0) {
            setShowUnreadCount(false);
        }
        else if (!isNewMessageSeparatorVisible && (currentChannel === null || currentChannel === void 0 ? void 0 : currentChannel.unreadMessageCount) > 0) {
            setShowUnreadCount(true);
        }
        if (isNewMessageSeparatorVisible && (markAsUnreadSourceRef === null || markAsUnreadSourceRef === void 0 ? void 0 : markAsUnreadSourceRef.current) !== 'manual') {
            if ((newMessages === null || newMessages === void 0 ? void 0 : newMessages.length) > 0) {
                markAsUnread(newMessages[0], 'internal');
                separatorMessageRef.current = undefined;
            }
            else if (firstUnreadMessage) {
                if (!separatorMessageRef.current || separatorMessageRef.current.messageId !== firstUnreadMessage.messageId) {
                    separatorMessageRef.current = firstUnreadMessage;
                }
                markAsReadAll(currentChannel);
            }
        }
    }, [firstUnreadMessage, markAsUnread, markAsReadAll, currentChannel === null || currentChannel === void 0 ? void 0 : currentChannel.unreadMessageCount]);
    /**
     * 1. Move the message list scroll
     *    when each message's height is changed by `reactions` OR `showEdit`
     * 2. Keep the scrollBottom value after fetching new message list
     */
    var onMessageContentSizeChanged = function (isBottomMessageAffected) {
        if (isBottomMessageAffected === void 0) { isBottomMessageAffected = false; }
        var elem = scrollRef.current;
        if (elem) {
            var latestDistance = scrollDistanceFromBottomRef.current;
            var currentDistance = elem.scrollHeight - elem.scrollTop - elem.offsetHeight;
            if (latestDistance < currentDistance && (!isBottomMessageAffected || latestDistance < consts.SCROLL_BUFFER)) {
                var diff = currentDistance - latestDistance;
                // Move the scroll as much as the height of the message has changed
                scrollPubSub.publish('scroll', { top: elem.scrollTop + diff, lazy: false, animated: false });
            }
        }
    };
    var renderer = {
        frozenNotification: function () {
            if (!currentChannel || !currentChannel.isFrozen)
                return null;
            return renderFrozenNotification();
        },
        unreadMessagesNotification: function () {
            var _a;
            if (enableMarkAsUnread) {
                if (!showUnreadCount || (currentChannel === null || currentChannel === void 0 ? void 0 : currentChannel.unreadMessageCount) === 0)
                    return null;
                return (React__default.default.createElement(UnreadCount, { className: "sendbird-unread-messages-count", count: (_a = currentChannel === null || currentChannel === void 0 ? void 0 : currentChannel.unreadMessageCount) !== null && _a !== void 0 ? _a : 0, isFrozenChannel: (currentChannel === null || currentChannel === void 0 ? void 0 : currentChannel.isFrozen) || false, onClick: function () {
                        if (newMessages.length > 0) {
                            resetNewMessages();
                        }
                        isUnreadMessageExistInChannel.current = false;
                        markAsReadAll(currentChannel);
                    } }));
            }
            if (isScrollBottomReached || !unreadSinceDate)
                return null;
            return (React__default.default.createElement(GroupChannel_components_UnreadCount.UnreadCount, { className: "sendbird-conversation__messages__notification", count: newMessages.length, lastReadAt: unreadSinceDate, onClick: function () { return scrollToBottom(); } }));
        },
        scrollToBottomButton: function () {
            if (!hasNext() && isScrollBottomReached)
                return null;
            return (React__default.default.createElement("div", { className: "sendbird-conversation__scroll-bottom-button", onClick: function () { return scrollToBottom(); }, onKeyDown: function () { return scrollToBottom(); }, tabIndex: 0, role: "button" },
                React__default.default.createElement(ui_Icon.default, { width: "24px", height: "24px", type: ui_Icon.IconTypes.CHEVRON_DOWN, fillColor: ui_Icon.IconColors.PRIMARY })));
        },
        newMessageCount: function () {
            // 스크롤이 bottom에 있을 때는 new message count를 표시하지 않음
            if (isScrollBottomReached)
                return null;
            return (React__default.default.createElement(NewMessageCount, { className: "sendbird-new-messages-count", count: newMessages.length, onClick: function () { return scrollToBottom(); } }));
        },
    };
    if (loading) {
        return renderPlaceholderLoader();
    }
    if (messages.length === 0) {
        return renderPlaceholderEmpty();
    }
    return (React__default.default.createElement(React__default.default.Fragment, null,
        React__default.default.createElement("div", { className: "sendbird-conversation__messages ".concat(className), dir: index.getHTMLTextDirection(state.config.htmlTextDirection, state.config.forceLeftToRightMessageLayout) },
            React__default.default.createElement(InfiniteList, { ref: scrollRef, initDeps: [channelUrl], scrollPositionRef: scrollPositionRef, scrollDistanceFromBottomRef: scrollDistanceFromBottomRef, onLoadNext: loadNext, onLoadPrevious: loadPrevious, onScrollPosition: function (it) {
                    var isScrollBottomReached = it === 'bottom';
                    if (isInitializedRef.current && isScrollBottomReached) {
                        if (newMessages.length > 0) {
                            resetNewMessages();
                        }
                        else if (!isUnreadMessageExistInChannel.current && (currentChannel === null || currentChannel === void 0 ? void 0 : currentChannel.unreadMessageCount) === 0) {
                            markAsReadAll(currentChannel);
                        }
                    }
                    setIsScrollBottomReached(isScrollBottomReached);
                }, messages: messages, renderMessage: function (_a) {
                    var _b;
                    var message = _a.message, index$1 = _a.index;
                    var finalFirstUnreadMessageId = ((_b = separatorMessageRef.current) === null || _b === void 0 ? void 0 : _b.messageId) || (firstUnreadMessage === null || firstUnreadMessage === void 0 ? void 0 : firstUnreadMessage.messageId);
                    var _c = Channel_utils_getMessagePartsInfo.getMessagePartsInfo({
                        allMessages: messages,
                        stringSet: stringSet,
                        replyType: replyType !== null && replyType !== void 0 ? replyType : 'NONE',
                        isMessageGroupingEnabled: isMessageGroupingEnabled !== null && isMessageGroupingEnabled !== void 0 ? isMessageGroupingEnabled : false,
                        currentIndex: index$1,
                        currentMessage: message,
                        currentChannel: currentChannel,
                        firstUnreadMessageId: finalFirstUnreadMessageId,
                        isUnreadMessageExistInChannel: isUnreadMessageExistInChannel,
                    }), chainTop = _c.chainTop, chainBottom = _c.chainBottom, hasSeparator = _c.hasSeparator, hasNewMessageSeparator = _c.hasNewMessageSeparator;
                    var isOutgoingMessage = index.isSendableMessage(message) && message.sender.userId === state.config.userId;
                    return (React__default.default.createElement(Message_context.MessageProvider, { message: message, key: utils$2.getComponentKeyFromMessage(message), isByMe: isOutgoingMessage }, renderMessage({
                        handleScroll: onMessageContentSizeChanged,
                        message: message,
                        hasSeparator: hasSeparator,
                        hasNewMessageSeparator: hasNewMessageSeparator,
                        chainTop: chainTop,
                        chainBottom: chainBottom,
                        renderMessageContent: renderMessageContent,
                        renderSuggestedReplies: renderSuggestedReplies,
                        renderCustomSeparator: renderCustomSeparator,
                        onNewMessageSeparatorVisibilityChange: checkDisplayedNewMessageSeparator,
                    })));
                }, typingIndicator: !hasNext()
                    && ((_b = (_a = state === null || state === void 0 ? void 0 : state.config) === null || _a === void 0 ? void 0 : _a.groupChannel) === null || _b === void 0 ? void 0 : _b.enableTypingIndicator)
                    && ((_e = (_d = (_c = state === null || state === void 0 ? void 0 : state.config) === null || _c === void 0 ? void 0 : _c.groupChannel) === null || _d === void 0 ? void 0 : _d.typingIndicatorTypes) === null || _e === void 0 ? void 0 : _e.has(types.TypingIndicatorType.Bubble)) && (React__default.default.createElement(TypingIndicatorBubbleWrapper, { channelUrl: channelUrl, handleScroll: onMessageContentSizeChanged })) }),
            React__default.default.createElement(React__default.default.Fragment, null, renderer.frozenNotification()),
            React__default.default.createElement(React__default.default.Fragment, null, renderer.unreadMessagesNotification()),
            React__default.default.createElement(React__default.default.Fragment, null, renderer.scrollToBottomButton()),
            React__default.default.createElement(React__default.default.Fragment, null, renderer.newMessageCount()))));
};
var TypingIndicatorBubbleWrapper = function (props) {
    var stores = useSendbird.useSendbird().state.stores;
    var _a = GroupChannelProvider.useGroupChannel().state, isScrollBottomReached = _a.isScrollBottomReached, scrollPubSub = _a.scrollPubSub;
    var _b = React.useState([]), typingMembers = _b[0], setTypingMembers = _b[1];
    uikitTools.useGroupChannelHandler(stores.sdkStore.sdk, {
        onTypingStatusUpdated: function (channel) {
            if (channel.url === props.channelUrl) {
                setTypingMembers(channel.getTypingUsers());
            }
            if (isScrollBottomReached && utils$2.isContextMenuClosed()) {
                setTimeout(function () {
                    scrollPubSub.publish('scrollToBottom', {});
                }, 10);
            }
        },
    });
    return React__default.default.createElement(ui_TypingIndicatorBubble, { typingMembers: typingMembers, handleScroll: props.handleScroll });
};

exports.MessageList = MessageList;
exports.default = MessageList;
//# sourceMappingURL=MessageList.js.map
