/**
 * React Router analyzer
 * Analyzes React Router route definitions
 */
import * as fs from 'fs';
import * as path from 'path';
/**
 * Analyze React Router routes
 */
export async function analyzeReactRouter(routesFile = 'src/routes.tsx') {
    const routes = [];
    try {
        const routesPath = path.join(process.cwd(), routesFile);
        if (!fs.existsSync(routesPath)) {
            console.warn(`Routes file not found: ${routesFile}`);
            return routes;
        }
        const content = fs.readFileSync(routesPath, 'utf-8');
        // Extract routes from React Router
        // Look for <Route path="/..." />
        const routeRegex = /<Route\s+path=["']([^"']+)["']/g;
        let match;
        while ((match = routeRegex.exec(content)) !== null) {
            const routePath = match[1];
            routes.push({
                method: 'GET',
                path: routePath,
                description: `React Router: ${routePath}`,
                tags: ['frontend'],
                middleware: [],
                parameters: extractParameters(routePath),
                responses: {
                    '200': { description: 'Page rendered' }
                }
            });
        }
        // Also check for createBrowserRouter routes
        const browserRouterRegex = /path:\s*["']([^"']+)["']/g;
        while ((match = browserRouterRegex.exec(content)) !== null) {
            const routePath = match[1];
            if (!routes.find(r => r.path === routePath)) {
                routes.push({
                    method: 'GET',
                    path: routePath,
                    description: `React Router: ${routePath}`,
                    tags: ['frontend'],
                    middleware: [],
                    parameters: extractParameters(routePath),
                    responses: {
                        '200': { description: 'Page rendered' }
                    }
                });
            }
        }
        console.log(`✅ Found ${routes.length} React Router routes`);
    }
    catch (error) {
        console.error('Error analyzing React Router:', error.message);
    }
    return routes;
}
/**
 * Extract parameters from route path
 */
function extractParameters(routePath) {
    const params = [];
    const paramMatches = routePath.match(/:(\w+)/g) || [];
    paramMatches.forEach(param => {
        const name = param.slice(1);
        params.push({
            name,
            in: 'path',
            required: true,
            type: 'string',
            description: `Path parameter: ${name}`
        });
    });
    return params;
}
