import { escapeHtml } from "./gate-report-html.js";
/** How each verdict is headed, in the operator's words. */
const VERDICT_HEADINGS = {
    matched: "Declared required, and enforced",
    "declared-not-enforced": "Declared required — enforced by nothing",
    "enforced-declared-optional": "Enforced, declared optional",
    "enforced-declared-off": "Enforced, declared OFF",
    "enforced-undeclared": "Enforced, governed by no declaration",
    "enforced-not-lisa-owned": "Enforced, produced by no Lisa gate",
};
/** Which verdicts are drawn as sharp rather than neutral. */
const SHARP_VERDICTS = new Set([
    "declared-not-enforced",
    "enforced-declared-off",
]);
/** The verdicts, in the order an operator should read them. */
const VERDICT_ORDER = [
    "enforced-declared-off",
    "declared-not-enforced",
    "enforced-undeclared",
    "enforced-declared-optional",
    "enforced-not-lisa-owned",
    "matched",
];
/**
 * One verdict's card, listing every context that earned it.
 * @param report - The completed comparison
 * @param verdict - The verdict to card
 * @returns A card of HTML, or an empty string when nothing earned it
 */
function verdictCard(report, verdict) {
    const entries = report.entries.filter(entry => entry.verdict === verdict);
    if (entries.length === 0)
        return "";
    const items = entries
        .map(entry => `<li><code>${escapeHtml(entry.context)}</code><div class="lgr-why">${escapeHtml(entry.detail)}</div><div class="lgr-why">remedy: <strong>${escapeHtml(entry.remedy)}</strong></div></li>`)
        .join("");
    return `<div${SHARP_VERDICTS.has(verdict) ? ' class="lgr-sharp"' : ""}><h3>${escapeHtml(VERDICT_HEADINGS[verdict])} <span class="lgr-count">${entries.length}</span></h3><ul>${items}</ul></div>`;
}
/**
 * One enforcing surface's comparison — including the case where it was unread.
 * @param finding - The comparison, or why there is none
 * @param title - How to name the surface
 * @returns A block of HTML
 */
function driftBlock(finding, title) {
    if (finding.state !== "verified") {
        return `<h3 class="lgr-surface">${escapeHtml(title)}</h3><p class="lgr-note">Not compared this run — <strong>${escapeHtml(finding.reason)}</strong>. ${escapeHtml(finding.message)} This is <em>not</em> a match.</p>`;
    }
    return [
        `<h3 class="lgr-surface">${escapeHtml(title)}</h3>`,
        '<div class="lgr-cols">',
        VERDICT_ORDER.map(verdict => verdictCard(finding.value, verdict)).join(""),
        "</div>",
    ].join("");
}
/**
 * The declaration-versus-enforcement section, one block per surface.
 * @param report - The whole report
 * @returns A section of HTML
 */
export function declarationDriftSection(report) {
    return [
        driftBlock(report.declarationDrift.templates, "Against the ruleset template this repository is provisioned from"),
        driftBlock(report.declarationDrift.live, "Against the live branch-protection ruleset"),
    ].join("");
}
//# sourceMappingURL=gate-report-drift-section.js.map