"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.RegexExtractor = void 0;
class RegexExtractor {
    patterns = [
        {
            name: 'var_to_const_let',
            category: 'variable_declaration',
            regex: /\bvar\s+(\w+)/g,
            toPattern: 'const/let',
            description: 'Prefers const/let over var',
        },
        {
            name: 'function_to_arrow',
            category: 'function_style',
            regex: /\bfunction\b/g,
            toPattern: 'arrow function',
            description: 'Prefers arrow functions over function keyword',
        },
        {
            name: 'double_to_single_quotes',
            category: 'quote_style',
            regex: /"([^"]*)"/g,
            toPattern: 'single quotes',
            description: "Prefers single quotes over double quotes",
        },
        {
            name: 'single_to_double_quotes',
            category: 'quote_style',
            regex: /'([^']*)'/g,
            toPattern: 'double quotes',
            description: 'Prefers double quotes over single quotes',
        },
        {
            name: 'loose_to_strict_equality',
            category: 'equality',
            regex: /(?<![=!])==(?!=)/g,
            toPattern: '===',
            description: 'Prefers strict equality (===) over loose (==)',
        },
        {
            name: 'default_to_named_export',
            category: 'export_style',
            regex: /export\s+default\s+/g,
            toPattern: 'named export',
            description: 'Prefers named exports over default exports',
        },
        {
            name: 'require_to_import',
            category: 'module_system',
            regex: /\brequire\s*\(/g,
            toPattern: 'import',
            description: 'Prefers ES module import over require',
        },
        {
            name: 'then_to_await',
            category: 'promise_style',
            regex: /\.then\s*\(/g,
            toPattern: 'await',
            description: 'Prefers async/await over .then() chains',
        },
        {
            name: 'double_to_single_quotes_jsx',
            category: 'jsx_quote_style',
            regex: /="([^"]*)"/g,
            toPattern: 'single quotes in JSX',
            description: 'Prefers single quotes in JSX attributes',
        },
    ];
    extract(originalCode, editedCode) {
        const results = [];
        for (const pattern of this.patterns) {
            const originalMatches = this.countMatches(originalCode, pattern.regex);
            const editedMatches = this.countMatches(editedCode, pattern.regex);
            if (originalMatches > 0 && editedMatches === 0) {
                results.push({
                    category: pattern.category,
                    description: pattern.description,
                    from: pattern.name,
                    to: pattern.toPattern,
                    confidenceDelta: this.calculateDelta(originalMatches),
                    conditions: [],
                });
            }
            if (originalMatches === 0 && editedMatches > 0) {
                results.push({
                    category: pattern.category,
                    description: pattern.description,
                    from: 'none',
                    to: pattern.toPattern,
                    confidenceDelta: this.calculateDelta(editedMatches),
                    conditions: [],
                });
            }
        }
        return results;
    }
    extractFromDiff(originalCode, editedCode) {
        const results = [];
        for (const pattern of this.patterns) {
            const originalMatches = this.countMatches(originalCode, pattern.regex);
            const editedMatches = this.countMatches(editedCode, pattern.regex);
            if (originalMatches !== editedMatches) {
                const delta = originalMatches - editedMatches;
                if (delta > 0) {
                    results.push({
                        category: pattern.category,
                        description: `Removed ${pattern.description.toLowerCase()}`,
                        from: pattern.name,
                        to: pattern.toPattern,
                        confidenceDelta: this.calculateDelta(delta),
                        conditions: [],
                    });
                }
                else {
                    results.push({
                        category: pattern.category,
                        description: pattern.description,
                        from: 'none',
                        to: pattern.toPattern,
                        confidenceDelta: this.calculateDelta(Math.abs(delta)),
                        conditions: [],
                    });
                }
            }
        }
        return results;
    }
    getPatternCount() {
        return this.patterns.length;
    }
    countMatches(code, regex) {
        const matches = code.match(new RegExp(regex.source, regex.flags.includes('g') ? regex.flags : regex.flags + 'g'));
        return matches ? matches.length : 0;
    }
    calculateDelta(matchCount) {
        return Math.min(0.15, matchCount * 0.05);
    }
}
exports.RegexExtractor = RegexExtractor;
//# sourceMappingURL=regex-extractor.js.map