"use strict";
/**
 * Svelte Integration Detector
 *
 * Detects Svelte/SvelteKit usage and generates Svelte-optimized .faf context
 */
Object.defineProperty(exports, "__esModule", { value: true });
exports.svelteDetector = void 0;
const fs_1 = require("fs");
const path_1 = require("path");
exports.svelteDetector = {
    name: 'svelte',
    displayName: 'Svelte',
    tier: 'gold', // Based on evaluation: Svelte will score 95+
    qualityScore: 96,
    weeklyAdoption: 400_000, // ~400k weekly downloads
    mcpServers: [
        '@playwright/mcp', // #2: 625k/week - Browser automation & testing
        'mcp-proxy', // #6: 197k/week - Infrastructure & proxy
        'chrome-devtools-mcp', // #7: 156k/week - Chrome DevTools debugging
        '@mastra/mcp', // #8: 130k/week - AI workflows & automation
        '@langchain/mcp-adapters', // #13: 42k/week - LangChain AI integration
        '@mzxrai/mcp-webresearch', // #14: 36k/week - Web research tools
    ],
    contextContribution: ['frontend', 'ui_library', 'state_management'],
    detect(projectPath) {
        const packageJsonPath = (0, path_1.join)(projectPath, 'package.json');
        if (!(0, fs_1.existsSync)(packageJsonPath)) {
            return false;
        }
        try {
            const packageJson = JSON.parse((0, fs_1.readFileSync)(packageJsonPath, 'utf-8'));
            const allDeps = {
                ...packageJson.dependencies,
                ...packageJson.devDependencies,
            };
            return 'svelte' in allDeps || '@sveltejs/kit' in allDeps;
        }
        catch {
            return false;
        }
    },
    generateContext(projectPath) {
        const packageJsonPath = (0, path_1.join)(projectPath, 'package.json');
        let version = 'unknown';
        let isSvelteKit = false;
        let hasTypeScript = false;
        if ((0, fs_1.existsSync)(packageJsonPath)) {
            try {
                const packageJson = JSON.parse((0, fs_1.readFileSync)(packageJsonPath, 'utf-8'));
                const allDeps = {
                    ...packageJson.dependencies,
                    ...packageJson.devDependencies,
                };
                version = allDeps.svelte || allDeps['@sveltejs/kit'] || 'latest';
                isSvelteKit = '@sveltejs/kit' in allDeps;
                hasTypeScript = 'typescript' in allDeps || (0, fs_1.existsSync)((0, path_1.join)(projectPath, 'tsconfig.json'));
            }
            catch {
                // Fallback to defaults
            }
        }
        // Check for SvelteKit structure
        const svelteConfigExists = (0, fs_1.existsSync)((0, path_1.join)(projectPath, 'svelte.config.js'));
        const baseContext = {
            stack: {
                frontend: `Svelte ${version}`,
                ui_library: 'Svelte Components',
                state_management: 'Svelte Stores',
                main_language: hasTypeScript ? 'TypeScript' : 'JavaScript',
            },
            integration: {
                framework: 'svelte',
                mcp_servers: this.mcpServers,
                recommended_tools: [
                    '@playwright/mcp - Browser automation & testing (625k weekly)',
                    'mcp-proxy - Infrastructure & proxy (197k weekly)',
                    'chrome-devtools-mcp - Chrome DevTools debugging (156k weekly)',
                    '@mastra/mcp - AI workflows & automation (130k weekly)',
                    '@langchain/mcp-adapters - LangChain AI integration (42k weekly)',
                    '@mzxrai/mcp-webresearch - Web research tools (36k weekly)',
                    'Svelte DevTools',
                    'Vite for build tooling',
                ],
            },
        };
        // Add SvelteKit-specific context
        if (isSvelteKit) {
            baseContext.stack = {
                ...baseContext.stack,
                backend: 'SvelteKit Server Routes',
                build: 'Vite + SvelteKit',
                api_type: 'REST (SvelteKit endpoints)',
            };
            baseContext.project = {
                architecture: 'SvelteKit Full-Stack',
            };
        }
        return baseContext;
    },
};
//# sourceMappingURL=svelte.js.map