// tools/generate-spec-from-design.ts — Generate a Planu spec from a UI/UX design description (SPEC-159)
import { handleCreateSpec } from './create-spec.js';
// ---------------------------------------------------------------------------
// Acceptance criteria generator
// ---------------------------------------------------------------------------
function buildAcceptanceCriteria(input) {
    const criteria = [];
    for (const screen of input.screens ?? []) {
        criteria.push(`- [ ] ${screen} screen renders correctly with all specified elements`);
    }
    for (const flow of input.userFlows ?? []) {
        criteria.push(`- [ ] ${flow}`);
    }
    for (const component of input.components ?? []) {
        criteria.push(`- [ ] ${component} behaves as described`);
    }
    criteria.push('- [ ] Design matches the provided specification — no missing elements or layout deviations');
    criteria.push('- [ ] All interactive elements have visible loading/disabled states');
    criteria.push('- [ ] Screen is responsive / accessible (keyboard navigable, ARIA labels on interactive elements)');
    return criteria;
}
// ---------------------------------------------------------------------------
// Spec content builder
// ---------------------------------------------------------------------------
function buildSpecContent(input, criteria) {
    const lines = [];
    lines.push(`# ${input.title}`, '');
    lines.push('## Description', input.designDescription, '');
    if ((input.screens ?? []).length > 0) {
        lines.push('## Screens');
        for (const screen of input.screens ?? []) {
            lines.push(`- ${screen}`);
        }
        lines.push('');
    }
    if ((input.userFlows ?? []).length > 0) {
        lines.push('## User Flows');
        for (const flow of input.userFlows ?? []) {
            lines.push(`- ${flow}`);
        }
        lines.push('');
    }
    lines.push('## Acceptance Criteria', ...criteria, '');
    if ((input.components ?? []).length > 0) {
        lines.push('## Design Notes');
        lines.push(`Components involved: ${(input.components ?? []).join(', ')}`);
        lines.push('');
    }
    return lines.join('\n');
}
// ---------------------------------------------------------------------------
// Tag deduplication helper
// ---------------------------------------------------------------------------
function buildTags(providedTags) {
    const autoTags = ['design', 'frontend', 'ux'];
    const combined = [...providedTags, ...autoTags];
    return [...new Set(combined)];
}
// ---------------------------------------------------------------------------
// Handler
// ---------------------------------------------------------------------------
export async function handleGenerateSpecFromDesign(args) {
    const criteria = buildAcceptanceCriteria(args);
    const specContent = buildSpecContent(args, criteria);
    const tags = buildTags(args.tags ?? []);
    const createSpecResult = await handleCreateSpec({
        projectPath: args.projectPath,
        title: args.title,
        description: specContent,
        type: args.type ?? 'feature',
        scope: 'feature',
        target: 'frontend',
        tags,
    });
    if (createSpecResult.isError === true) {
        return createSpecResult;
    }
    const note = 'Generated from design description. Review and adjust acceptance criteria to match your design system.';
    const existingText = createSpecResult.content[0]?.type === 'text' ? createSpecResult.content[0].text : '';
    return {
        ...createSpecResult,
        content: [
            {
                type: 'text',
                text: `${existingText}\n\n> ${note}`,
            },
        ],
    };
}
//# sourceMappingURL=generate-spec-from-design.js.map