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

test("Issue comment composer aligns with the chat composer bottom", WEB, async ({ t3, app, browser, screen }) => {
  const project = await t3.project("Composer alignment");
  await runPromise(run("git", ["remote", "add", "origin", "https://github.com/pingdotgg/t3code.git"], { cwd: project }));
  const thread = await t3.thread({ project, title: "go", messages: ["https://github.com/pingdotgg/t3code/issues/40062"] });
  await t3.open(thread);
  await screen.getByRole("button", /^Agent https:\/\/github/).tap();
  await browser.locator('a[href="https://github.com/pingdotgg/t3code/issues/40062"]').first().tap();
  await screen.getByRole("textbox", "Add a comment", { exact: true }).waitFor();
  await screen.getByRole("textbox", "Add a comment", { exact: true }).hover();
  await browser.locator('[data-slot="preview-card-popup"]').waitFor({ state: "hidden" });
  const measurements = [];
  for (const width of [1280, 900, 600]) {
    await browser.setViewport({ width, height: 800 });
    await screen.getByRole("textbox", "Add a comment", { exact: true }).waitFor();
    const measured = await browser.evaluate(() => {
      const issue = document.querySelector('[aria-label="Add a comment"]')!.closest('[data-slot="composer-shell"]')!;
      const chat = document.querySelector('[data-chat-composer-stack="true"] [data-slot="composer-shell"]')!;
      return { width: innerWidth, chatBottom: chat.getBoundingClientRect().bottom, issueBottom: issue.getBoundingClientRect().bottom };
    });
    measurements.push(measured);
    await app.screenshot(`composer-bottom-${width}x800`);
  }
  expect(measurements, "Both composer outer areas end at the same responsive bottom inset").toEqual(measurements.map(m => ({...m, issueBottom: m.chatBottom})));
});
