export function isSuggestedEdit(item) {
    return "oldValue" in item && "newValue" in item;
}
function parseCreatedTime(value) {
    if (!value)
        return 0;
    const time = new Date(value).getTime();
    return Number.isFinite(time) ? time : 0;
}
export function getFeedbackActivityTime(item, suggestionCommentsBySuggestionId) {
    const itemTime = parseCreatedTime(item.created);
    if (!isSuggestedEdit(item))
        return itemTime;
    const latestCommentTime = Math.max(0, ...(suggestionCommentsBySuggestionId?.get(item.id) || []).map((comment) => parseCreatedTime(comment.created)));
    return Math.max(itemTime, latestCommentTime);
}
export function sortFeedbackItemsMostRecentFirst(items, suggestionCommentsBySuggestionId) {
    return items
        .map((item, index) => ({ item, index }))
        .sort((a, b) => {
        const timeDifference = getFeedbackActivityTime(b.item, suggestionCommentsBySuggestionId) -
            getFeedbackActivityTime(a.item, suggestionCommentsBySuggestionId);
        return timeDifference || a.index - b.index;
    })
        .map(({ item }) => item);
}
//# sourceMappingURL=feedbackOrdering.js.map