export const formatBovinShipments = (value: unknown): string => { if (!Array.isArray(value) || value.length === 0) return '-' return value.map((item: any) => { const label = item?.shipmentType?.label ?? item?.shipmentType?.code ?? 'Type inconnu' const qty = item?.nbBovinSend ?? '-' return `${label} : ${qty}` }).join(', ') } export const formatWeights = (value: unknown): string => { if (!Array.isArray(value) || value.length === 0) return '-' let gross = 0 let tare = 0 for (const item of value as Array<{ type?: string; weight?: unknown }>) { const w = Number(item.weight) if (!Number.isFinite(w)) continue if (item.type === 'gross') gross += w else if (item.type === 'tare') tare += w } return `${gross - tare} kg` } export const formatRoleLabels = ( value: unknown, roleLabelByValue: Map, ): string => { if (!Array.isArray(value) || value.length === 0) { return ' - ' } return value .map((role) => { const key = String(role) return roleLabelByValue.get(key) ?? key }) .join(', ') } export const formatAddresses = (value: unknown): string => { if (!Array.isArray(value) || value.length === 0) { return " - " } if (typeof value[0] === 'string') { return 'Adresses non chargées' } return value .map((item) => { if (!item || typeof item !== 'object') return '-' const address = item as Record const street = String(address.street ?? '').trim() const street2 = String(address.street2 ?? '').trim() const postalCode = String(address.postalCode ?? '').trim() const city = String(address.city ?? '').trim() const countryCode = String(address.countryCode ?? '').trim().toUpperCase() const firstLine = [street, street2].filter(Boolean).join(', ') const secondLine = [postalCode, city].filter(Boolean).join(' ') const finalLine = [firstLine, secondLine, countryCode].filter(Boolean).join(', ') return finalLine || '-' }) .join('\n') }