import { join } from 'node:path';
import { rm, access } from 'node:fs/promises';
import { generateDocsSite } from '../engine/docs-site-generator/index.js';
import { compactResult } from './output-formatter.js';
async function removeMisplacedDocsSite(projectPath) {
    const stale = join(projectPath, 'docs-site');
    try {
        await access(stale);
        await rm(stale, { recursive: true, force: true });
        return stale;
    }
    catch {
        return null;
    }
}
export async function handleGenerateDocsSite(params) {
    const removed = await removeMisplacedDocsSite(params.projectPath);
    const config = {
        projectPath: params.projectPath,
        outputDir: join(params.projectPath, 'planu', 'docs-site'),
        title: params.title,
    };
    const result = await generateDocsSite(config);
    return compactResult(JSON.stringify({
        success: true,
        pagesGenerated: result.pagesGenerated,
        outputDir: result.outputDir,
        pages: result.pages,
        ...(removed !== null && { removedStaleDir: removed }),
        message: `Documentation site generated with ${String(result.pagesGenerated)} pages at ${result.outputDir}`,
    }, null, 2));
}
//# sourceMappingURL=generate-docs-site.js.map