import { isNil } from 'lodash-es';

import { type PendingActionFilter } from 'src/pages/dashboard/performance/types';

import {
  ALL_FILTER,
  FILTER_CANDIDATES,
  type FilterCandidate,
} from './constants';

export const getVisibleFilterItems = (
  availableFilters: PendingActionFilter[],
): FilterCandidate[] => {
  const visibleCandidates = FILTER_CANDIDATES.filter(item =>
    !isNil(item.value) ? availableFilters.includes(item.value) : true,
  );
  if (visibleCandidates.length < 2) {
    return [];
  }
  return [ALL_FILTER, ...visibleCandidates];
};
