// tools/suggest-tooling/frontend-perf-catalog.ts — SPEC-057
// Generates tooling recommendations for frontend performance, MFE management,
// design systems, and E2E testing.
// Criteria: S3 (Lighthouse CI), S7 (Bit.dev/Nx Cloud), S11 (Storybook/Ladle),
//           S13 (Playwright/Cypress), S15 (Chromatic)
// ---------------------------------------------------------------------------
// Helpers
// ---------------------------------------------------------------------------
function isJsTsProject(knowledge) {
    const lang = knowledge.language.toLowerCase();
    return lang === 'typescript' || lang === 'javascript';
}
function hasMfeDetected(knowledge) {
    const mfe = knowledge.mfeDetection;
    if (!mfe) {
        return false;
    }
    return mfe.moduleFederation !== undefined || mfe.singleSpa === true || mfe.nxMfe === true;
}
function hasModuleFederation(knowledge) {
    return knowledge.mfeDetection?.moduleFederation !== undefined;
}
// ---------------------------------------------------------------------------
// S3: Lighthouse CI recommendation
// ---------------------------------------------------------------------------
function buildLighthouseCiLines(detection) {
    if (detection.hasPerformanceBudget) {
        return [];
    }
    return [
        '- **Lighthouse CI** — Automated performance budget enforcement in CI',
        '  - Install: `npm install -D @lhci/cli`',
        '  - Config: create `.lighthouserc.json` with performance budgets (LCP < 2.5s, CLS < 0.1)',
        '  - Docs: https://github.com/GoogleChrome/lighthouse-ci',
        '',
    ];
}
// ---------------------------------------------------------------------------
// S7: Bit.dev / Nx Cloud for MFE
// ---------------------------------------------------------------------------
function buildMfeToolingLines(knowledge) {
    if (!hasMfeDetected(knowledge)) {
        return [];
    }
    const lines = [];
    if (hasModuleFederation(knowledge)) {
        lines.push('- **Nx Cloud** — Distributed build cache and task execution for Module Federation monorepos', '  - Install: `npx nx connect`', '  - Benefits: shared build cache across MFE teams, affected-only CI runs', '  - Docs: https://nx.dev/ci/intro/nx-cloud', '');
    }
    lines.push('- **Bit.dev** — Component-driven development and versioning for micro-frontends', '  - Install: `npx @teambit/bvm install`', '  - Benefits: independent component versioning, cross-MFE dependency tracking', '  - Docs: https://bit.dev/docs', '');
    return lines;
}
// ---------------------------------------------------------------------------
// S11: Storybook / Ladle recommendation
// ---------------------------------------------------------------------------
function buildDesignSystemToolingLines(detection) {
    // Only recommend if no Storybook/Ladle already present
    if (detection.hasStorybook || detection.hasDesignSystem) {
        return [];
    }
    return [
        '- **Storybook 8** — Component development environment and design system documentation',
        '  - Install: `npx storybook@latest init`',
        '  - Benefits: isolated component development, visual testing, auto-generated docs',
        '  - Alternative: **Ladle** for lightweight Vite-only setup (`npm install -D @ladle/react`)',
        '  - Docs: https://storybook.js.org',
        '',
    ];
}
// ---------------------------------------------------------------------------
// S13: Playwright / Cypress recommendation
// ---------------------------------------------------------------------------
function buildE2eToolingLines(detection) {
    if (detection.hasE2eFramework) {
        return [];
    }
    return [
        '- **Playwright** — Modern E2E testing with multi-browser support',
        '  - Install: `npm init playwright@latest`',
        '  - Benefits: auto-wait, trace viewer, component testing, multi-browser parallel execution',
        '  - Alternative: **Cypress** for teams preferring a GUI-first approach (`npm install -D cypress`)',
        '  - Docs: https://playwright.dev',
        '',
    ];
}
// ---------------------------------------------------------------------------
// S15: Chromatic recommendation
// ---------------------------------------------------------------------------
function buildChromaticLines(detection) {
    if (!detection.hasStorybook) {
        return [];
    }
    return [
        '- **Chromatic** — Visual regression testing and review platform for Storybook',
        '  - Install: `npm install -D chromatic`',
        '  - Benefits: automated screenshot comparison per PR, Storybook publishing, UI review workflow',
        '  - Docs: https://www.chromatic.com/docs',
        '',
    ];
}
// ---------------------------------------------------------------------------
// Main export
// ---------------------------------------------------------------------------
/**
 * SPEC-057: Build frontend performance and architecture tooling recommendation lines.
 * Returns markdown lines for suggest_tooling output.
 */
export function buildFrontendPerfToolingLines(knowledge, detection) {
    if (!isJsTsProject(knowledge)) {
        return [];
    }
    if (!detection) {
        return [];
    }
    const lines = [];
    const sections = [
        buildLighthouseCiLines(detection),
        buildMfeToolingLines(knowledge),
        buildDesignSystemToolingLines(detection),
        buildE2eToolingLines(detection),
        buildChromaticLines(detection),
    ];
    const nonEmpty = sections.filter((s) => s.length > 0);
    if (nonEmpty.length === 0) {
        return [];
    }
    lines.push('## Frontend Architecture Tooling', '');
    for (const section of nonEmpty) {
        lines.push(...section);
    }
    return lines;
}
//# sourceMappingURL=frontend-perf-catalog.js.map