'use strict';

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

var index = require('../../chunks/bundle-FJtjwZwh.js');
var index$1 = require('../../chunks/bundle-D7YiKR6i.js');
require('../../chunks/bundle-C1G0SKDq.js');
require('../../chunks/bundle-BV7y6VDn.js');
require('../../chunks/bundle-CxoFSSXv.js');
require('@sendbird/chat/groupChannel');
require('../../utils/message/getOutgoingMessageState.js');
require('../../chunks/bundle-dfqZUdij.js');
require('../../chunks/bundle-Dn0hi6OJ.js');
require('../../chunks/bundle-yU9Mr2pS.js');

/**
 * exported, should be backward compatible
 * @returns [chainTop: `boolean`, chainBottom: `boolean`]
 */
var compareMessagesForGrouping = function (prevMessage, currMessage, nextMessage, stringSet, currentChannel, replyType) {
    if (!currentChannel || currentChannel.channelType !== 'group') {
        return [
            isSameGroup(prevMessage, currMessage, stringSet),
            isSameGroup(currMessage, nextMessage, stringSet),
        ];
    }
    if (replyType === 'THREAD' && (currMessage === null || currMessage === void 0 ? void 0 : currMessage.threadInfo)) {
        return [false, false];
    }
    var sendingStatus = (currMessage === null || currMessage === void 0 ? void 0 : currMessage.sendingStatus) || '';
    var isAcceptable = sendingStatus !== 'pending' && sendingStatus !== 'failed';
    return [
        isSameGroup(prevMessage, currMessage, stringSet, currentChannel) && isAcceptable,
        isSameGroup(currMessage, nextMessage, stringSet, currentChannel) && isAcceptable,
    ];
};
var getMessageCreatedAt = function (message, stringSet) {
    return index.format(message.createdAt, stringSet.DATE_FORMAT__MESSAGE_CREATED_AT);
};
var isSameGroup = function (message, comparingMessage, stringSet, currentChannel) {
    var _a, _b;
    if (!(message
        && comparingMessage
        && message.messageType
        && message.messageType !== 'admin'
        && comparingMessage.messageType
        && (comparingMessage === null || comparingMessage === void 0 ? void 0 : comparingMessage.messageType) !== 'admin'
        && 'sender' in message
        && 'sender' in comparingMessage
        && message.createdAt
        && comparingMessage.createdAt
        && message.sender.userId
        && comparingMessage.sender.userId)) {
        return false;
    }
    return ((message === null || message === void 0 ? void 0 : message.sendingStatus) === (comparingMessage === null || comparingMessage === void 0 ? void 0 : comparingMessage.sendingStatus)
        && ((_a = message === null || message === void 0 ? void 0 : message.sender) === null || _a === void 0 ? void 0 : _a.userId) === ((_b = comparingMessage === null || comparingMessage === void 0 ? void 0 : comparingMessage.sender) === null || _b === void 0 ? void 0 : _b.userId)
        && getMessageCreatedAt(message, stringSet) === getMessageCreatedAt(comparingMessage, stringSet)) && (currentChannel ? index$1.isReadMessage(currentChannel, message) === index$1.isReadMessage(currentChannel, comparingMessage) : true);
};
var messages = {
    compareMessagesForGrouping: compareMessagesForGrouping,
    getMessageCreatedAt: getMessageCreatedAt,
    isSameGroup: isSameGroup,
};

exports.compareMessagesForGrouping = compareMessagesForGrouping;
exports.default = messages;
exports.getMessageCreatedAt = getMessageCreatedAt;
exports.isSameGroup = isSameGroup;
//# sourceMappingURL=compareMessagesForGrouping.js.map
