import get from 'lodash/get';
export default function getCalendarNote({
  parties,
  isCaucus,
  officesDecided,
  notes
}) {
  const party = {
    gopOnly: 'GOP',
    demOnly: 'Dem',
    allPartyPrimary: 'all-party'
  };

  // custom notes always take priority
  if (notes) {
    return notes;
  }

  // special handling for presidential-only events
  if (officesDecided === 'presidentialRaceOnly') {
    const labels = {
      gopOnly: {
        primary: 'GOP presidential primary',
        caucus: 'GOP presidential caucus'
      },
      demOnly: {
        primary: 'Dem presidential primary',
        caucus: 'Dem presidential caucus'
      },
      demAndGop: {
        primary: 'Presidential primaries',
        caucus: 'Presidential caucuses'
      }
    };
    const key = `${parties}.${isCaucus ? 'caucus' : 'primary'}`;
    return get(labels, key);
  }

  // special handling for down-ticket-only events
  if (officesDecided === 'downBallotRacesOnly') {
    const partyName = get(party, parties, '');
    const primaries = partyName ? `${partyName} primaries` : 'primaries';
    return `Down-ticket ${primaries}`;
  }

  // no note if everything is happening
  return undefined;
}