"use strict";
/**
 * React Router analyzer
 * Analyzes React Router route definitions
 */
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
    if (k2 === undefined) k2 = k;
    var desc = Object.getOwnPropertyDescriptor(m, k);
    if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
      desc = { enumerable: true, get: function() { return m[k]; } };
    }
    Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
    if (k2 === undefined) k2 = k;
    o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
    Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
    o["default"] = v;
});
var __importStar = (this && this.__importStar) || (function () {
    var ownKeys = function(o) {
        ownKeys = Object.getOwnPropertyNames || function (o) {
            var ar = [];
            for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
            return ar;
        };
        return ownKeys(o);
    };
    return function (mod) {
        if (mod && mod.__esModule) return mod;
        var result = {};
        if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
        __setModuleDefault(result, mod);
        return result;
    };
})();
Object.defineProperty(exports, "__esModule", { value: true });
exports.analyzeReactRouter = analyzeReactRouter;
const fs = __importStar(require("fs"));
const path = __importStar(require("path"));
/**
 * Analyze React Router routes
 */
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;
}
