import { Col } from '../dc-validator/models/col.model'

/**
 * Maps grid column names to their display headers.
 *
 * When `useLabels` is true, each name is swapped for its `LABEL` from `cols`
 * (falling back to the NAME itself when a column has no LABEL, or isn't
 * present in `cols` at all). Order always follows `colNames` (grid order).
 */
export function getDisplayColHeaders(
  colNames: string[],
  cols: Col[],
  useLabels: boolean
): string[] {
  if (!useLabels) return colNames

  const labelsByName = new Map(cols.map((col) => [col.NAME, col.LABEL]))

  return colNames.map((name) => labelsByName.get(name) || name)
}
