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

test("A dual-palette theme import toast uses the selected German language", WEB, async ({ t3, app, screen, browser }) => {
  await t3.project("demo");
  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/appearance");
  await screen.getByRole("button", "Design hinzufügen", { exact: true }).tap();
  await browser.evaluate(() => {
    const input = document.querySelector<HTMLInputElement>('input[type="file"]');
    if (!input) throw new Error("Theme file input missing");
    const files = new DataTransfer();
    files.items.add(new File([JSON.stringify({version:1,name:"Dusk",appearance:"dark",colors:{accent:"#8b5cf6"},variants:{light:{accent:"#7c3aed"}}})], "Dusk.json", {type:"application/json"}));
    input.files = files.files;
    input.dispatchEvent(new Event("change", {bubbles:true}));
    return null;
  });
  await screen.getByRole("textbox", "Design-JSON", {exact:true}).waitFor();
  await screen.getByRole("dialog").getByRole("button", "Design hinzufügen", {exact:true}).tap();
  await screen.getByText("Es ist jetzt aktiv.", {exact:true}).waitFor();
  await app.screenshot("dual-palette-import-toast-german");
  await expect(screen.getByText("Dusk hinzugefügt", {exact:true})).toBeVisible();
});
