import { expect } from "e2e";
import { test, IOS } from "./t3-mobile.ts";
const config = JSON.stringify({ provider: { uni: { npm: "@ai-sdk/openai-compatible", name: "uni", options: { baseURL: "http://127.0.0.1:9/v1", apiKey: "synthetic" }, models: { "medium-gpt": { name: "medium-gpt", limit: { context: 32000, output: 4000 } } } } } });
test("Project OpenCode catalog appears in mobile thread settings", { ...IOS, video: "off" }, async ({ t3, app, screen, device }) => {
  const project = await t3.project("Project A", { "opencode.jsonc": config });
  await t3.project("Project B");
  await t3.thread({ project, title: "Existing project thread", messages: ["Hello"], model: "showcase" });
  await t3.open();
  await app.screenshot("mobile-home");
  await app.startRecording({ name: "mobile-picker-interactions" });
  await screen.getByText("Existing project thread", { exact: false }).first().tap();
  await screen.getByRole("button", "Model and reasoning settings", { exact: false }).tap();
  await app.screenshot("mobile-settings");
  await screen.getByRole("button", "filter", { exact: true }).tap();
  await screen.getByText("Provider", { exact: true }).tap();
  await screen.getByText("OpenCode", { exact: true }).tap();
  await screen.getByPlaceholder("Find a model").fill("medium-gpt");
  const model = screen.getByRole("radio", "medium-gpt", { exact: false });
  await model.waitFor({ state: "visible", timeout: 15000 }).catch(() => {});
  await app.screenshot("mobile-existing-thread-catalog");
  const foundInitial = await model.isVisible();
  await screen.getByPlaceholder("Find a model").fill("");
  await screen.swipe({ from: { x: 190, y: 230 }, to: { x: 190, y: 490 }, duration: 700 });
  await screen.getByPlaceholder("Find a model").fill("medium-gpt");
  const refreshed = screen.getByRole("radio", "medium-gpt", { exact: false });
  await refreshed.waitFor({ state: "visible", timeout: 15000 }).catch(() => {});
  await app.screenshot("mobile-refreshed-project-catalog");
  const foundRefreshed = await refreshed.isVisible();
  await screen.getByRole("button", "Cancel thread settings").tap();
  await device.openLink("t3code-dev://new/project", { app: "com.t3tools.t3code.dev" });
  await device.alert("accept").catch(() => {});
  await screen.getByRole("button", "Project A", { exact: true }).tap();
  await app.screenshot("mobile-project-a-draft");
  const openModels = async () => {
    await screen.getByRole("button", "Model and reasoning settings", { exact: false }).tap();
    await screen.getByRole("button", "filter", { exact: true }).tap();
    await screen.getByText("Provider", { exact: true }).tap();
    await screen.getByText("OpenCode", { exact: true }).tap();
    await screen.getByPlaceholder("Find a model").fill("medium-gpt");
  };
  await openModels();
  await model.waitFor({ state: "visible", timeout: 15000 }).catch(() => {});
  const foundInDraft = await model.isVisible();
  await app.screenshot("mobile-project-a-draft-catalog");
  await screen.getByRole("button", "Cancel thread settings").tap();
  await screen.getByRole("button", "Project A", { exact: true }).tap();
  await screen.getByRole("button", "Project B", { exact: true }).tap();
  await app.screenshot("mobile-project-b-draft");
  await openModels();
  await app.screenshot("mobile-project-b-draft-catalog");
  await app.stopRecording();
  await expect(model).toBeHidden();
  await expect(foundInitial).toBe(true);
  await expect(foundRefreshed).toBe(true);
  await expect(foundInDraft).toBe(true);
});
