/// <reference lib="dom" />
import { expect } from "e2e";
import { test, WEB } from "./t3.ts";

test("German diagnostics stat details have localized accessible names", WEB, async ({ t3, app, browser, screen }) => {
  await t3.project("diagnostics-demo");
  await t3.open("/settings/general");
  await screen.getByLabel("Language", { exact: true }).tap({ timeout: 120_000 });
  await screen.getByText("Deutsch", { exact: true }).tap();
  await screen.getByLabel("Sprache", { exact: true }).waitFor();
  await t3.open("/settings/diagnostics");
  await screen.getByText("Laufende Prozesse", { exact: true }).waitFor({ timeout: 30_000 });
  const names = await browser.evaluate(() => {
    const buttons = Array.from(document.querySelectorAll<HTMLButtonElement>('button[aria-label]')).filter(button => /details|Details zu/.test(button.getAttribute("aria-label") ?? ""));
    const names = buttons.map(button => button.getAttribute("aria-label"));
    const memory = buttons.find(button => button.getAttribute("aria-label")?.includes("Arbeitsspeicher"));
    memory?.focus();
    const panel = document.createElement("aside");
    panel.style.cssText = "position:fixed;bottom:20px;right:20px;z-index:99999;background:#171717;color:white;border:2px solid #aaa;padding:18px;font:16px/1.6 monospace;max-width:520px;white-space:pre-wrap;pointer-events:none";
    panel.textContent = "Accessibility inspection (live DOM)\nhtml lang: " + document.documentElement.lang + "\nStat button aria-label values:\n" + names.join("\n");
    document.body.append(panel);
    return names;
  });
  await app.screenshot("german-diagnostics-accessible-names");
  expect(names).toContain("Details zu Arbeitsspeicher");
  expect(names.some(name => name?.endsWith(" details"))).toBe(false);
});
