import fs from 'node:fs';
import { config, mesclarConfigExcludes } from '../../core/config/index.js';
export function processPatternListAchatado(raw) {
    if (!raw || !raw.length)
        return [];
    return Array.from(new Set(raw.flatMap(raiz => raiz.split(/[\s,]+/)).map(string => string.trim()).filter(Boolean)));
}
export function processPatternGroups(raw) {
    if (!raw || !raw.length)
        return [];
    return raw.map(grupo => grupo.split(/[\s,]+/).map(string => string.trim()).filter(Boolean)).filter(grupo => grupo.length > 0);
}
export function expandIncludes(list) {
    const META = /[\\*\?\{\}\[\]]/;
    const out = new Set();
    for (const caminho of list) {
        out.add(caminho);
        if (!META.test(caminho)) {
            out.add(`${caminho.replace(/[\\\/]+$/, '')}/**`);
            if (!caminho.includes('/') && !caminho.includes('\\'))
                out.add(`**/${caminho}/**`);
        }
    }
    return Array.from(out);
}
export function getDefaultExcludes() {
    const configIncluirExcluir = config.INCLUDE_EXCLUDE_RULES;
    if (configIncluirExcluir) {
        if (Array.isArray(configIncluirExcluir.globalExcludeGlob) && configIncluirExcluir.globalExcludeGlob.length > 0) {
            return Array.from(new Set(configIncluirExcluir.globalExcludeGlob));
        }
    }
    const tipoProjeto = detectarTipoProjeto();
    return mesclarConfigExcludes(null, tipoProjeto);
}
function detectarTipoProjeto() {
    try {
        const cwd = process.cwd();
        const files = fs.readdirSync(cwd);
        const hasFile = (name) => files.includes(name);
        const hasExt = (ext) => files.some((arquivo) => arquivo.endsWith(ext));
        if (hasFile('package.json')) {
            if (hasFile('tsconfig.json'))
                return 'typescript';
            return 'nodejs';
        }
        if (hasFile('requirements.txt') || hasFile('pyproject.toml')) {
            return 'python';
        }
        if (hasExt('.csproj') || hasExt('.sln')) {
            return 'dotnet';
        }
        return 'generico';
    }
    catch {
        return 'generico';
    }
}
export function configurarFiltros(includeGroupsRaw, includeListFlat, excludeList, incluiNodeModules) {
    if (includeListFlat.length) {
        config.CLI_INCLUDE_GROUPS = includeGroupsRaw;
        config.CLI_INCLUDE_PATTERNS = includeListFlat;
    }
    else {
        config.CLI_INCLUDE_GROUPS = [];
        config.CLI_INCLUDE_PATTERNS = [];
    }
    let finalExcluirPadroes;
    if (excludeList.length > 0) {
        finalExcluirPadroes = excludeList;
    }
    else {
        finalExcluirPadroes = getDefaultExcludes();
    }
    if (incluiNodeModules) {
        finalExcluirPadroes = finalExcluirPadroes.filter(caminho => !/node_modules/.test(caminho));
    }
    config.CLI_EXCLUDE_PATTERNS = finalExcluirPadroes;
    sincronizarArraysExclusao(finalExcluirPadroes);
}
function sincronizarArraysExclusao(_exclFiltered) {
}
//# sourceMappingURL=filters.js.map