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

test("Importing Aurora Light and Dark together preserves shared custom CSS", WEB, async ({ t3, app, screen, browser }) => {
  await t3.project("demo");
  await t3.open("/settings/appearance");
  await screen.getByRole("button", "Add theme", { exact: true }).tap();
  await browser.evaluate(() => {
    const css = "[data-settings-page-scroll] { outline: 8px solid #ff2d95; outline-offset: -8px; }";
    const transfer = new DataTransfer();
    for (const appearance of ["light", "dark"]) {
      const name = appearance === "light" ? "Aurora Light" : "Aurora Dark";
      transfer.items.add(new File([JSON.stringify({ version: 1, name, appearance, colors: { canvas: appearance === "light" ? "#f4f1ff" : "#191525" }, css })], `${name}.json`, { type: "application/json" }));
    }
    const input = document.querySelector<HTMLInputElement>('input[type="file"]')!;
    input.files = transfer.files;
    input.dispatchEvent(new Event("change", { bubbles: true }));
  });
  await screen.getByRole("button", "Use Aurora theme", { exact: true }).tap();
  await app.screenshot("aurora-paired-import-selected");
  await expect.poll(() => browser.evaluate(() => {
    const element = document.querySelector('[data-settings-page-scroll]')!;
    const style = getComputedStyle(element);
    return `${style.outlineWidth} ${style.outlineStyle} ${style.outlineColor}`;
  })).toBe("8px solid rgb(255, 45, 149)");
});
