import lodashGet from 'lodash/get';
import { selectorFamily } from 'recoil';
import contestCollectionContests from './contestCollectionContests';
const contestCollectionMetadata = selectorFamily({
  key: 'election.selectors.contestCollectionMetadata',
  get: key => ({
    get
  }) => {
    const contestsResults = get(contestCollectionContests(key));
    if (!contestsResults) return undefined;
    const contestEntries = Object.entries(contestsResults.data).map(contest => {
      const [contestId, results] = contest;
      const contestMeta = lodashGet(results, 'combinedMetadata.contest');
      if (!contestMeta) return undefined;
      return [contestId, {
        ...contestMeta,
        candidates: lodashGet(results, 'combinedMetadata.candidates')
      }];
    });
    return {
      ...contestsResults,
      data: Object.fromEntries(contestEntries)
    };
  }
});
export default contestCollectionMetadata;