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

test("Appearance Contrast strengthens highlights and focus outlines in both modes", WEB, async ({ t3, app, screen, browser }) => {
  const project = await t3.project("Contrast demo");
  const thread = await t3.thread({ project, title: "Review interface contrast", messages: ["Hello" ] });
  const samples: Record<string, string> = {};
  for (const mode of ["light", "dark"] as const) {
    await t3.open("/settings/appearance");
    await screen.getByRole("button", `Use ${mode} mode`, { exact: true }).tap();
    for (const contrast of [100, 200, 100]) {
      await t3.open("/settings/appearance");
      const slider = screen.getByRole("slider", "Contrast", { exact: true });
      await slider.press("Home");
      if (contrast === 100) {
        for (let i = 0; i < 10; i++) await slider.press("ArrowRight");
      } else await slider.press("End");
      await screen.getByText(`${contrast}%`, { exact: true }).waitFor();
      await slider.press("Tab");
      await browser.keyboard.press("Shift+Tab");
      await app.screenshot(`${mode}-${contrast}-settings-focus`);
      await t3.open(thread);
      await screen.getByRole("textbox", "Message Review interface contrast", { exact: true }).waitFor();
      await screen.getByText("Syncing messages...", { exact: true }).waitFor({ state: "hidden" });
      await app.screenshot(`${mode}-${contrast}-sidebar-composer`);
      await screen.getByRole("combobox", "Branch: main", { exact: true }).tap();
      await browser.keyboard.press("ArrowDown");
      await app.screenshot(`${mode}-${contrast}-dropdown-highlight`);
      await browser.keyboard.press("Escape");
      await screen.getByRole("textbox", "Message Review interface contrast", { exact: true }).press("Control+k");
      const palette = screen.getByRole("dialog", "Command palette");
      await palette.getByRole("combobox").fill("> ");
      await browser.keyboard.press("ArrowDown");
      await browser.keyboard.press("ArrowDown");
      await browser.locator('[data-slot="command-item"][data-active="true"]').waitFor();
      samples[`${mode}-${contrast}`] = await browser.evaluate(() => {
        const item = document.querySelector('[data-slot="command-item"][data-active="true"]');
        if (!item) throw new Error("No highlighted command");
        return getComputedStyle(item).backgroundColor;
      });
      await app.screenshot(`${mode}-${contrast}-command-highlight`);
      await browser.keyboard.press("Escape");
    }
  }
  expect(samples["light-200"]).not.toBe(samples["light-100"]);
  expect(samples["dark-200"]).not.toBe(samples["dark-100"]);
});
