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

const read = (relative) => readFile(new URL(relative, import.meta.url), "utf8");

test("approved interface icons use lucide while refresh and animated status marks stay custom", async () => {
  const [packageJson, icons, activity, conversation, conversationCss, gallery, queued, statusCss, refresh] = await Promise.all([
    read("../../package.json"),
    read("./ActionIcons.jsx"),
    read("../features/conversation/ActivityCard.jsx"),
    read("../features/conversation/ConversationPanel.jsx"),
    read("../features/conversation/conversation.css"),
    read("../features/conversation/ImageGallery.jsx"),
    read("../features/conversation/QueuedMessageList.jsx"),
    read("../features/status/status.css"),
    read("./PullToRefreshIndicator.jsx")
  ]);

  assert.equal(JSON.parse(packageJson).dependencies["lucide-react"] !== undefined, true);
  assert.match(icons, /from "lucide-react"/);
  for (const lucideName of [
    "AppWindow", "ArrowDown", "ArrowLeft", "ArrowUp", "Ban", "Check", "ChevronDown",
    "ChevronLeft", "ChevronRight", "Clock3", "CodeXml", "Copy", "Ellipsis", "Folder",
    "Image", "ListFilter", "ListTodo", "LoaderCircle", "Mic", "Plus", "Sparkles", "Square", "SquarePen",
    "Trash2", "X"
  ]) assert.match(icons, new RegExp(`\\b${lucideName}\\b`));

  assert.match(activity, /<TechnicalActivityIcon/);
  assert.match(activity, /<ForwardIcon className="activity-tool-call-arrow"/);
  assert.match(activity, /<DisclosureIcon className="activity-chevron"/);
  assert.match(icons, /export function AttachmentLoadingIcon/);
  assert.match(conversation, /<AttachmentLoadingIcon className="composer-attachment-pending-icon" \/>/);
  assert.doesNotMatch(conversation, /className="composer-attachment-pending"[^>]*><\/span>/);
  assert.match(conversationCss, /@keyframes composer-attachment-pending-spin/);
  assert.doesNotMatch(activity, /&lt;\/>|&gt;<\/span>/);
  assert.match(gallery, /<PreviousIcon \/>/);
  assert.match(gallery, /<ForwardIcon \/>/);
  assert.doesNotMatch(gallery, /[‹›]/);
  assert.match(queued, /<MoreIcon \/>/);
  assert.doesNotMatch(queued, /•••/);

  assert.match(statusCss, /\.usage-sort-trigger::before,\.usage-sort-direction::before\{content:none\}/);
  assert.match(statusCss, /\.usage-sort-trigger>svg,\.usage-sort-direction>svg\{/);
  assert.match(refresh, /M21 12a9 9 0 1 1-2\.64-6\.36L21 8/);
});

test("launcher source is the approved phone terminal mark", async () => {
  const source = await read("../../public/icons/icon-source.svg");
  assert.match(source, /Code Remote Manager phone terminal icon/);
  assert.match(source, /<rect x="159" y="113" width="194" height="286" rx="38"/);
  assert.match(source, /<path d="M207 225L253 263L207 301"/);
});
