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

test("Git availability accessible name follows German interface language", WEB, async ({ t3, app, browser, screen }) => {
  const project = await t3.project("translation-demo");
  await t3.thread({ project, title: "Translation check", messages: ["Start"] });
  await t3.open("/settings/general");
  await screen.getByLabel("Language", { exact: true }).tap();
  await screen.getByText("Deutsch", { exact: true }).tap();
  await screen.getByLabel("Sprache", { exact: true }).waitFor();
  await t3.open("/settings/source-control");
  await screen.getByRole("switch", /Git availability|Verfügbarkeit von Git/).waitFor();
  const observed = await browser.evaluate(() => {
    const control = [...document.querySelectorAll<HTMLElement>('[role="switch"]')].find(el => /Git availability|Verfügbarkeit von Git/.test(el.getAttribute("aria-label") ?? ""));
    const result = { language: document.documentElement.lang, name: control?.getAttribute("aria-label"), checked: control?.getAttribute("aria-checked"), disabled: control?.getAttribute("aria-disabled") === "true" || control?.hasAttribute("disabled") || control?.hasAttribute("data-disabled") };
    const readout = document.createElement("aside");
    readout.textContent = `Live accessibility readout\nInterface language: ${result.language}\nGit switch aria-label: ${result.name}\nChecked: ${result.checked} · Disabled: ${result.disabled}`;
    readout.style.cssText = "position:fixed;bottom:20px;right:20px;z-index:99999;background:#fff;color:#111;border:2px solid #555;border-radius:8px;padding:16px;font:15px/1.6 monospace;white-space:pre-wrap;box-shadow:0 4px 16px #0003;pointer-events:none";
    document.body.append(readout);
    return result;
  });
  await app.screenshot("german-git-switch-accessible-name");
  expect(observed.name, "Git switch accessible name in German").toEqual("Verfügbarkeit von Git");
});
