"use client"; import { useEffect, useState } from "react"; import Link from "next/link"; import { AdminPageHeader, cardClass } from "@/components/admin/controls"; import { commercialGet } from "../adapters/http"; import { COMMERCIAL_ADMIN_RESOURCES, type CommercialAdminResourceDef, } from "../admin/resources"; type CatalogEntry = { kind: string; path?: string; display_name?: string; description?: string | null; href?: string; generic_href?: string; }; /** * Admin hub — prefers live GET /api/v1/commercial/catalog. * Static resource defs are path bindings only (no row data); used as label fallback. */ export function AdminCommercialHub() { const [entries, setEntries] = useState< Array<{ key: string; label: string; description: string; href: string; listPath: string }> >([]); const [source, setSource] = useState<"catalog" | "bindings">("bindings"); const [error, setError] = useState(""); useEffect(() => { void (async () => { const res = await commercialGet<{ registries?: CatalogEntry[] }>("/api/v1/commercial/catalog"); if (res.ok && Array.isArray(res.data.registries) && res.data.registries.length) { const byPath = new Map(COMMERCIAL_ADMIN_RESOURCES.map((r) => [r.listPath, r])); setEntries( res.data.registries.map((r) => { const path = r.href || `/api/v1/commercial/${r.path || r.kind}`; const binding = byPath.get(path) || byPath.get(`/api/v1/commercial/${r.path}`); const key = binding?.key || r.path || r.kind; return { key, label: r.display_name || binding?.label || r.kind, description: r.description || binding?.description || "Commercial registry", href: `/admin/commercial/${key}`, listPath: path, }; }) ); setSource("catalog"); return; } setError(res.ok ? "" : res.message); setEntries( COMMERCIAL_ADMIN_RESOURCES.map((r: CommercialAdminResourceDef) => ({ key: r.key, label: r.label, description: r.description, href: `/admin/commercial/${r.key}`, listPath: r.listPath, })) ); setSource("bindings"); })(); }, []); return (
discovery: {source} {error ? ` · ${error}` : ""}
{r.label}
{r.description}
{r.listPath}
))}{r.label}
{r.description}
))}