export function renderIndex(pages) {
    const lines = ['# AE Docs Wiki — Index', '', '| 页面 | 分类路径 | 原始链接 |', '|---|---|---|'];
    for (const p of pages) {
        const rel = p.outPath.replace(/^wiki\/te-docs\//, '');
        const cat = p.pathSegments.slice(0, -1).join(' / ') || '—';
        lines.push(`| [${p.name}](${rel}) | ${cat} | [docs](${p.sourceUrl}) |`);
    }
    lines.push('');
    return lines.join('\n');
}
export function renderLog(reports, pages) {
    const ok = reports.filter((r) => r.status === 'ok');
    const fail = reports.filter((r) => r.status === 'fail');
    const unsupported = new Map();
    for (const r of reports) {
        for (const t of r.unsupportedBlocks ?? []) {
            unsupported.set(t, (unsupported.get(t) ?? 0) + 1);
        }
    }
    const lines = [
        '# AE Docs Wiki — Build Log',
        '',
        `Built: ${new Date().toISOString()}`,
        `Pages planned: ${pages.length}`,
        `ok: ${ok.length}`,
        `fail: ${fail.length}`,
        '',
        '## Failures',
    ];
    if (fail.length === 0) {
        lines.push('(none)');
    }
    else {
        for (const r of fail)
            lines.push(`- ${r.wikiToken} → ${r.outPath}: ${r.reason ?? 'unknown'}`);
    }
    lines.push('', '## Unsupported blocks encountered');
    if (unsupported.size === 0) {
        lines.push('(none)');
    }
    else {
        for (const [t, n] of [...unsupported.entries()].sort((a, b) => a[0] - b[0])) {
            lines.push(`- unsupported type ${t}: ${n} occurrences`);
        }
    }
    lines.push('');
    return lines.join('\n');
}
export function renderSchema() {
    return [
        '# AE Docs Wiki Schema',
        '',
        '## Layout',
        '- `index.md` — catalog of pages with raw paths and source URLs',
        '- `raw/` — Feishu docx → markdown mirror (read-only, crawler-owned)',
        '- `synthesis/` — topic pages authored by synthesizer agents',
        '- `log.md` — last build report',
        '',
        '## Query flow for consuming skills',
        '1. Read `index.md` first.',
        '2. For topic overviews, prefer `synthesis/`.',
        '3. For exact API / config lookup, read `raw/`.',
        '4. Cite `sourceUrl` from page frontmatter when quoting.',
        '',
        '## Rules',
        '- Do not edit `raw/` — it is regenerated by the crawler.',
        '- Hand-authored or LLM-synthesized notes go in `synthesis/`.',
        '',
    ].join('\n');
}
