import { Column, TableColumn } from '../model';

export function simplifyColumn<T>(
  {
    id: maybeId,
    name,
    hideable = true,
    hiddenFromCustomColumnsSelection = false,
    infoTooltipProps,
    ...rest
  }: TableColumn<T>,
  { fallbackID }: { fallbackID?: number } = {},
): Column {
  const id = maybeId ?? String(fallbackID);
  return {
    id,
    name: name ?? '',
    hiddenFromCustomColumnsSelection,
    hideable: maybeId == null ? false : hideable,
    infoTooltipProps: infoTooltipProps
      ? {
          content: infoTooltipProps.content,
          panelContent: infoTooltipProps.panelContent,
          ...infoTooltipProps,
        }
      : undefined,
    ...rest,
  };
}

export function simplifyColumns<T>(tableColumns: TableColumn<T>[]): Column[] {
  return tableColumns.map((props, i): Column => {
    return simplifyColumn(props, { fallbackID: i });
  });
}
