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

test("duplicate trash and folder actions use one clean shared icon each", async () => {
  const [icons, chats, notifications, notificationCss, newChat, workspace] = await Promise.all([
    readFile(new URL("./ActionIcons.jsx", import.meta.url), "utf8"),
    readFile(new URL("../features/chats/ChatsPanel.jsx", import.meta.url), "utf8"),
    readFile(new URL("../features/notifications/NotificationCenter.jsx", import.meta.url), "utf8"),
    readFile(new URL("../features/notifications/notifications.css", import.meta.url), "utf8"),
    readFile(new URL("../features/chats/NewChatPanel.jsx", import.meta.url), "utf8"),
    readFile(new URL("../features/conversation/WorkspaceAttachPicker.jsx", import.meta.url), "utf8")
  ]);

  assert.match(icons, /export function TrashIcon/);
  assert.match(icons, /export function FolderIcon/);
  assert.match(icons, /export function FolderOpenIcon/);
  assert.match(chats, /<TrashIcon className="archived-chat-delete-icon" \/>/);
  assert.equal((notifications.match(/<TrashIcon/g) ?? []).length, 2);
  assert.doesNotMatch(notificationCss, /mask:url/);
  assert.match(notificationCss, /\.notification-center-dismiss-icon\{[^}]*stroke:currentColor/);
  assert.ok((newChat.match(/<FolderIcon/g) ?? []).length >= 3);
  assert.match(workspace, /<FolderIcon className="project-picker-icon" \/>/);
  assert.doesNotMatch(newChat, /FolderBrowseIcon/);
});

test("project navigation and settings choices share confirmed forward icon 24", async () => {
  const [icons, newChat, settings] = await Promise.all([
    readFile(new URL("./ActionIcons.jsx", import.meta.url), "utf8"),
    readFile(new URL("../features/chats/NewChatPanel.jsx", import.meta.url), "utf8"),
    readFile(new URL("../features/context/SettingsWindow.jsx", import.meta.url), "utf8")
  ]);

  assert.match(icons, /export function ForwardIcon/);
  assert.equal((newChat.match(/<ForwardIcon/g) ?? []).length, 2);
  assert.equal((settings.match(/<ForwardIcon/g) ?? []).length, 5);
  assert.doesNotMatch(newChat, /ChevronIcon|PromptIcon|new-chat-prompt-icon/);
});

test("settings rows use one icon gap and keep nested choice arrows near the right edge", async () => {
  const css = await readFile(new URL("../features/context/context.css", import.meta.url), "utf8");

  assert.match(css, /\.settings-choice-label\{[^}]*gap:12px/);
  assert.match(css, /\.settings-choice \.settings-select-wrap,\.settings-language-picker,\.settings-theme-picker\{[^}]*padding:0 4px 0 12px/);
  assert.match(css, /\.settings-choice \.settings-select,\.settings-language-trigger,\.settings-theme-trigger\{[^}]*padding:0/);
});

test("clock and composer tool glyphs use redesigned SVG icons", async () => {
  const [icons, usage, tools] = await Promise.all([
    readFile(new URL("./ActionIcons.jsx", import.meta.url), "utf8"),
    readFile(new URL("../features/status/UsageSettingsPage.jsx", import.meta.url), "utf8"),
    readFile(new URL("../features/conversation/ComposerToolsMenu.jsx", import.meta.url), "utf8")
  ]);

  for (const name of ["ClockIcon", "ImageUploadIcon", "PlanIcon", "SkillIcon"]) {
    assert.match(icons, new RegExp(`export function ${name}`));
  }
  assert.match(usage, /<ClockIcon className="usage-range-icon" \/>/);
  assert.match(tools, /<ImageUploadIcon \/>/);
  assert.match(tools, /<PlanIcon \/>/);
  assert.match(tools, /<SkillIcon \/>/);
  assert.doesNotMatch(tools, /[▧☷⌘]/);
});

test("copy success reuses confirmed check icon 13", async () => {
  const button = await readFile(new URL("../features/conversation/MessageCopyButton.jsx", import.meta.url), "utf8");
  assert.match(button, /<CheckIcon \/>/);
  assert.doesNotMatch(button, /m5 12 4 4L19 6/);
});
