// ── Helpers ─────────────────────────────────────────────────────────────────
function statusToBadgeClass(status) {
    switch (status) {
        case 'draft':
            return 'badge-draft';
        case 'review':
            return 'badge-review';
        case 'approved':
            return 'badge-approved';
        case 'implementing':
            return 'badge-implementing';
        case 'done':
            return 'badge-done';
        default:
            return 'badge-draft';
    }
}
function formatUsd(amount) {
    return amount.toLocaleString('en-US', {
        style: 'currency',
        currency: 'USD',
        maximumFractionDigits: 0,
    });
}
function metricCard(value, label) {
    return `<div class="metric-card"><div class="metric-value">${value}</div><div class="metric-label">${label}</div></div>`;
}
// ── Section builders ─────────────────────────────────────────────────────────
/** Header section: project name, spec count, generated date. */
export function buildHeaderSection(projectName, generatedAt, specCount) {
    const date = new Date(generatedAt).toLocaleDateString('en-US', {
        year: 'numeric',
        month: 'long',
        day: 'numeric',
    });
    return `<div class="header">
  <h1>Planu — Executive Summary</h1>
  <h2>${escapeHtml(projectName)}</h2>
  <div class="meta"><span class="badge badge-draft">${specCount} spec${specCount !== 1 ? 's' : ''}</span>&nbsp; Generated on ${date}</div>
</div>`;
}
/** Overview section: language, framework, database, layer count. */
export function buildOverviewSection(arch) {
    return `<div class="section">
  <h2>Project Overview</h2>
  <div class="metric-grid">
    ${metricCard(escapeHtml(arch.language), 'Language')}
    ${metricCard(escapeHtml(arch.framework), 'Framework')}
    ${metricCard(escapeHtml(arch.database), 'Database')}
    ${metricCard(String(arch.layers.length), 'Architecture Layers')}
  </div>
</div>`;
}
/** Specs table section. Adds actual columns if any spec has actuals. */
export function buildSpecsTableSection(specs) {
    const hasActuals = specs.some((s) => s.actualDevHours !== undefined);
    const header = `<tr>
    <th>ID</th><th>Title</th><th>Status</th><th>Difficulty</th><th>Risk</th><th>Dev Hours</th><th>Cost (est.)</th>
    ${hasActuals ? '<th>Actual Hours</th><th>Actual Cost</th>' : ''}
  </tr>`;
    const rows = specs
        .map((s) => {
        const badgeClass = statusToBadgeClass(s.status);
        const actualCols = hasActuals
            ? `<td>${s.actualDevHours !== undefined ? String(s.actualDevHours) : '—'}</td><td>${s.actualTotalCostUsd !== undefined ? formatUsd(s.actualTotalCostUsd) : '—'}</td>`
            : '';
        return `<tr>
    <td>${escapeHtml(s.id)}</td>
    <td>${escapeHtml(s.title)}</td>
    <td><span class="badge ${badgeClass}">${s.status}</span></td>
    <td>${s.difficulty}</td>
    <td>${s.risk}</td>
    <td>${s.devHours}h</td>
    <td>${formatUsd(s.totalCostUsd)}</td>
    ${actualCols}
  </tr>`;
    })
        .join('');
    return `<div class="section">
  <h2>Specifications</h2>
  <table>${header}${rows}</table>
</div>`;
}
/** Estimation section: totals, and side-by-side if actuals available. */
export function buildEstimationSection(est, hasActuals, actualEstimation) {
    const cards = `<div class="metric-grid">
    ${metricCard(String(est.totalDevHours) + 'h', 'Total Dev Hours')}
    ${metricCard(String(est.totalReviewHours) + 'h', 'Review Hours')}
    ${metricCard(formatUsd(est.totalHumanCostUsd), 'Human Cost')}
    ${metricCard(formatUsd(est.totalApiCostUsd), 'API Cost')}
    ${metricCard(formatUsd(est.totalCostUsd), 'Total Cost')}
  </div>`;
    let actualsBlock = '';
    if (hasActuals && actualEstimation !== undefined) {
        const delta = est.totalCostUsd > 0
            ? Math.round(((actualEstimation.totalCostUsd - est.totalCostUsd) / est.totalCostUsd) * 100)
            : 0;
        const sign = delta >= 0 ? '+' : '';
        actualsBlock = `<p style="margin-top:8px;font-size:0.85em;color:#6b7280;">Actual total: <strong>${formatUsd(actualEstimation.totalCostUsd)}</strong> — ${sign}${delta}% vs estimate</p>`;
    }
    return `<div class="section">
  <h2>Cost Estimation</h2>
  ${cards}
  ${actualsBlock}
</div>`;
}
/** Risk section: metric cards + SVG bar + highlights. */
export function buildRiskSection(risk, svgContent) {
    const highlights = risk.highlights.length > 0
        ? risk.highlights.map((h) => `<div class="risk-highlight">${escapeHtml(h)}</div>`).join('')
        : '<p style="color:#6b7280;font-size:0.85em;">No high-risk specs identified.</p>';
    return `<div class="section">
  <h2>Risk Assessment</h2>
  <div class="metric-grid">
    ${metricCard(String(risk.low), 'Low Risk')}
    ${metricCard(String(risk.medium), 'Medium Risk')}
    ${metricCard(String(risk.high), 'High Risk')}
    ${metricCard(String(risk.critical), 'Critical Risk')}
  </div>
  ${svgContent}
  <div style="margin-top:12px"><strong style="font-size:0.85em;color:#374151;">High &amp; Critical Specs:</strong>${highlights}</div>
</div>`;
}
/** Architecture section: language/framework/DB info + SVG. */
export function buildArchitectureSection(arch, svgContent) {
    return `<div class="section">
  <h2>Architecture</h2>
  <p style="margin-bottom:12px;font-size:0.9em;color:#374151;">
    <strong>${escapeHtml(arch.language)}</strong> project using <strong>${escapeHtml(arch.framework)}</strong> with <strong>${escapeHtml(arch.database)}</strong> — ${arch.layers.length} architecture layer${arch.layers.length !== 1 ? 's' : ''}.
  </p>
  ${svgContent}
</div>`;
}
/** Timeline section: SVG only. */
export function buildTimelineSection(svgContent) {
    return `<div class="section">
  <h2>Development Timeline</h2>
  ${svgContent}
</div>`;
}
/** Footer section. */
export function buildFooterSection() {
    return `<div class="footer">Generated by Planu &mdash; ${new Date().toUTCString()}</div>`;
}
function escapeHtml(str) {
    return str
        .replace(/&/g, '&amp;')
        .replace(/</g, '&lt;')
        .replace(/>/g, '&gt;')
        .replace(/"/g, '&quot;');
}
//# sourceMappingURL=section-builders.js.map