import { expect } from "e2e";
import { IOS, test } from "./t3-mobile.ts";
import { environmentId, runPromise } from "./t3.ts";
import { MOBILE } from "../e2e.config.ts";

test("Quote controls use Chinese and German", IOS, async ({ t3, app, screen, device }) => {
  const project = await t3.project("translation-demo");
  const thread = await t3.thread({ project, title: "go", messages: ["first"] });
  await t3.open();
  const environment = await runPromise(environmentId(`http://127.0.0.1:${MOBILE.serverPort}`));
  const openThread = async () => {
    await screen.getByTestId("workspace-tab-threads").tap();
    await device.openLink(`t3code-dev://threads/${environment}/${thread.threadId}`, { app: "com.t3tools.t3code.dev" });
    await screen.getByText("first fixture turn complete", { exact: false }).waitFor();
  };
  const expandSheet = async () => {
    const grabber = await screen.getByRole("button", "Sheet Grabber").boundingBox();
    await screen.swipe({ from: { x: grabber!.x + grabber!.width / 2, y: grabber!.y + grabber!.height / 2 }, to: { x: 201, y: 150 }, duration: 500 });
  };
  await screen.getByTestId("workspace-tab-settings").tap();
  await screen.getByText("General", { exact: true }).tap();
  await screen.getByRole("button", /^Language,/).tap();
  await screen.getByText("中文（简体）", { exact: true }).tap();
  await app.restart();
  await openThread();
  await screen.getByText("first fixture turn complete", { exact: false }).longPress();
  await app.screenshot("chinese-selection-menu");
  await screen.getByText(/^(Cite|引用)$/).tap();
  await screen.getByRole("button", "turn", { exact: true }).tap();
  await expandSheet();
  await app.screenshot("chinese-quote-sheet");
  await expect.soft(screen.getByText("复制引用", { exact: true })).toBeVisible();
  await expect.soft(screen.getByRole("textbox", "评论引用内容 添加评论（选填）…")).toBeVisible();
  await expect.soft(screen.getByText("转到消息", { exact: true })).toBeVisible();
  await screen.getByRole("button", /Close|关闭/).tap();
  await device.openLink("t3code-dev://settings/language", { app: "com.t3tools.t3code.dev" });
  await screen.getByText("Deutsch", { exact: true }).tap();
  await app.restart();
  await openThread();
  await screen.getByRole("button", "turn", { exact: true }).tap();
  await expandSheet();
  await app.screenshot("german-quote-sheet");
  await expect.soft(screen.getByText("Zitat kopieren", { exact: true })).toBeVisible();
  await expect.soft(screen.getByText("Zur Nachricht", { exact: true })).toBeVisible();
});
