// tools/storybook-handler.ts — Handlers for Storybook component sync tools (SPEC-432)
import { getStorybookComponents, saveStorybookComponents } from '../storage/storybook-store.js';
import { scanStorybookFiles, formatComponentsAsMarkdown, getComponentContext, } from '../engine/storybook/story-parser.js';
export async function handleSyncStorybook(input) {
    const result = await scanStorybookFiles(input.projectPath);
    await saveStorybookComponents(input.projectPath, result);
    const text = formatComponentsAsMarkdown(result);
    return { content: [{ type: 'text', text }] };
}
export async function handleListStorybookComponents(input) {
    const result = await getStorybookComponents(input.projectPath);
    if (result === null) {
        return {
            content: [
                {
                    type: 'text',
                    text: 'No Storybook data. Run sync_storybook_components first.',
                },
            ],
        };
    }
    const text = formatComponentsAsMarkdown(result);
    return { content: [{ type: 'text', text }] };
}
export async function handleInjectComponentContext(input) {
    const result = await getStorybookComponents(input.projectPath);
    if (result === null) {
        return {
            content: [
                {
                    type: 'text',
                    text: 'No Storybook data. Run sync_storybook_components first.',
                },
            ],
        };
    }
    const matches = getComponentContext(result.components, input.query);
    if (matches.length === 0) {
        return {
            content: [
                {
                    type: 'text',
                    text: `## Component Context for '${input.query}'\n\nNo matching components found.`,
                },
            ],
        };
    }
    const sections = [`## Component Context for '${input.query}'`, ''];
    for (const comp of matches) {
        sections.push(`### ${comp.componentName} (${comp.category})`);
        sections.push(`**Stories**: ${comp.storyNames.join(', ')}`);
        sections.push(`**Props**: ${comp.propNames.join(', ')}`);
        sections.push('');
    }
    return { content: [{ type: 'text', text: sections.join('\n') }] };
}
//# sourceMappingURL=storybook-handler.js.map