import { useMemo } from 'react';
import uniqBy from 'lodash/uniqBy';
import get from 'lodash/get';
import sortBy from "../../../utils/sorting/sortBy.js";
export default function useSelectOptions(data) {
  return useMemo(() => {
    const events = get(data, 'electionEvents', []).filter(e => e.stateFips && !e.isNationalGeneral);
    const uniqueSet = uniqBy(events, s => s.stateFips);
    const mappedSet = uniqueSet.map(s => ({
      value: s.stateFips,
      label: s.state
    }));
    return sortBy(mappedSet, ['label']);
  }, [data]);
}