import { selectorFamily } from 'recoil';
import delegatesAtom from '../atoms/delegates';
import multiSourceData from './multiSourceData';
const delegates = selectorFamily({
  key: 'election.selectors.delegates',
  get: key => ({
    get
  }) => {
    const atom = delegatesAtom(key);
    const source = get(multiSourceData(atom.key));
    if (!source) return undefined;
    const {
      parties = []
    } = source.data;
    const data = parties.find(party => party.party === key);
    return {
      data,
      source
    };
  }
});
export default delegates;