export { type CustomFieldDef, type CustomFieldType, parseCustomFieldDefs, parseCustomData, slugifyCustomFieldKey, formatCustomFieldValue, } from '@cfdm/shared/contracts/custom-fields' import type { ReactNode } from 'react' import { Badge } from '@/components/reui/badge' import { type CustomFieldDef, formatCustomFieldValue, parseCustomData, } from '@cfdm/shared/contracts/custom-fields' import type { DataGridColumn } from '@/components/data-grid-types' export function buildCustomFieldColumns( defs: CustomFieldDef[], ): DataGridColumn[] { return defs.map((def) => ({ key: `custom_${def.key}`, header: def.label, headerTitle: def.label, enableHiding: true, sortValue: (row) => { const data = parseCustomData(row.customData) const val = data[def.key] if (def.type === 'bool') return val ? 1 : 0 if (def.type === 'number') return Number(val) || 0 return String(val ?? '') }, cell: (row): ReactNode => { const data = parseCustomData(row.customData) const val = data[def.key] if (val === undefined || val === null || val === '') { return } if (def.type === 'bool') { return ( {formatCustomFieldValue(def, val)} ) } if (def.type === 'number') { return ( {formatCustomFieldValue(def, val)} ) } const text = formatCustomFieldValue(def, val) return ( {text} ) }, })) } export function buildCustomFieldColumnVisibility( defs: CustomFieldDef[], ): Record { const visibility: Record = {} for (const def of defs) { visibility[`custom_${def.key}`] = false } return visibility }