import { ColumnSettingType, ApolloColumnType } from '../interfaces';
import { findKey } from './findKey';

export default function withColumnSettings<T>(
  columns: ApolloColumnType<T>[],
  columnSettings: ColumnSettingType[],
): ApolloColumnType<T>[] {
  const tempColumns: ApolloColumnType<T>[] = [];

  columnSettings.forEach((columnSetting): void => {
    const column = columns.find((col): boolean => findKey(col) === columnSetting.key);

    if (column)
      tempColumns.push({
        ...column,
        hidden: columnSetting.hidden,
        fixed: columnSetting.fixed,
      });
  });

  return tempColumns;
}
