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

test("Right panel tooltip appears over the tab top strip", WEB, async ({ t3, app, screen, browser }) => {
  await browser.emulateMedia({ colorScheme: "dark" });
  const project = await t3.project("panel-demo");
  const thread = await t3.thread({ project, title: "Tab tooltip", messages: ["Hello"] });
  await t3.open(thread);
  await screen.getByRole("button", "Toggle right panel").tap();
  await screen.getByRole("button", "Browser B").tap();
  await screen.getByRole("textbox", "Search or enter URL").waitFor();
  await screen.getByText("You have control", { exact: true }).waitFor();
  const point = await browser.evaluate(() => {
    const row = document.querySelector('[data-active-tab="true"]');
    if (!row) throw new Error("Active panel tab missing");
    const rect = row.getBoundingClientRect();
    return { x: rect.x + rect.width * 0.6, y: rect.top + 1 };
  });
  await browser.mouse.move(point.x, point.y);
  try {
    await expect.poll(() => browser.evaluate(() => {
      const popup = document.querySelector('[data-slot="tooltip-popup"]');
      return popup && getComputedStyle(popup).opacity === "1" ? popup.textContent?.trim() : null;
    })).toBe("Browser");
  } finally {
    await app.screenshot("tab-top-strip-tooltip");
  }
});
