import { listSpecs } from '../../storage/spec-store.js';
import { hashProjectPath } from '../../storage/base-store.js';
import { generateSpecId } from '../spec-format/spec-id.js';
// ---------------------------------------------------------------------------
// generateSpecsForSections — create one FigmaGeneratedSpec per section
// ---------------------------------------------------------------------------
export async function generateSpecsForSections(projectPath, sections, sectionFilter) {
    const projectId = hashProjectPath(projectPath);
    const existingSpecs = await listSpecs(projectId);
    const sectionNames = [...sections.keys()];
    const filtered = sectionFilter !== undefined
        ? sectionNames.filter((name) => name.startsWith(sectionFilter))
        : sectionNames;
    const now = new Date().toISOString();
    const generated = [];
    // Build a rolling list so each new spec gets a unique ID
    const allSpecs = [...existingSpecs];
    for (const sectionName of filtered) {
        const frames = sections.get(sectionName) ?? [];
        if (frames.length === 0) {
            continue;
        }
        const specId = generateSpecId(allSpecs);
        allSpecs.push({ id: specId });
        generated.push({
            section: sectionName,
            specId,
            frameCount: frames.length,
            nodeIds: frames.map((f) => f.nodeId),
            createdAt: now,
        });
    }
    return generated;
}
//# sourceMappingURL=spec-generator.js.map