import { splitLines } from '../../../shared/helpers/index.js';
export function pontuarHtml(src, relPath) {
    let score = 0;
    const maxScore = 100;
    const issues = [];
    const strengths = [];
    const _linhas = splitLines(src);
    const srcCompleto = src;
    const isTemplate = /\.(template\.html|\.component\.html)$/i.test(relPath);
    if (!isTemplate && /<!DOCTYPE\s+html>/i.test(srcCompleto)) {
        score += 10;
        strengths.push('DOCTYPE presente');
    }
    else if (!isTemplate) {
        issues.push('DOCTYPE ausente');
    }
    else {
        score += 10;
    }
    if (/<html[^>]*\slang=['"][^'"]+['"]/i.test(srcCompleto)) {
        score += 10;
        strengths.push('Atributo lang presente');
    }
    else {
        issues.push('Atributo lang ausente');
    }
    if (/<title>[^<]+<\/title>/i.test(srcCompleto)) {
        score += 10;
        strengths.push('Title presente');
    }
    else {
        issues.push('Title ausente ou vazio');
    }
    const imgs = (srcCompleto.match(/<img[^>]*>/gi) || []).length;
    const imgsWithAlt = (srcCompleto.match(/<img[^>]*alt=['"][^'"]+['"][^>]*>/gi) || []).length;
    const imgsWithAriaHidden = (srcCompleto.match(/<img[^>]*aria-hidden=['"]true['"][^>]*>/gi) || []).length;
    if (imgs === 0) {
        score += 20;
        strengths.push('Sem imagens para verificar');
    }
    else {
        const accessible = imgsWithAlt + imgsWithAriaHidden;
        const ratio = accessible / imgs;
        score += Math.round(ratio * 20);
        if (ratio === 1)
            strengths.push('Todas imagens acessíveis');
        else
            issues.push(`${imgs - accessible} imagem(ns) sem alt`);
    }
    const inlineHandlers = (srcCompleto.match(/\son\w+\s*=/gi) || []).length;
    if (inlineHandlers === 0) {
        score += 15;
        strengths.push('Sem handlers inline');
    }
    else {
        score += Math.max(0, 15 - inlineHandlers * 3);
        issues.push(`${inlineHandlers} handler(es) inline`);
    }
    const hasSemantic = /<(header|nav|main|section|article|aside|footer)[^>]*>/i.test(srcCompleto);
    if (hasSemantic) {
        score += 15;
        strengths.push('Elementos semânticos usados');
    }
    else if (!isTemplate) {
        issues.push('Sem elementos semânticos (header, nav, main, etc.)');
    }
    else {
        score += 15;
    }
    const h1Count = (srcCompleto.match(/<h1[^>]*>/gi) || []).length;
    if (h1Count <= 1) {
        score += 10;
        strengths.push('Hierarquia de headings adequada');
    }
    else {
        issues.push(`${h1Count} elementos <h1> - deve ter apenas um`);
    }
    const inputs = (srcCompleto.match(/<input[^>]*>/gi) || []).length;
    const inputsWithLabel = (srcCompleto.match(/<input[^>]*(aria-label|aria-labelledby|id=)[^>]*>/gi) || []).length;
    if (inputs === 0 || inputsWithLabel === inputs) {
        score += 10;
        strengths.push('Inputs com labels adequados');
    }
    else if (inputsWithLabel > 0) {
        score += 5;
        issues.push(`${inputs - inputsWithLabel} input(s) sem label`);
    }
    return {
        score,
        maxScore,
        percentage: Math.round((score / maxScore) * 100),
        issues,
        strengths
    };
}
export const pontuadorHtml = {
    nome: 'pontuador-html',
    categoria: 'markup',
    descricao: 'Pontua qualidade de HTML',
    pontuar: pontuarHtml
};
//# sourceMappingURL=scorer-html.js.map