"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.renderOptionalMarkdownPostCompletionComments = renderOptionalMarkdownPostCompletionComments;
exports.renderOptionalTextPostCompletionComments = renderOptionalTextPostCompletionComments;
exports.renderOptionalMarkdownComments = renderOptionalMarkdownComments;
exports.renderOptionalTextComments = renderOptionalTextComments;
const catalog_1 = require("../../i18n/catalog");
const issue_report_1 = require("../../issues/issue-report");
const types_1 = require("../../issues/types");
const format_1 = require("./format");
function renderOptionalMarkdownPostCompletionComments(viewModel, locale, displayTimeZone) {
    const postCompletionComments = resolvePostCompletionComments(viewModel);
    if (postCompletionComments.mode !== "post-completion") {
        return [];
    }
    return [
        "",
        `**${(0, catalog_1.translate)(locale, "issue.command.show.postCompletionCommentsHeading")}**`,
        `- ${(0, catalog_1.translate)(locale, "issue.command.show.postCompletionComments.note")}`,
        ...(postCompletionComments.unavailable
            ? [
                `- ${(0, catalog_1.translate)(locale, "issue.command.show.postCompletionComments.unavailable")}`,
            ]
            : renderMarkdownPostCompletionCommentTimeline(postCompletionComments.comments, locale, displayTimeZone)),
    ];
}
function renderOptionalTextPostCompletionComments(viewModel, locale, displayTimeZone) {
    const postCompletionComments = resolvePostCompletionComments(viewModel);
    if (postCompletionComments.mode !== "post-completion") {
        return [];
    }
    return [
        "",
        `${(0, catalog_1.translate)(locale, "issue.command.show.postCompletionCommentsHeading")}:`,
        (0, catalog_1.translate)(locale, "issue.command.show.postCompletionComments.note"),
        ...(postCompletionComments.unavailable
            ? [
                (0, catalog_1.translate)(locale, "issue.command.show.postCompletionComments.unavailable"),
            ]
            : renderTextPostCompletionCommentTimeline(postCompletionComments.comments, locale, displayTimeZone)),
    ];
}
function renderOptionalMarkdownComments(viewModel, locale, displayTimeZone) {
    if (resolvePostCompletionComments(viewModel).mode !== "all") {
        return [];
    }
    return [
        "",
        `**${(0, catalog_1.translate)(locale, "issue.command.show.commentsHeading", {
            count: viewModel.comments.length,
        })}**`,
        ...renderMarkdownCommentTimeline(viewModel.comments, locale, displayTimeZone),
    ];
}
function renderOptionalTextComments(viewModel, locale, displayTimeZone) {
    if (resolvePostCompletionComments(viewModel).mode !== "all") {
        return [];
    }
    return [
        "",
        `${(0, catalog_1.translate)(locale, "issue.command.show.commentsHeading", {
            count: viewModel.comments.length,
        })}:`,
        ...renderTextCommentTimeline(viewModel.comments, locale, displayTimeZone),
    ];
}
function resolvePostCompletionComments(viewModel) {
    return (viewModel.postCompletionComments ?? {
        mode: "all",
        completedAt: null,
        comments: [],
        unavailable: false,
    });
}
function renderMarkdownCommentTimeline(comments, locale, displayTimeZone) {
    if (comments.length === 0) {
        return [`- ${(0, catalog_1.translate)(locale, "issue.command.show.none")}`];
    }
    return comments.flatMap((comment) => [
        `- ${(0, format_1.formatIssueReference)(`${comment.author} | ${(0, issue_report_1.formatIssueUpdatedAt)(comment.createdAt, locale, displayTimeZone)}`, comment.url, types_1.ISSUE_REPORT_FORMATS.markdown)}`,
        ...(0, format_1.toMarkdownCodeBlock)(comment.body).map((line) => `  ${line}`),
    ]);
}
function renderMarkdownPostCompletionCommentTimeline(comments, locale, displayTimeZone) {
    if (comments.length === 0) {
        return [`- ${(0, catalog_1.translate)(locale, "issue.command.show.none")}`];
    }
    return comments.map((comment) => `- ${(0, format_1.formatIssueReference)(`${comment.author} | ${(0, issue_report_1.formatIssueUpdatedAt)(comment.createdAt, locale, displayTimeZone)}`, comment.url, types_1.ISSUE_REPORT_FORMATS.markdown)}: ${(0, issue_report_1.formatCommentExcerpt)(comment)}`);
}
function renderTextCommentTimeline(comments, locale, displayTimeZone) {
    if (comments.length === 0) {
        return [(0, catalog_1.translate)(locale, "issue.command.show.none")];
    }
    return comments.flatMap((comment) => [
        `${comment.author} | ${(0, issue_report_1.formatIssueUpdatedAt)(comment.createdAt, locale, displayTimeZone)} | ${comment.url}`,
        comment.body,
        "",
    ]);
}
function renderTextPostCompletionCommentTimeline(comments, locale, displayTimeZone) {
    if (comments.length === 0) {
        return [(0, catalog_1.translate)(locale, "issue.command.show.none")];
    }
    return comments.map((comment) => `${comment.author} | ${(0, issue_report_1.formatIssueUpdatedAt)(comment.createdAt, locale, displayTimeZone)} | ${comment.url} | ${(0, issue_report_1.formatCommentExcerpt)(comment)}`);
}
