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

/**
 * Select the color assignments of each candidate in a contest.
 */
const contestCandidateColors = selectorFamily({
  key: 'election.selectors.contestCandidateColors',
  get: key => ({
    get
  }) => {
    const data = get(contest(key));
    if (!data) return undefined;
    return {
      metadata: data.metadata,
      data: data.data.candidateColors
    };
  }
});
export default contestCandidateColors;