import test from "node:test";
import assert from "node:assert/strict";
import { readFile } from "node:fs/promises";

test("new chat project rows use one-color folder icons and a current-project row state", async () => {
  const [app, panel, css] = await Promise.all([
    readFile(new URL("../../App.jsx", import.meta.url), "utf8"),
    readFile(new URL("./NewChatPanel.jsx", import.meta.url), "utf8"),
    readFile(new URL("./project-picker.css", import.meta.url), "utf8")
  ]);

  assert.doesNotMatch(app, /selectedWorkspaceId=\{app\.workspaceId\}/);
  assert.match(panel, /aria-current=\{project\.workspaceId === selectedWorkspaceId \? "true" : undefined\}/);
  assert.doesNotMatch(panel, /\u2713/);
  assert.match(panel, /<FolderIcon className="project-picker-icon" \/>/);
  assert.match(css, /\.project-picker-icon\{[^}]*stroke:currentColor/);
  assert.match(css, /\.project-picker-icon::before\{content:none\}/);
  assert.match(css, /\.project-picker-list button\[aria-current="true"\]/);
  assert.doesNotMatch(css, /\.project-picker-list button\[aria-current="true"\]\{[^}]*box-shadow:/);
});

test("light mode refresh uses a visible circular arrow spinner", async () => {
  const [indicator, css] = await Promise.all([
    readFile(new URL("../../shared/PullToRefreshIndicator.jsx", import.meta.url), "utf8"),
    readFile(new URL("../../shared/pull-to-refresh.css", import.meta.url), "utf8")
  ]);

  assert.match(indicator, /<svg className="pull-refresh-spinner"[\s\S]*?<path d="M21 12a9 9 0 1 1-2\.64-6\.36L21 8"/);
  assert.match(indicator, /<path d="M21 3v5h-5"/);
  assert.doesNotMatch(indicator, /M3 12a9|M16 16h5v5/);
  assert.doesNotMatch(indicator, /pull-refresh-arrowhead|<polygon|<polyline/);
  assert.doesNotMatch(indicator, /v2\.84h2\.84/);
  assert.match(css, /\.pull-refresh-spinner\{[^}]*stroke:currentColor[^}]*stroke-linecap:round/);
  assert.doesNotMatch(css, /\.pull-refresh-arrowhead/);
  assert.match(css, /html\[data-theme="light"\] \.app-shell \.pull-refresh-indicator\{[^}]*background-color:#fff!important[^}]*box-shadow:/);
  assert.match(css, /html\[data-theme="light"\] \.app-shell \.pull-refresh-spinner\{[^}]*color:#57606a!important/);
});

test("new chat project selection does not render a transient spinner", async () => {
  const [panel, css] = await Promise.all([
    readFile(new URL("./NewChatPanel.jsx", import.meta.url), "utf8"),
    readFile(new URL("./project-picker.css", import.meta.url), "utf8")
  ]);

  assert.doesNotMatch(panel, /NewChatLoadingSpinner|new-chat-loading-spinner/);
  assert.doesNotMatch(css, /new-chat-loading-spinner|new-chat-loading-spin/);
});
