import { getCdnUrl } from '../../../config/version-defaults.js';
/**
 * Render an array of SpecDiagrams as HTML sections with Mermaid pre blocks.
 * Uses Mermaid.js CDN for client-side rendering with raw code fallback.
 */
export function renderMermaidDiagrams(diagrams) {
    if (diagrams.length === 0) {
        return '<p class="empty">No diagrams available for this spec.</p>';
    }
    return diagrams.map((d) => renderSingleDiagram(d)).join('\n');
}
function renderSingleDiagram(diagram) {
    const escapedTitle = escapeHtml(diagram.title);
    const escapedDesc = escapeHtml(diagram.description);
    const escapedContent = escapeHtml(diagram.content);
    return `<div class="diagram-section">
  <h3>${escapedTitle}</h3>
  <p class="diagram-desc">${escapedDesc}</p>
  <pre class="mermaid">${escapedContent}</pre>
</div>`;
}
/**
 * Generate the Mermaid.js CDN script tag with initialization.
 * Includes fallback: if CDN fails, shows raw code.
 */
export function getMermaidScript() {
    return `<script type="module">
  import mermaid from '${getCdnUrl('mermaid')}/mermaid.esm.min.mjs';
  mermaid.initialize({ startOnLoad: true, theme: 'default' });
</script>
<noscript><style>.mermaid { white-space: pre; font-family: monospace; background: #f3f4f6; padding: 16px; border-radius: 8px; }</style></noscript>`;
}
function escapeHtml(str) {
    return str
        .replace(/&/g, '&amp;')
        .replace(/</g, '&lt;')
        .replace(/>/g, '&gt;')
        .replace(/"/g, '&quot;');
}
//# sourceMappingURL=mermaid-renderer.js.map