import { selectorFamily } from 'recoil';
import contestCountyResultsAtom from '../atoms/contestCountyResults';
import multiSourceData from './multiSourceData';

/**
 * Contest county results can only be hydrated by a single-contest county-level
 * results file.
 */
const contestCountyResults = selectorFamily({
  key: 'election.selectors.contestCountyResults',
  get: key => ({
    get
  }) => {
    const atom = contestCountyResultsAtom(key);
    const source = get(multiSourceData(atom.key));
    if (!source) return undefined;
    return {
      data: source.data,
      source
    };
  }
});
export default contestCountyResults;