'use strict';

var index = require('../../chunks/bundle-DQaXgp8o.js');
var Channel_utils_compareMessagesForGrouping = require('./compareMessagesForGrouping.js');
var index$1 = require('../../chunks/bundle-fYxs1lss.js');
require('../../chunks/bundle-CVJwHwWn.js');
require('../../chunks/bundle-CHAKEXIJ.js');
require('../../chunks/bundle-Cyl6_qLo.js');
require('../../chunks/bundle-Conb-pOy.js');
require('@sendbird/chat/groupChannel');
require('../../utils/message/getOutgoingMessageState.js');
require('../../chunks/bundle-DAdgL6r8.js');
require('../../chunks/bundle-Dobj18FB.js');
require('../../chunks/bundle-Cfh78Xnm.js');

/**
 * exported, should be backward compatible
 */
var getMessagePartsInfo = function (_a) {
    var allMessages = _a.allMessages, stringSet = _a.stringSet, _b = _a.isMessageGroupingEnabled, isMessageGroupingEnabled = _b === void 0 ? true : _b, _c = _a.currentIndex, currentIndex = _c === void 0 ? 0 : _c, currentMessage = _a.currentMessage, _d = _a.currentChannel, currentChannel = _d === void 0 ? null : _d, _e = _a.replyType, replyType = _e === void 0 ? '' : _e, firstUnreadMessageId = _a.firstUnreadMessageId, isUnreadMessageExistInChannel = _a.isUnreadMessageExistInChannel;
    var previousMessage = allMessages[currentIndex - 1];
    var nextMessage = allMessages[currentIndex + 1];
    var _f = isMessageGroupingEnabled
        ? Channel_utils_compareMessagesForGrouping.compareMessagesForGrouping(previousMessage, currentMessage, nextMessage, stringSet, currentChannel, replyType)
        : [false, false], chainTop = _f[0], chainBottom = _f[1];
    var previousMessageCreatedAt = previousMessage === null || previousMessage === void 0 ? void 0 : previousMessage.createdAt;
    var currentCreatedAt = currentMessage.createdAt;
    // NOTE: for pending/failed messages
    var isLocalMessage = 'sendingStatus' in currentMessage && (currentMessage.sendingStatus !== 'succeeded');
    // https://stackoverflow.com/a/41855608
    var hasSeparator = isLocalMessage ? false : !(previousMessageCreatedAt && (index.isSameDay(currentCreatedAt, previousMessageCreatedAt)));
    var hasNewMessageSeparator = (isLocalMessage || !(isUnreadMessageExistInChannel === null || isUnreadMessageExistInChannel === void 0 ? void 0 : isUnreadMessageExistInChannel.current)) ? false : (!index$1.isAdminMessage(currentMessage) && firstUnreadMessageId === currentMessage.messageId);
    return {
        chainTop: chainTop,
        chainBottom: chainBottom,
        hasSeparator: hasSeparator,
        hasNewMessageSeparator: hasNewMessageSeparator,
    };
};

exports.getMessagePartsInfo = getMessagePartsInfo;
//# sourceMappingURL=getMessagePartsInfo.js.map
