"use strict";
/**
 * Chat utilities
 */
Object.defineProperty(exports, "__esModule", { value: true });
exports.groupChatsByDate = groupChatsByDate;
exports.defaultChatFilter = defaultChatFilter;
/**
 * Groups chats by date
 *
 * @param chats - Array of chats to group
 * @returns Map of date keys to chat arrays
 */
function groupChatsByDate(chats) {
    const grouped = new Map();
    chats.forEach((chat) => {
        var _a;
        if (!chat.createTime)
            return;
        const date = new Date(chat.createTime);
        const dateKey = date.toDateString();
        if (!grouped.has(dateKey)) {
            grouped.set(dateKey, []);
        }
        (_a = grouped.get(dateKey)) === null || _a === void 0 ? void 0 : _a.push(chat);
    });
    return grouped;
}
/**
 * Default filter function - searches in chat name and last message
 *
 * @param filter - Search query string
 * @returns Function that filters list items
 */
function defaultChatFilter(filter) {
    return (item) => {
        var _a, _b;
        // Skip date headers from filtering
        if (item.type === 'date-header') {
            return true;
        }
        const chat = item;
        const lowerQuery = filter.toLowerCase();
        return (chat.name.toLowerCase().includes(lowerQuery) ||
            ((_b = (_a = chat.lastMessage) === null || _a === void 0 ? void 0 : _a.toLowerCase().includes(lowerQuery)) !== null && _b !== void 0 ? _b : false));
    };
}
//# sourceMappingURL=chatUtils.js.map
