import { splitLines } from '../../../shared/helpers/index.js';
export function pontuarReact(src, _relPath) {
    let score = 0;
    const maxScore = 100;
    const issues = [];
    const strengths = [];
    const _linhas = splitLines(src);
    const srcCompleto = src;
    const usaHooks = /use(State|Effect|Memo|Callback|Ref|Context)/.test(srcCompleto);
    const hookPontos = usaHooks ? 15 : 0;
    score += hookPontos;
    if (usaHooks) {
        strengths.push('Uso de React Hooks detectado');
    }
    const hasMemoization = /use(Memo|Callback)/.test(srcCompleto);
    if (hasMemoization) {
        score += 15;
        strengths.push('Memoization implementada');
    }
    else if (/\.map\(|\.filter\(|\.reduce\(/.test(srcCompleto) && /<[A-Z]/.test(srcCompleto)) {
        score += 5;
        issues.push('Considere useMemo/useCallback para listas');
    }
    const imgWithoutAlt = (srcCompleto.match(/<img(?![^>]*alt=)[^>]*>/gi) || []).length;
    const imgWithAriaHidden = (srcCompleto.match(/<img[^>]*aria-hidden=["']true["'][^>]*>/gi) || []).length;
    if (imgWithoutAlt === 0 || imgWithoutAlt === imgWithAriaHidden) {
        score += 20;
        strengths.push('Imagens com alt ou aria-hidden adequados');
    }
    else {
        score += Math.max(0, 20 - imgWithoutAlt * 5);
        issues.push(`${imgWithoutAlt} imagem(ns) sem alt`);
    }
    if (!/dangerouslySetInnerHTML/.test(srcCompleto)) {
        score += 15;
        strengths.push('Sem uso de dangerouslySetInnerHTML');
    }
    else {
        issues.push('dangerouslySetInnerHTML detectado');
    }
    const inlineHandlers = (srcCompleto.match(/onClick=\{[^}]*=>|onSubmit=\{[^}]*=>/g) || []).length;
    if (inlineHandlers === 0) {
        score += 15;
        strengths.push('Handlers extraídos (sem inline)');
    }
    else if (inlineHandlers <= 2) {
        score += 10;
        issues.push(`${inlineHandlers} handler(es) inline`);
    }
    else {
        score += 5;
        issues.push(`${inlineHandlers} handlers inline - extraia para funções`);
    }
    if (!/componentWillMount|componentWillReceiveProps|componentWillUpdate/.test(srcCompleto)) {
        score += 15;
        strengths.push('Sem lifecycle methods deprecated');
    }
    else {
        issues.push('Lifecycle methods deprecated detectados');
    }
    return {
        score,
        maxScore,
        percentage: Math.round((score / maxScore) * 100),
        issues,
        strengths
    };
}
export const pontuadorReact = {
    nome: 'pontuador-react',
    categoria: 'framework',
    descricao: 'Pontua qualidade de código React',
    pontuar: pontuarReact
};
//# sourceMappingURL=scorer-react.js.map