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

test("Started Replay thread keeps its selection when Claude is enabled", WEB, async ({t3, app, screen, browser}) => {
  await t3.project("Selection proof");
  await t3.open("/settings/chat");
  await screen.getByRole("combobox", "Tool calls in chat").tap();
  await screen.getByRole("option", "Hide all", {exact:true}).tap();
  await t3.open("/settings/providers");
  await screen.getByRole("switch", "Enable Claude").tap();
  await t3.open("/settings/threads");
  await browser.locator('#default-model [data-chat-provider-model-picker]').tap();
  await screen.getByRole('button', 'Claude', {exact:true}).tap();
  await screen.getByRole('option', /Claude Haiku 5.5/).tap();
  await screen.getByRole('option', /Claude Haiku 5.5/).waitFor({state:'hidden'});
  await t3.open("/settings/providers");
  await screen.getByRole("switch", "Enable Claude").tap();
  await t3.open();
  await screen.getByRole("button", "New thread", {exact:true}).tap();
  await screen.getByRole("textbox").fill("first message");
  await screen.getByRole("textbox").press("Enter");
  await screen.getByText("This turn is a replay.", {exact:false}).waitFor({state:"visible"});
  const threadUrl = await browser.evaluate(() => location.pathname);
  await screen.getByRole("button", "Stop generation").waitFor({state:"hidden"});
  await app.screenshot("started-on-replay");
  await t3.open("/settings/providers");
  await screen.getByRole("switch", "Enable Claude").tap();
  await t3.open(threadUrl);
  await screen.getByRole("textbox").waitFor({state:"visible"});
  await screen.getByText("Syncing messages...", {exact:true}).waitFor({state:"hidden"});
  await browser.locator("pre").filter({hasText:"clamp(12, 0, 10)"}).waitFor({state:"visible"});
  await app.screenshot("provider-reenabled");
  await expect(screen.getByRole("button", /Showcase/)).toBeVisible();
  await expect(screen.getByText("Context handoff pending", {exact:false})).toBeHidden();
});
