import path from 'node:path';
import { config } from './config.js';
function toPosix(caminho) {
    return caminho.replace(/\\/g, '/');
}
function trimSlashes(caminho) {
    return caminho.replace(/^\/*/, '').replace(/\/*$/, '');
}
export function getTypesDirectoryRelPosix() {
    const raw = config;
    const string = typeof raw.nameConventions?.typesDirectory === 'string' && raw.nameConventions.typesDirectory.trim() || typeof raw.conventions?.typesDirectory === 'string' && raw.conventions.typesDirectory.trim() || 'src/tipos';
    return trimSlashes(toPosix(string));
}
export function getTypesDirectoryDisplay() {
    const base = getTypesDirectoryRelPosix();
    return base.endsWith('/') ? base : `${base}/`;
}
export function isInsideTypesDirectory(relPath) {
    const norm = trimSlashes(toPosix(relPath));
    const base = getTypesDirectoryRelPosix();
    if (norm === base || norm.startsWith(`${base}/`)) {
        return true;
    }
    return isInsideDirectory(relPath, 'typesDirectory');
}
export function isInsideDirectory(relPath, key) {
    const norm = trimSlashes(toPosix(relPath));
    const expected = getExpectedDirectoryName(key);
    if (expected && (norm === expected || norm.split('/').some(seg => seg === expected))) {
        return true;
    }
    const pattern = getDirVariantPattern(key);
    const segments = norm.split('/');
    return segments.some(seg => pattern.test(seg));
}
export function isInsideTestsDirectory(relPath) {
    return isInsideDirectory(relPath, 'testsDirectory');
}
export function isInsideDocsDirectory(relPath) {
    return isInsideDirectory(relPath, 'docsDirectory');
}
export function isInsideConfigDirectory(relPath) {
    return isInsideDirectory(relPath, 'configDirectory');
}
export function isInsideScriptsDirectory(relPath) {
    return isInsideDirectory(relPath, 'scriptsDirectory');
}
export function isInsideUtilsDirectory(relPath) {
    return isInsideDirectory(relPath, 'utilsDirectory');
}
export function buildTypesRelPathPosix(relInsideTypesDir) {
    const base = getTypesDirectoryRelPosix();
    const inside = trimSlashes(toPosix(relInsideTypesDir));
    return inside ? `${base}/${inside}` : base;
}
export function buildTypesFsPath(relInsideTypesDir) {
    const relPosix = buildTypesRelPathPosix(relInsideTypesDir);
    return path.join(...relPosix.split('/'));
}
const DIR_VARIANT_PATTERNS = {
    typesDirectory: /types|tipos/i,
    testsDirectory: /tests?|testes|spec/i,
    docsDirectory: /docs?|doc|documentacao/i,
    srcDirectory: /src|source|codigo/i,
    configDirectory: /config|cfg|conf|settings/i,
    scriptsDirectory: /scripts?|scripts|bin/i,
    distDirectory: /dist|build|out|release/i,
    assetsDirectory: /assets?|static|public|resources/i,
    utilsDirectory: /utils?|helpers?|lib|libs|tools/i,
    servicesDirectory: /services?|svc|apis/i,
    componentsDirectory: /components?|comps?|widgets|ui/i,
    modelsDirectory: /models?|entities|schemas?/i,
    middlewareDirectory: /middlewares?|middleware|interceptors?/i,
    routesDirectory: /routes?|paths?|endpoints?/i,
    controllersDirectory: /controllers?|handlers?|actions/i,
    viewsDirectory: /views?|pages?|screens?|templates?/i,
    stylesDirectory: /styles?|css|scss|sass|themes?/i,
    imagesDirectory: /images?|imgs?|assets\/img|icons?|media/i,
    localesDirectory: /locales?|i18n|translations?|lang|l10n/i
};
export function getNameConventions() {
    return config.nameConventions ?? {};
}
export function getExpectedDirectoryName(key) {
    const conventions = getNameConventions();
    return conventions[key] ?? '';
}
export function getAllExpectedDirNames() {
    const conventions = getNameConventions();
    return Object.entries(conventions).filter(([, valor]) => typeof valor === 'string' && valor.trim().length > 0).map(([chave, valor]) => ({
        key: chave,
        expected: valor
    }));
}
export function getDirVariantPattern(key) {
    return DIR_VARIANT_PATTERNS[key] ?? /^$/;
}
//# sourceMappingURL=conventions.js.map