"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"; import { getRegistryPresentation } from "../presentation"; 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; icon: string; accentColor: string; group: CommercialAdminResourceDef["group"]; }> >([]); 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])); const presentedEntries = 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; const presentation = binding?.presentation || getRegistryPresentation(key); return { key, label: presentation.navigationTitle, description: presentation.description, href: `/admin/commercial/${key}`, listPath: path, icon: presentation.icon, accentColor: presentation.accentColor, group: binding?.group || "catalog", }; }); setEntries( Array.from( new Map(presentedEntries.map((entry) => [entry.key, entry])).values() ) ); return; } setEntries( COMMERCIAL_ADMIN_RESOURCES.map((r: CommercialAdminResourceDef) => ({ key: r.key, label: r.presentation.navigationTitle, description: r.presentation.description, href: `/admin/commercial/${r.key}`, listPath: r.listPath, icon: r.presentation.icon, accentColor: r.presentation.accentColor, group: r.group, })) ); })(); }, []); return (
{entries.filter((entry) => entry.group !== "tenant").map((r) => (

{r.label}

{r.description}

))}

مشتریان و فعال‌سازی

{COMMERCIAL_ADMIN_RESOURCES.filter((r) => r.group === "tenant").map((r) => (

{r.presentation.navigationTitle}

{r.presentation.description}

))}
); }