import { extractPerSpecData } from './spec-data-extractor.js';
import { buildSpecHeaderSection, buildAffectedFilesSection, buildArchDecisionsSection, buildSpecFooterSection, } from './spec-section-builders.js';
import { renderMermaidDiagrams, getMermaidScript } from './mermaid-renderer.js';
import { wrapPerSpecHtml } from './html-wrapper.js';
/**
 * Generate a self-contained HTML technical report for a single spec.
 * Includes: header, Mermaid diagrams, affected files, architectural decisions.
 */
export function generatePerSpecTechnicalReport(spec, diagrams, affectedFiles, architecturalDecisions) {
    const data = extractPerSpecData(spec, affectedFiles, architecturalDecisions);
    const scopeInfo = `<div class="section">
  <h2>Scope</h2>
  <p><strong>Scope:</strong> ${escapeHtml(data.scope)} &middot; <strong>Target:</strong> ${escapeHtml(data.target)}</p>
  ${data.gitBranch ? `<p><strong>Branch:</strong> <code>${escapeHtml(data.gitBranch)}</code></p>` : ''}
</div>`;
    const diagramsSection = diagrams.length > 0
        ? `<div class="section"><h2>Diagrams</h2>${renderMermaidDiagrams(diagrams)}</div>`
        : '';
    const body = [
        buildSpecHeaderSection(data),
        scopeInfo,
        diagramsSection,
        buildAffectedFilesSection(data.affectedFiles),
        buildArchDecisionsSection(data.architecturalDecisions),
        buildSpecFooterSection(),
    ]
        .filter(Boolean)
        .join('\n');
    const title = `Technical Report — ${data.specId}: ${data.title}`;
    const mermaidScript = diagrams.length > 0 ? getMermaidScript() : '';
    const content = wrapPerSpecHtml(title, body, mermaidScript);
    return {
        type: 'per-spec-technical',
        title,
        path: `technical-report.html`,
        content,
        audience: 'developer',
        sections: [],
        diagrams,
        relatedSpecs: [data.specId],
    };
}
function escapeHtml(str) {
    return str
        .replace(/&/g, '&amp;')
        .replace(/</g, '&lt;')
        .replace(/>/g, '&gt;')
        .replace(/"/g, '&quot;');
}
//# sourceMappingURL=technical-report.js.map