import { expect } from "e2e";
import { test, WEB } from "./t3.ts";

test("Plane click retains focus for immediate Shift+ArrowRight fine tuning", WEB, async ({ t3, app, screen, browser }) => {
  await t3.project("color-picker-demo");
  await t3.open("/settings/appearance");
  await screen.getByRole("button", "Create theme", { exact: true }).tap();
  await screen.getByRole("button", "Choose Accent color", { exact: true }).tap();
  const hex = screen.getByRole("textbox", "Accent picker hex value", { exact: true });
  await hex.fill("#405180");
  await browser.keyboard.press("Tab");
  await hex.tap();
  await screen.getByRole("group", "Accent saturation and brightness", { exact: true }).tap();
  const read = () => browser.evaluate(() => {
    const hex = document.querySelector<HTMLInputElement>('input[aria-label="Accent picker hex value"]')!;
    const saturation = document.querySelector<HTMLInputElement>('input[aria-label="Accent saturation"]')!;
    return { hex: hex.value, saturation: saturation.value, focused: document.activeElement === saturation };
  });
  const clicked = await read();
  await app.screenshot("after-plane-click");
  await browser.keyboard.press("Shift+ArrowRight");
  const adjusted = await read();
  await app.screenshot("after-shift-arrow-right");
  expect(adjusted.hex).not.toBe(clicked.hex);
  expect(Number(adjusted.saturation)).toBeGreaterThan(Number(clicked.saturation));
  expect(adjusted.focused).toBe(true);
});
