// SPEC-597-EXEMPT: canonical mapping (npm-package↔framework, keyword catalogue)
// — must enumerate framework names by design; no detection logic to migrate.
// engine/advanced-testing/accessibility-checker.ts — SPEC-049
// Generates WCAG 2.1 Level AA criteria and axe-core test scaffolds.
/** WCAG 2.1 Level AA criteria list for create_spec. */
export function buildA11yCriteria() {
    return [
        '- [ ] Todas las páginas tienen 0 violations en axe-core (WCAG 2.1 Level AA) — verificado automáticamente en CI',
        '- [ ] Todos los formularios tienen `<label>` asociado correctamente a cada input (no placeholder como sustituto)',
        '- [ ] La aplicación es navegable con teclado (Tab/Shift+Tab/Enter/Escape) sin depender del mouse',
        '- [ ] El contraste de texto cumple ratio 4.5:1 para texto normal y 3:1 para texto grande (WCAG 1.4.3)',
        '- [ ] Todas las imágenes significativas tienen atributo `alt` descriptivo; imágenes decorativas tienen `alt=""`',
        '- [ ] Los componentes interactivos con roles no estándar tienen `role` y `aria-label` / `aria-labelledby` correctos',
        '- [ ] Los aria-live regions anuncian cambios dinámicos a lectores de pantalla (aria-live="polite" o "assertive")',
        '- [ ] El color no es el único indicador de estado — se usa texto o icono adicional',
        '- [ ] NOTA: axe-core detecta ~57% de violations WCAG automáticamente. El testing manual con screen reader real (NVDA/VoiceOver) es responsabilidad del equipo para cobertura completa.',
    ];
}
/** Generate a Playwright + axe-core accessibility test scaffold. */
function buildPlaywrightAxeScaffold() {
    return `import { test, expect } from '@playwright/test';
import { checkA11y, injectAxe } from 'axe-playwright';

const ROUTES = [
  '/',
  '/login',
  '/dashboard',
  // Add all main routes here
];

for (const route of ROUTES) {
  test(\`a11y: \${route} has no axe violations (WCAG 2.1 AA)\`, async ({ page }) => {
    await page.goto(route);
    await injectAxe(page);
    await checkA11y(page, undefined, {
      axeOptions: {
        runOnly: {
          type: 'tag',
          values: ['wcag2a', 'wcag2aa', 'wcag21a', 'wcag21aa'],
        },
      },
      detailedReport: true,
      detailedReportOptions: { html: true },
    });
  });
}

test('a11y: keyboard navigation — Tab cycles through interactive elements', async ({ page }) => {
  await page.goto('/');
  // Tab through focusable elements and verify focus is visible
  await page.keyboard.press('Tab');
  const focusedElement = await page.evaluate(() => document.activeElement?.tagName);
  expect(focusedElement).not.toBe('BODY');
});

test('a11y: keyboard navigation — Escape closes modals/dialogs', async ({ page }) => {
  await page.goto('/');
  // Open a modal/dialog if your app has one, then press Escape
  // await page.click('[data-testid="open-modal"]');
  await page.keyboard.press('Escape');
  // Verify the modal closed and focus returned to the trigger element
});
`;
}
/** Generate a jest-axe accessibility test scaffold. */
function buildJestAxeScaffold() {
    return `import { render } from '@testing-library/react';
import { axe, toHaveNoViolations } from 'jest-axe';
import { YourComponent } from './YourComponent';

expect.extend(toHaveNoViolations);

describe('YourComponent — accessibility (WCAG 2.1 AA)', () => {
  it('has no axe violations', async () => {
    const { container } = render(<YourComponent />);
    const results = await axe(container, {
      rules: {
        // Customize rules if needed
        // 'color-contrast': { enabled: false }, // only if justified
      },
    });
    expect(results).toHaveNoViolations();
  });

  it('has accessible labels for all form inputs', async () => {
    const { container } = render(<YourComponent />);
    const results = await axe(container);
    const labelViolations = results.violations.filter((v) => v.id === 'label');
    expect(labelViolations).toHaveLength(0);
  });
});
`;
}
/** Generate a pa11y CI configuration. */
function buildPa11yScaffold() {
    return `# .pa11yci — pa11y CI configuration
defaults:
  standard: WCAG2AA
  timeout: 10000
  wait: 500
  ignore:
    - notice
    - warning

urls:
  - http://localhost:3000
  - http://localhost:3000/login
  - http://localhost:3000/dashboard
  # Add all main routes here
`;
}
/** Map framework name to A11yFramework type. */
function toA11yFramework(testFramework) {
    const fw = testFramework.toLowerCase();
    if (fw.includes('playwright')) {
        return 'axe-core';
    }
    if (fw.includes('jest') || fw.includes('react-testing-library')) {
        return 'jest-axe';
    }
    if (fw.includes('pa11y')) {
        return 'pa11y';
    }
    if (fw.includes('lighthouse')) {
        return 'lighthouse-ci';
    }
    return 'axe-core';
}
/**
 * Generate an accessibility test scaffold for the given test framework.
 * Returns an A11yTestScaffold with framework name and test file content.
 */
export function generateA11yTests(testFramework) {
    const framework = toA11yFramework(testFramework);
    let testFile = buildPlaywrightAxeScaffold();
    switch (framework) {
        case 'jest-axe':
            testFile = buildJestAxeScaffold();
            break;
        case 'pa11y':
            testFile = buildPa11yScaffold();
            break;
        case 'axe-core':
        case 'lighthouse-ci':
            // Playwright-axe is the default for both
            testFile = buildPlaywrightAxeScaffold();
            break;
    }
    return { framework, testFile };
}
/** Detect if the project is a web project based on stack signals. */
export function isWebProject(stack) {
    const webSignals = [
        'react',
        'vue',
        'angular',
        'svelte',
        'next',
        'nuxt',
        'remix',
        'astro',
        'html',
        'css',
        'browser',
        'frontend',
        'web',
        'playwright',
        'cypress',
    ];
    const stackLower = stack.map((s) => s.toLowerCase()).join(' ');
    return webSignals.some((sig) => stackLower.includes(sig));
}
//# sourceMappingURL=accessibility-checker.js.map