import { getFigmaConfig, saveFigmaFlows } from '../../storage/figma-store.js';
import { getFigmaFile, parseFigmaUrl } from '../../engine/figma/api-client.js';
import { extractFlows, groupFlowsBySection as groupFlowsBySectionEngine, formatFlowsAsMarkdown, } from '../../engine/figma/flow-analyzer.js';
import { FIGMA_NOT_CONNECTED } from './shared.js';
export async function handleAnalyzeFigmaFlows(input) {
    const config = await getFigmaConfig(input.projectPath);
    if (config === null) {
        return FIGMA_NOT_CONNECTED;
    }
    const parsed = parseFigmaUrl(input.figmaUrl);
    const figmaFile = await getFigmaFile(parsed.fileKey, config.accessToken);
    const flows = extractFlows(figmaFile);
    await saveFigmaFlows(input.projectPath, flows);
    const sections = groupFlowsBySectionEngine(flows);
    const md = formatFlowsAsMarkdown(sections);
    return { content: [{ type: 'text', text: md }] };
}
//# sourceMappingURL=flows.js.map