"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.renderOptionalMarkdownOriginIssues = renderOptionalMarkdownOriginIssues;
exports.renderOptionalTextOriginIssues = renderOptionalTextOriginIssues;
const catalog_1 = require("../../i18n/catalog");
const types_1 = require("../../issues/types");
const format_1 = require("./format");
function renderOptionalMarkdownOriginIssues(viewModel, locale) {
    if (viewModel.originIssues.items.length === 0) {
        return [];
    }
    return [
        "",
        `**${(0, catalog_1.translate)(locale, "issue.command.show.originIssuesHeading")}**`,
        ...viewModel.originIssues.items.map((item) => `- ${renderMarkdownOriginIssueItem(item, locale)}`),
        ...renderMarkdownHiddenOriginIssueCount(viewModel, locale),
    ];
}
function renderOptionalTextOriginIssues(viewModel, locale) {
    if (viewModel.originIssues.items.length === 0) {
        return [];
    }
    return [
        "",
        `${(0, catalog_1.translate)(locale, "issue.command.show.originIssuesHeading")}:`,
        ...viewModel.originIssues.items.map((item) => `- ${renderTextOriginIssueItem(item, locale)}`),
        ...renderTextHiddenOriginIssueCount(viewModel, locale),
    ];
}
function renderMarkdownOriginIssueItem(item, locale) {
    const segments = renderOriginIssueItemSegments(item, types_1.ISSUE_REPORT_FORMATS.markdown, locale);
    const [issueRef = "", ...rest] = segments;
    return [issueRef, ...rest.map(format_1.escapeMarkdownText)].join(" | ");
}
function renderTextOriginIssueItem(item, locale) {
    return renderOriginIssueItemSegments(item, types_1.ISSUE_REPORT_FORMATS.text, locale).join(" | ");
}
function renderMarkdownHiddenOriginIssueCount(viewModel, locale) {
    return viewModel.originIssues.truncated
        ? [`- ${(0, catalog_1.translate)(locale, "issue.command.show.originIssues.hidden")}`]
        : [];
}
function renderTextHiddenOriginIssueCount(viewModel, locale) {
    return viewModel.originIssues.truncated
        ? [(0, catalog_1.translate)(locale, "issue.command.show.originIssues.hidden")]
        : [];
}
function renderOriginIssueItemSegments(item, format, locale) {
    return [
        (0, format_1.formatIssueReference)(item.displayId, item.url, format),
        (0, catalog_1.translate)(locale, originIssueStateLabelKey(item.state)),
        item.title,
        ...(item.requestTitle !== null
            ? [
                (0, catalog_1.translate)(locale, "issue.command.show.originIssues.request", {
                    value: item.requestTitle,
                }),
            ]
            : []),
        ...(item.summary !== null
            ? [
                (0, catalog_1.translate)(locale, "issue.command.show.childIssues.summary", {
                    value: item.summary,
                }),
            ]
            : []),
    ];
}
function originIssueStateLabelKey(state) {
    switch (state) {
        case "open":
            return "issue.command.show.childIssues.state.open";
        case "closed":
            return "issue.command.show.childIssues.state.closed";
        case "pending":
            return "issue.command.show.childIssues.state.pending";
        case "unknown":
            return "issue.command.show.childIssues.state.unknown";
    }
}
