import { getLatestComments } from "../services/reviewsService";
import { getLatestSuggestedEdits } from "../services/suggestedEditsService";
export const LATEST_FEEDBACK_TAKE = 50;
export const latestFeedbackRefreshMessageTypes = new Set([
    "comment-updated",
    "comment-deleted",
    "suggested-edit-updated",
    "suggested-edit-deleted",
]);
export function getLatestFeedbackCreatedTime(item) {
    const created = item.created;
    return created ? new Date(created).getTime() : 0;
}
export function isLatestFeedbackRefreshMessage(type) {
    return (typeof type === "string" && latestFeedbackRefreshMessageTypes.has(type));
}
export async function loadLatestFeedbackItems(take = LATEST_FEEDBACK_TAKE, language) {
    const [commentsResult, suggestionsResult] = await Promise.all([
        getLatestComments(take, language),
        getLatestSuggestedEdits(take, language),
    ]);
    const comments = (commentsResult.data || []).map((comment) => ({
        ...comment,
        kind: "comment",
    }));
    const suggestions = (suggestionsResult.data || []).map((suggestion) => ({
        ...suggestion,
        kind: "suggestion",
    }));
    return [...comments, ...suggestions]
        .sort((a, b) => getLatestFeedbackCreatedTime(b) - getLatestFeedbackCreatedTime(a))
        .slice(0, take);
}
//# sourceMappingURL=latestFeedbackData.js.map