import { selectorFamily } from 'recoil';
import lodashGet from 'lodash/get';
import contestSummaryCollection from '../atoms/contestSummaryCollection';
import contestSummaryResults from './contestSummaryResults';
import multiSourceData from './multiSourceData';
const contestCollectionSummaryResults = selectorFamily({
  key: 'election.selectors.contestCollectionSummaryResults',
  get: key => ({
    get
  }) => {
    const atom = contestSummaryCollection(key);
    const source = get(multiSourceData(atom.key));
    if (!source) return undefined;
    const contestEntries = source.data.contests.map(contestId => [contestId, lodashGet(get(contestSummaryResults(contestId)), 'data', undefined)]);
    return {
      data: {
        ...source.data,
        contestsById: Object.fromEntries(contestEntries)
      },
      source
    };
  }
});
export default contestCollectionSummaryResults;