/**
 * ADR-PIPELINE-071 §5: Consensus visualization.
 *
 * Pure-string SVG generator. Produces a horizontal bar chart showing the
 * per-dimension agreement level (financial / operational / compliance /
 * workforce / technical). Embedded inline in directional and contested
 * executive summaries so the visual story matches the textual one.
 *
 * No external dependencies — outputs an SVG 1.1 document.
 */
const DIMENSION_ORDER = [
    'financial',
    'operational',
    'compliance',
    'workforce',
    'technical',
];
const DIMENSION_LABEL = {
    financial: 'Financial',
    operational: 'Operational',
    compliance: 'Compliance',
    workforce: 'Workforce',
    technical: 'Technical',
};
const TIER_COLOR = {
    aligned: '#16a34a', // green
    directional: '#f59e0b', // amber
    contested: '#dc2626', // red
};
export function renderConsensusSvg(snapshot, options = {}) {
    const width = options.width ?? 600;
    const barHeight = options.barHeight ?? 24;
    const padding = 40;
    const labelWidth = 110;
    const trackHeight = barHeight + 12;
    const headerHeight = 70;
    const footerHeight = 30;
    const chartHeight = trackHeight * DIMENSION_ORDER.length;
    const totalHeight = headerHeight + chartHeight + footerHeight;
    const chartLeft = padding + labelWidth;
    const chartRight = width - padding;
    const chartWidth = chartRight - chartLeft;
    const fillColor = TIER_COLOR[snapshot.tier];
    const trackColor = '#e5e7eb';
    const axisColor = '#9ca3af';
    const textColor = '#111827';
    const title = options.title ?? `Consensus: ${snapshot.tier}`;
    const lines = [];
    lines.push(`<svg xmlns="http://www.w3.org/2000/svg" width="${width}" height="${totalHeight}" viewBox="0 0 ${width} ${totalHeight}" role="img" aria-labelledby="consensus-svg-title">`);
    lines.push(`  <title id="consensus-svg-title">${escapeXml(title)}</title>`);
    // Background
    lines.push(`  <rect width="${width}" height="${totalHeight}" fill="#ffffff" />`);
    // Header text
    lines.push(`  <text x="${padding}" y="${padding}" font-family="-apple-system, system-ui, sans-serif" font-size="18" font-weight="700" fill="${textColor}">${escapeXml(title)}</text>`);
    lines.push(`  <text x="${padding}" y="${padding + 22}" font-family="-apple-system, system-ui, sans-serif" font-size="12" fill="${axisColor}">Agreement: ${snapshot.agreementLevelPct}% · Precision: ${snapshot.precisionConfidencePct}% · Direction: ${snapshot.directionalConfidencePct}%</text>`);
    // Bars
    for (let i = 0; i < DIMENSION_ORDER.length; i++) {
        const dim = DIMENSION_ORDER[i];
        const fraction = clamp01(snapshot.perDimension[dim] ?? 0.5);
        const barWidth = Math.max(2, Math.round(chartWidth * fraction));
        const barY = headerHeight + i * trackHeight + 4;
        const labelY = barY + barHeight - 6;
        // Label
        lines.push(`  <text x="${padding}" y="${labelY}" font-family="-apple-system, system-ui, sans-serif" font-size="13" fill="${textColor}">${escapeXml(DIMENSION_LABEL[dim])}</text>`);
        // Track
        lines.push(`  <rect x="${chartLeft}" y="${barY}" width="${chartWidth}" height="${barHeight}" rx="4" fill="${trackColor}" />`);
        // Filled bar
        lines.push(`  <rect x="${chartLeft}" y="${barY}" width="${barWidth}" height="${barHeight}" rx="4" fill="${fillColor}" />`);
        // Value text
        lines.push(`  <text x="${chartLeft + barWidth + 6}" y="${labelY}" font-family="-apple-system, system-ui, sans-serif" font-size="12" fill="${axisColor}">${Math.round(fraction * 100)}%</text>`);
    }
    // Footer
    const footerY = headerHeight + chartHeight + 18;
    lines.push(`  <text x="${padding}" y="${footerY}" font-family="-apple-system, system-ui, sans-serif" font-size="11" fill="${axisColor}">Generated by ADR-PIPELINE-071 (consensus tier: ${snapshot.tier})</text>`);
    lines.push('</svg>');
    return lines.join('\n');
}
function clamp01(n) {
    if (!Number.isFinite(n))
        return 0;
    if (n < 0)
        return 0;
    if (n > 1)
        return 1;
    return n;
}
function escapeXml(s) {
    return s
        .replace(/&/g, '&amp;')
        .replace(/</g, '&lt;')
        .replace(/>/g, '&gt;')
        .replace(/"/g, '&quot;')
        .replace(/'/g, '&apos;');
}
//# sourceMappingURL=consensus-svg.js.map