import type { CatalogRow } from "@/app/lib/types"; // Portal-side column registry for the /catalog-setup page (add-admin-catalog-setup, spec // "admin-portal-catalog-ui"). Mirrors referenceTables.ts's registry-driven-grid pattern. All // three catalog lists key off the SAME wire field, `code`: mobile-api's CatalogRow (spec // "admin-catalog-api") carries every list's stable key in the single `code` field — for // brand that's the actual code, for category it's the categoryName value, and for // priceType it's the priceType label. Only the FORM LABEL differs per list ("Code" for // brand, "Name" for category, "Price Type" for priceType); category/priceType simply // have no separate name column, so `code` doubles as their display name. (Do not reintroduce // `field: "name"` / `field: "priceType"` for these two lists — the backend never emits either.) // Status ("Y"/"N") is never a dialog field — editable: false, badge: true marks it read-only in // the grid, rendered as a Badge; it changes only via the inline Activate/Deactivate toggle // (POST .../toggle-status), never the add/edit dialog. // Collection was removed (openspec/changes/bundle-by-sku-drop-collection) — Category is // sufficient; it had no product relationship and 0 rows. // Supplier was added (add-sku-supplier). export interface CatalogColumn { /** CatalogRow field name — the value key rendered in the grid and, when editable, the form. */ field: keyof CatalogRow; /** Human grid/form label. */ label: string; /** Whether the field appears in the add/edit dialog. Status never does. */ editable: boolean; /** Whether the field must be non-empty (enforced by the form and the server). */ required?: boolean; /** Renders as a status Badge in the grid instead of plain text; implies editable: false. */ badge?: boolean; } export interface CatalogTableSpec { /** URL list key — matches the mobile-api registry ({list} path segment). */ key: string; /** Picker label. */ label: string; columns: CatalogColumn[]; /** The stable row key field — immutable on edit. Always "code": every catalog list carries its * stable key in CatalogRow.code on the wire (see the header comment above). */ keyField: "code"; /** Whether rows carry an optional image (brand/category — add-catalog-images). */ hasImage?: boolean; /** Message code of the singular noun for copy ("No supplier rows yet"). */ noun: string; } export const CATALOG_TABLES: CatalogTableSpec[] = [ { key: "brand", label: "Brand", keyField: "code", hasImage: true, noun: "CatNounBrand", columns: [ { field: "code", label: "Code", editable: true, required: true }, { field: "name", label: "CatName", editable: true, required: true }, { field: "status", label: "Status", editable: false, badge: true }, ], }, { key: "category", label: "Category", keyField: "code", hasImage: true, noun: "CatNounCategory", columns: [ { field: "code", label: "CatName", editable: true, required: true }, { field: "status", label: "Status", editable: false, badge: true }, ], }, { key: "priceType", label: "CatTabPriceTypes", keyField: "code", noun: "CatNounPriceType", columns: [ { field: "code", label: "PricingPriceType", editable: true, required: true }, { field: "status", label: "Status", editable: false, badge: true }, ], }, { key: "supplier", label: "CatTabSuppliers", keyField: "code", noun: "CatNounSupplier", columns: [ { field: "code", label: "Code", editable: true, required: true }, { field: "name", label: "CatName", editable: true, required: true }, { field: "contactName", label: "CatColContactPerson", editable: true }, { field: "phone", label: "Phone", editable: true }, { field: "email", label: "Email", editable: true }, { field: "status", label: "Status", editable: false, badge: true }, ], }, ]; export function catalogTableSpec(key: string): CatalogTableSpec | undefined { return CATALOG_TABLES.find((t) => t.key === key); }