import { getFormatterForPath, registerFormatter } from './core/formatter-registry.js';
import { formatarCodeMinimo, formatarJavaScriptMinimo, formatarPhpMinimo, formatarPythonMinimo, formatarTypeScriptMinimo } from './formatters/code.js';
import { corrigirPontuacaoECodigo, normalizarFimDeLinha, normalizarNewlinesFinais, removerEspacosFinaisPorLinha } from './formatters/commons.js';
import { formatarCssMinimo, formatarLessMinimo, formatarScssMinimo } from './formatters/css.js';
import { formatarDockerfileMinimo } from './formatters/dockerfile.js';
import { formatarEditorconfigMinimo, formatarGitignoreMinimo, formatarNpmrcMinimo, formatarNvmrcMinimo } from './formatters/dotfiles.js';
import { formatarGoMinimo } from './formatters/go.js';
import { formatarHtmlMinimo } from './formatters/html.js';
import { formatarJsonMinimo } from './formatters/json.js';
import { formatarMarkdownMinimo } from './formatters/markdown.js';
import { formatarGradleMinimo, formatarPropertiesMinimo } from './formatters/properties.js';
import { formatarShellMinimo } from './formatters/shell.js';
import { formatarSqlMinimo } from './formatters/sql.js';
import { formatarSvgMinimo } from './formatters/svg.js';
import { formatarIniMinimo, formatarTomlMinimo } from './formatters/toml.js';
import { formatarXmlMinimo } from './formatters/xml.js';
import { formatarYamlMinimo } from './formatters/yaml.js';
export { formatarComPrettierProjeto } from './engines/prettier.js';
function formatarJson5Minimo(code) {
    return formatarCodeMinimo(code, {
        normalizarSeparadoresDeSecao: false,
        parser: 'json5',
    });
}
function formatarJsoncMinimo(code) {
    return formatarCodeMinimo(code, {
        normalizarSeparadoresDeSecao: false,
        parser: 'json',
    });
}
export function formatarPrettierMinimo(params) {
    const relPath = params.relPath ?? '';
    const code = params.code;
    const formatter = getFormatterForPath(relPath);
    if (formatter) {
        return formatter(code, relPath);
    }
    const normalized = normalizarFimDeLinha(code);
    const semEspacos = removerEspacosFinaisPorLinha(normalized);
    const { text: comPontuacao, stats } = corrigirPontuacaoECodigo(semEspacos);
    const formatted = normalizarNewlinesFinais(comPontuacao);
    const baseline = normalizarNewlinesFinais(normalized);
    const hasChanges = formatted !== baseline;
    return {
        ok: true,
        parser: 'code',
        formatted,
        changed: hasChanges,
        reason: hasChanges ? `estilo-tutanus-fallback(punct:${stats.pontuacaoRepetida},space:${stats.espacamentoIncorreto},ops:${stats.operadoresRelacionais})` : 'normalizacao-basica'
    };
}
registerFormatter('.json', (code) => {
    const normalized = normalizarFimDeLinha(code);
    const hasComments = /(^|\n)\s*\/\//.test(normalized) || /(^|\n)\s*\/\*/.test(normalized);
    return hasComments ? formatarJsoncMinimo(code) : formatarJsonMinimo(code);
});
registerFormatter('.jsonc', formatarJsoncMinimo);
registerFormatter('.lock', formatarJsonMinimo);
registerFormatter('.md', (code) => formatarMarkdownMinimo(code));
registerFormatter('.markdown', (code) => formatarMarkdownMinimo(code));
registerFormatter('.yml', formatarYamlMinimo);
registerFormatter('.yaml', formatarYamlMinimo);
registerFormatter('.xml', formatarXmlMinimo);
registerFormatter('.svg', formatarSvgMinimo);
registerFormatter('.html', formatarHtmlMinimo);
registerFormatter('.htm', formatarHtmlMinimo);
registerFormatter('.css', formatarCssMinimo);
registerFormatter('.scss', formatarScssMinimo);
registerFormatter('.less', formatarLessMinimo);
registerFormatter('.sql', formatarSqlMinimo);
registerFormatter('.toml', formatarTomlMinimo);
registerFormatter('.ini', formatarIniMinimo);
registerFormatter('.sh', formatarShellMinimo);
registerFormatter('.bash', formatarShellMinimo);
registerFormatter('.gradle', formatarGradleMinimo);
registerFormatter('.properties', formatarPropertiesMinimo);
registerFormatter('.py', formatarPythonMinimo);
registerFormatter('.php', formatarPhpMinimo);
registerFormatter('.dockerfile', formatarDockerfileMinimo);
registerFormatter('Dockerfile', formatarDockerfileMinimo);
registerFormatter('.txt', (code) => formatarCodeMinimo(code, { normalizarSeparadoresDeSecao: false, parser: 'code' }));
registerFormatter('.log', (code) => formatarCodeMinimo(code, { normalizarSeparadoresDeSecao: false, parser: 'code' }));
registerFormatter('.env', (code) => formatarCodeMinimo(code, { normalizarSeparadoresDeSecao: false, parser: 'code' }));
registerFormatter('.go', formatarGoMinimo);
registerFormatter('.gitignore', formatarGitignoreMinimo);
registerFormatter('.editorconfig', formatarEditorconfigMinimo);
registerFormatter('.npmrc', formatarNpmrcMinimo);
registerFormatter('.nvmrc', formatarNvmrcMinimo);
registerFormatter('.json5', formatarJson5Minimo);
registerFormatter('.ts', (code, relPath) => formatarTypeScriptMinimo(code, relPath ?? ''));
registerFormatter('.tsx', (code, relPath) => formatarTypeScriptMinimo(code, relPath ?? ''));
registerFormatter('.cts', (code, relPath) => formatarTypeScriptMinimo(code, relPath ?? ''));
registerFormatter('.mts', (code, relPath) => formatarTypeScriptMinimo(code, relPath ?? ''));
registerFormatter('.js', (code, relPath) => formatarJavaScriptMinimo(code, relPath ?? ''));
registerFormatter('.jsx', (code, relPath) => formatarJavaScriptMinimo(code, relPath ?? ''));
registerFormatter('.mjs', (code, relPath) => formatarJavaScriptMinimo(code, relPath ?? ''));
registerFormatter('.cjs', (code, relPath) => formatarJavaScriptMinimo(code, relPath ?? ''));
export function getRegisteredFormatter(relPath) {
    return getFormatterForPath(relPath);
}
//# sourceMappingURL=formatter.js.map