export function normalizeReviewIdentity(value) {
    return value?.trim().toLocaleLowerCase() ?? "";
}
export function getReviewDisplayStatus(review) {
    const decision = review.finalDecision ?? review.status;
    if (decision === "Approved")
        return "approved";
    if (decision === "Rejected")
        return "rejected";
    if (review.isExpired)
        return "expired";
    return "in-progress";
}
export function getReviewerDisplayName(reviewer) {
    return (reviewer.name?.trim() ||
        reviewer.userName?.trim() ||
        reviewer.email?.trim() ||
        "Unknown reviewer");
}
export function getReviewerKey(reviewer) {
    return normalizeReviewIdentity(reviewer.email || reviewer.userName || reviewer.name);
}
export function reviewIncludesUser(review, user) {
    const userIdentities = new Set([user?.email, user?.name, user?.fullName]
        .map(normalizeReviewIdentity)
        .filter(Boolean));
    if (userIdentities.size === 0)
        return false;
    return (review.reviewers ?? []).some((reviewer) => [reviewer.email, reviewer.userName, reviewer.name]
        .map(normalizeReviewIdentity)
        .some((identity) => identity && userIdentities.has(identity)));
}
export function getReviewDecisionProgressStatus(review) {
    const decisionsCount = review.currentUserDecisionsCount;
    if (decisionsCount == null)
        return null;
    if (decisionsCount <= 0)
        return "open";
    if (review.pagesCount > 0 && decisionsCount >= review.pagesCount) {
        return "completed";
    }
    return "in-progress";
}
export function getReviewLanguages(review) {
    const detailedLanguages = (review.languages ?? []).filter((language) => language && language !== "*");
    if (detailedLanguages.length > 0)
        return detailedLanguages;
    if (review.language === "*")
        return ["All"];
    if (review.language === "mixed")
        return ["Multiple"];
    return review.language ? [review.language] : [];
}
export function formatReviewSummaryList(values, visibleCount) {
    if (values.length <= visibleCount)
        return values.join(", ");
    return `${values.slice(0, visibleCount).join(", ")}, +${values.length - visibleCount}`;
}
export function filterReviewList(reviews, filters) {
    const search = normalizeReviewIdentity(filters.searchTerm);
    return reviews.filter((review) => {
        const displayStatus = getReviewDisplayStatus(review);
        if (filters.view === "open" && displayStatus !== "in-progress") {
            return false;
        }
        if (filters.status !== "all" && displayStatus !== filters.status) {
            return false;
        }
        if (filters.reviewer !== "all" &&
            !(review.reviewers ?? []).some((reviewer) => getReviewerKey(reviewer) === filters.reviewer)) {
            return false;
        }
        if (!search)
            return true;
        const searchableValues = [
            review.title,
            review.createdBy,
            review.language,
            ...(review.languages ?? []),
            ...(review.reviewers ?? []).flatMap((reviewer) => [
                reviewer.name,
                reviewer.userName,
                reviewer.email,
            ]),
        ];
        return searchableValues.some((value) => normalizeReviewIdentity(value).includes(search));
    });
}
//# sourceMappingURL=reviewListPresentation.js.map