"use client"; import type { AdapterResult, RegistryAvailability } from "../types"; import { CommercialEmptyState } from "./CommercialEmptyState"; import { fieldLabel, friendlyMessage, humanizeCommercialCode, isTechnicalField, presentValue, } from "../presentation"; function availabilityLabel(a: RegistryAvailability): string { switch (a) { case "loading": return "در حال بارگذاری…"; case "empty": return "خالی"; case "unavailable": return "در دسترس نیست"; case "permission_denied": return "بدون دسترسی"; case "error": return "خطا"; default: return ""; } } function PresentedValue({ value }: { value: unknown }) { const presented = presentValue(value); if (Array.isArray(presented)) { return (
{presented.map((item, index) => ( {item} ))}
); } if (presented && typeof presented === "object") { const entries = Object.entries(presented).filter(([key]) => !isTechnicalField(key)); return (
مشاهده جزئیات
{entries.map(([key, nested]) => (
{fieldLabel(key)}
))}
); } return <>{presented}; } /** Generic human-facing catalog list. Implementation identifiers are deliberately hidden. */ export function RegistryBrowser({ title, subtitle, result, codeKey, nameKey = "display_name", emptyTitle, }: { title: string; subtitle?: string; result: AdapterResult | null; codeKey: string; nameKey?: string; emptyTitle?: string; }) { if (!result || result.availability === "loading") { return (

{title}

{availabilityLabel("loading")}

); } if (result.availability !== "ready" || !result.data.length) { return (

{title}

{subtitle ?

{subtitle}

: null}
); } return (

{title}

{subtitle ?

{subtitle}

: null}
); } /** Renders an arbitrary metadata bag without whitelisting attribute keys. */ export function MetadataBagView({ title, attributes, message, availability, }: { title: string; attributes?: Record | null; message?: string; availability?: RegistryAvailability; }) { const entries = attributes ? Object.entries(attributes) : []; if (!entries.length) { return ( ); } return (

{title}

{entries.filter(([key]) => !isTechnicalField(key)).map(([key, value]) => (
{fieldLabel(key)}
))}
); }