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

const svg = '<svg xmlns="http://www.w3.org/2000/svg" width="64" height="64" viewBox="0 0 64 64"><rect width="64" height="64" rx="12" fill="#18ba98"/><path d="M12 34 26 48 53 18" fill="none" stroke="white" stroke-width="9"/></svg>';

test("Project icons resolve URL fragments in HTML and route head links", WEB, async ({ t3, app, screen, browser }) => {
  const brand = await t3.project("brand-demo", {
    "public/brand/logo.svg": svg,
    "index.html": '<link rel="icon" href="/brand/logo.svg#mark">',
  });
  await t3.project("route-demo", {
    "public/brand/logo.svg": svg,
    "src/routes/__root.tsx": 'export const Route = createRootRoute({ head: () => ({ links: [{ rel: "icon", href: "/brand/logo.svg#mark" }] }) });',
  });
  await t3.project("control-demo", {
    "public/brand/logo.svg": svg,
    "index.html": '<link rel="icon" href="/brand/logo.svg">',
  });
  const thread = await t3.thread({ project: brand, title: "Favicon fragment check", messages: ["first"] });
  await t3.open(thread);
  await screen.getByRole("combobox", "Projects").tap();
  await browser.locator('[role="option"]:has-text("control-demo") img:not(.hidden)').waitFor({ state: "visible" });
  await app.screenshot("project-favicons");
  await expect(browser.locator('[role="option"]:has-text("brand-demo") img:not(.hidden)')).toBeVisible();
  await expect(browser.locator('[role="option"]:has-text("route-demo") img:not(.hidden)')).toBeVisible();
});
