import { splitLines } from '../../../shared/helpers/index.js';
export function pontuarTailwind(src, _relPath) {
    let score = 0;
    const maxScore = 100;
    const issues = [];
    const strengths = [];
    const _linhas = splitLines(src);
    const srcCompleto = src;
    const classMatches = srcCompleto.match(/\bclass(Name)?\s*=\s*["']([^"']*)["']/g) || [];
    const allClasses = classMatches.map(metrica => {
        const match = metrica.match(/["']([^"']*)["']/);
        return match ? match[1].split(/\s+/).filter(Boolean) : [];
    }).flat();
    const duplicates = allClasses.filter((elem, indice) => allClasses.indexOf(elem) !== indice);
    if (duplicates.length === 0) {
        score += 25;
        strengths.push('Sem classes duplicadas');
    }
    else {
        score += Math.max(0, 25 - duplicates.length * 3);
        issues.push(`${duplicates.length} classe(s) duplicada(s)`);
    }
    const propGroups = new Map();
    allClasses.forEach(token => {
        const base = token.split(':').pop() || token;
        if (/^(p|m)[trblxy]?(-|$)/.test(base)) {
            const key = base.match(/^(p|m)[trblxy]?/)?.[0] || 'spacing';
            if (!propGroups.has(key))
                propGroups.set(key, []);
            const existing = propGroups.get(key);
            if (existing)
                existing.push(token);
        }
    });
    const conflicts = [...propGroups.values()].filter(valor => valor.length > 1).length;
    if (conflicts === 0) {
        score += 20;
        strengths.push('Sem classes conflitantes');
    }
    else {
        score += Math.max(0, 20 - conflicts * 5);
        issues.push(`${conflicts} grupo(s) de classes conflitantes`);
    }
    const arbitraryValues = (srcCompleto.match(/\[[^\]]+\]/g) || []).filter(valor => !/(var\(|rgb\(|calc\()/i.test(valor));
    if (arbitraryValues.length === 0) {
        score += 20;
        strengths.push('Sem valores arbitrários');
    }
    else if (arbitraryValues.length <= 3) {
        score += 15;
        issues.push(`${arbitraryValues.length} valor(es) arbitrário(s)`);
    }
    else {
        score += 5;
        issues.push(`${arbitraryValues.length} valores arbitrários - considere tailwind.config.js`);
    }
    const importantCount = (srcCompleto.match(/class(Name)?=.*!/g) || []).length;
    if (importantCount === 0) {
        score += 15;
        strengths.push('Sem !important');
    }
    else {
        issues.push(`${importantCount} uso(s) de !important`);
    }
    const hasCnOrClsx = /\b(cn|clsx|twMerge|classnames)\s*\(/.test(srcCompleto);
    if (hasCnOrClsx) {
        score += 20;
        strengths.push('Uso de cn/clsx para organização');
    }
    else if (classMatches.length > 5) {
        score += 10;
        issues.push('Muitos class attributes - considere cn/clsx');
    }
    else {
        score += 20;
    }
    return {
        score,
        maxScore,
        percentage: Math.round(score / maxScore * 100),
        issues,
        strengths
    };
}
export const pontuadorTailwind = {
    nome: 'pontuador-tailwind',
    categoria: 'estilo',
    descricao: 'Pontua qualidade de Tailwind CSS',
    pontuar: pontuarTailwind
};
//# sourceMappingURL=scorer-tailwind.js.map