/// <reference lib="dom" />
import { expect } from "e2e";
import { T3_HOME } from "../e2e.config.ts";
import { makeState, runPromise, test, WEB } from "./t3.ts";

test("Boring sidebar folder rows offer snooze beside settle", WEB, async ({ t3, app, browser, screen }) => {
  const project = await t3.project("Snooze demo");
  const { cli } = makeState(T3_HOME);
  // The scenario home defaults to Replay (dev), Showcase. Let thread start inherit it.
  const started = await runPromise(cli(["thread", "start", project, "go", "--title", "Review sidebar", "--wait", "--json"]));
  const thread = JSON.parse(started.stdout);
  await t3.open(thread);
  await screen.getByText("Done", { exact: true }).waitFor();
  await screen.getByText("Syncing messages...", { exact: true }).waitFor({ state: "hidden" });
  await browser.locator('[data-testid="sidebar-row-card"]').hover();
  await app.screenshot("card-row-control");
  await t3.open("/settings/labs");
  await screen.getByRole("switch", "Boring sidebar (group by project)").check();
  await t3.open(thread);
  await screen.getByText("Done", { exact: true }).waitFor();
  await screen.getByText("Syncing messages...", { exact: true }).waitFor({ state: "hidden" });
  const row = browser.locator('[data-testid="sidebar-row-folder"]');
  await row.hover();
  await row.getByRole("button", "Settle thread", { exact: true }).waitFor();
  await browser.evaluate(async () => { await Promise.allSettled(document.getAnimations().map(animation => animation.finished)); return null; });
  await app.screenshot("folder-row-hover");
  await expect(row.getByRole("button", "Snooze thread", { exact: true })).toBeVisible();
});
