import type { FormFieldRowOption } from './form-field-row-option' // The value a phone settings row shows beside its label: option labels for selects (the first one // plus a `+N` count), a short date, or the text itself. Empty values return null so the row can // show its placeholder instead. export function formatFormFieldRowValue( value: unknown, options?: FormFieldRowOption[] ): string | null { const values = Array.isArray(value) ? value : [value] const filled = values.filter( (item) => item !== null && item !== undefined && String(item).trim() !== '' ) if (filled.length === 0) return null const labels = filled.map((item) => { if (item instanceof Date) return item.toLocaleDateString() const text = String(item) return options?.find((option) => option.value === text)?.label ?? text }) return labels.length > 1 ? `${labels[0]} +${labels.length - 1}` : labels[0] }