// Planu — Compliance gap analyzer (SPEC-402)
import { getControlsForFramework, findMatchingControls, } from './framework-catalog.js';
export function analyzeComplianceGaps(framework, specs) {
    const controls = getControlsForFramework(framework);
    const coverageMap = [];
    for (const control of controls) {
        const matchingSpecs = specs.filter((s) => {
            const matches = findMatchingControls(framework, s.title, s.description ?? '');
            return matches.some((m) => m.id === control.id);
        });
        const status = matchingSpecs.length === 0
            ? 'missing'
            : matchingSpecs.some((s) => s.status === 'done')
                ? 'passing'
                : 'partial';
        coverageMap.push({
            controlId: control.id,
            controlName: control.name,
            status,
            coveringSpecIds: matchingSpecs.map((s) => s.id),
            requiredCriteria: control.requiredCriteria,
        });
    }
    const passing = coverageMap.filter((c) => c.status === 'passing').length;
    const score = controls.length === 0 ? 100 : Math.round((passing / controls.length) * 100);
    return {
        framework,
        score,
        totalControls: controls.length,
        passing,
        partial: coverageMap.filter((c) => c.status === 'partial').length,
        missing: coverageMap.filter((c) => c.status === 'missing').length,
        coverage: coverageMap,
        recommendations: coverageMap
            .filter((c) => c.status === 'missing')
            .map((c) => `Create spec addressing: ${c.controlName} (${c.controlId})`),
    };
}
//# sourceMappingURL=gap-analyzer.js.map