import { selectorFamily } from 'recoil';
import contest from './contest';

/**
 * Contest summary results can either be hydrated by a summary collection or
 * a single-contest summary file.
 */
const contestSummaryResults = selectorFamily({
  key: 'election.selectors.contestSummaryResults',
  get: key => ({
    get
  }) => {
    const data = get(contest(key));
    if (!data) return undefined;
    return {
      metadata: data.metadata,
      data: {
        ...data.data.summary,
        calls: data.data.callEvents
      }
    };
  }
});
export default contestSummaryResults;