import { ProviderInstanceId } from "@t3tools/contracts";
import { expect } from "e2e";
import * as Effect from "effect/Effect";
import { T3_HOME } from "../e2e.config.ts";
import { rpcClient, runPromise, test, WEB } from "./t3.ts";

test("Provider shortcut closes the open session mode menu", WEB, async ({ t3, app, browser, screen }) => {
  const project = await t3.project("Shortcut demo");
  const thread = await t3.thread({ project, title: "Model options", messages: ["Hello"], model: "multi-turn" });
  await runPromise(Effect.gen(function* () {
    const client = yield* rpcClient(T3_HOME, app.baseUrl ?? "");
    yield* client["server.updateSettings"]({ patch: {}, providerInstanceMutation: {
      operation: "upsert", instanceId: ProviderInstanceId.make("opencode-acp"),
      instance: { driver: "acpRegistry", displayName: "OpenCode ACP", enabled: true,
        config: { source: "local", commandPath: "opencode", commandArgs: ["acp"] } },
    } });
  }).pipe(Effect.scoped));
  await t3.open(thread);
  const picker = browser.locator("[data-chat-provider-model-picker]").first();
  await picker.tap();
  await screen.getByRole("button", "OpenCode ACP", { exact: true }).tap();
  await screen.getByRole("option", /Claude Haiku 5.5/).tap();
  await screen.getByRole("button", /^Session Mode:/).tap();
  await screen.getByRole("menuitemradio", /^Build/).waitFor();
  await app.screenshot("session-mode-open");
  await browser.keyboard.press("Control+Shift+ArrowDown");
  await browser.locator('input[placeholder="Search models..."]').waitFor();
  await app.screenshot("after-provider-shortcut");
  await expect(browser.locator("[data-model-picker-option-menu]")).not.toBeVisible();
});
