import { apnumber, intcomma } from 'journalize';
import { getPartyName } from "../../../../utils/election/index.js";
const defaultHeadline = '{delegates} {party} delegates are up for grabs in {states} states';
export default function getHeadline({
  headline,
  party,
  delegates,
  states
}) {
  const fipsCodes = new Set(states);
  const stateDels = delegates.states.filter(state => fipsCodes.has(state.stateFips)).reduce((total, state) => total + state.total, 0);
  const numDels = intcomma(stateDels);
  const numStates = apnumber(states.length);
  const partyName = getPartyName(party);
  const headlineTemplate = headline || defaultHeadline;
  return headlineTemplate.replace('{delegates}', numDels).replace('{party}', partyName).replace('{states}', numStates);
}