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

/**
 * Select the candidate metadata for all of a contest's candidates.
 */
const contestCandidatesMetadata = selectorFamily({
  key: 'election.selectors.contestCandidatesMetadata',
  get: key => ({
    get
  }) => {
    const data = get(contest(key));
    if (!data) return undefined;
    return {
      metadata: data.metadata,
      data: Object.values(data.data.combinedMetadata.candidates)
    };
  }
});
export default contestCandidatesMetadata;