import { splitLines } from '../../../shared/helpers/index.js';
export function pontuarCss(src, _relPath) {
    let score = 0;
    const maxScore = 100;
    const issues = [];
    const strengths = [];
    const linhas = splitLines(src);
    const srcCompleto = src;
    const importantCount = (srcCompleto.match(/!important/g) || []).length;
    if (importantCount === 0) {
        score += 25;
        strengths.push('Sem uso de !important');
    }
    else if (importantCount <= 3) {
        score += 15;
        issues.push(`${importantCount} uso(s) de !important`);
    }
    else {
        score += 5;
        issues.push(`${importantCount} usos de !important - refatore especificidade`);
    }
    const props = new Map();
    let inBlock = false;
    linhas.forEach(linha => {
        if (linha.includes('{')) {
            inBlock = true;
            props.clear();
        }
        if (linha.includes('}'))
            inBlock = false;
        if (inBlock) {
            const match = /^\s*([a-zA-Z-]+)\s*:/.exec(linha);
            if (match) {
                const prop = match[1].toLowerCase();
                props.set(prop, (props.get(prop) || 0) + 1);
            }
        }
    });
    const duplicates = [...props.values()].filter(valor => valor > 1).length;
    if (duplicates === 0) {
        score += 20;
        strengths.push('Sem propriedades duplicadas');
    }
    else {
        score += Math.max(0, 20 - duplicates * 5);
        issues.push(`${duplicates} propriedade(s) duplicada(s)`);
    }
    const idSelectors = (srcCompleto.match(/#[a-zA-Z][a-zA-Z0-9_-]*\s*\{/g) || []).length;
    if (idSelectors === 0) {
        score += 15;
        strengths.push('Sem seletores ID');
    }
    else {
        score += Math.max(0, 15 - idSelectors * 3);
        issues.push(`${idSelectors} seletor(es) ID`);
    }
    const cssHacks = (srcCompleto.match(/\\9|\*property|_property|expression\s*\(/g) || []).length;
    if (cssHacks === 0) {
        score += 15;
        strengths.push('Sem CSS hacks');
    }
    else {
        issues.push(`${cssHacks} CSS hack(s) detectado(s)`);
    }
    const emptyRules = (srcCompleto.match(/\{[^}]*\}/g) || []).filter(raiz => !raiz.includes(':')).length;
    if (emptyRules === 0) {
        score += 10;
        strengths.push('Sem regras vazias');
    }
    else {
        issues.push(`${emptyRules} regra(s) vazia(s)`);
    }
    const vendorPrefixes = (srcCompleto.match(/-(webkit|moz|ms|o)-/g) || []).length;
    if (vendorPrefixes === 0) {
        score += 15;
        strengths.push('Sem vendor prefixes desnecessários');
    }
    else {
        score += 10;
        issues.push(`${vendorPrefixes} vendor prefix(es) - considere usar Autoprefixer`);
    }
    return {
        score,
        maxScore,
        percentage: Math.round(score / maxScore * 100),
        issues,
        strengths
    };
}
export const pontuadorCss = {
    nome: 'pontuador-css',
    categoria: 'estilo',
    descricao: 'Pontua qualidade de CSS',
    pontuar: pontuarCss
};
//# sourceMappingURL=scorer-css.js.map