import test from "node:test";
import assert from "node:assert/strict";

import { renderAppShell } from "../../features/layout/app-shell.tsx";
import { renderAssetsPage } from "./assets-page.tsx";
import { renderAssetDetailPage } from "./asset-detail-page.tsx";

test("app shell renders primary navigation", () => {
  const html = renderAppShell({
    workspaceName: "Personal Workspace",
    projectName: "Delivery Demo",
    content: "<section>Assets</section>",
  });

  assert.match(html, /Assets/);
  assert.match(html, /Nodes/);
  assert.match(html, /Workflows/);
  assert.match(html, /Runs/);
  assert.match(html, /Explore/);
});

test("assets page renders asset rows from API data", () => {
  const html = renderAssetsPage({
    workspaceName: "Team Workspace",
    projectName: "Xspark Delivery",
    assets: [
      {
        id: "asset-1",
        displayName: "BJ_001_0001_OsmoNano_2026-03-19_14-51-43",
        status: "pending",
        sourceType: "upload",
        probeSummary: "Detected delivery package structure",
      },
    ],
  });

  assert.match(html, /BJ_001_0001_OsmoNano_2026-03-19_14-51-43/);
  assert.match(html, /Detected delivery package structure/);
  assert.match(html, /Create Workflow/);
});

test("asset detail page renders probe summary", () => {
  const html = renderAssetDetailPage({
    workspaceName: "Team Workspace",
    projectName: "Xspark Delivery",
    asset: {
      id: "asset-1",
      displayName: "BJ_001_0001_OsmoNano_2026-03-19_14-51-43",
      type: "folder",
      status: "pending",
      sourceType: "upload",
    },
    probeReport: {
      detectedFormats: ["delivery_package"],
      warnings: ["intrinsics.json missing"],
      recommendedNextNodes: ["validate_structure", "validate_metadata"],
    },
  });

  assert.match(html, /delivery_package/);
  assert.match(html, /intrinsics.json missing/);
  assert.match(html, /validate_structure/);
});
