import { getPartyName, getStateName } from "../../../utils/election/index.js";
import { useMemo } from 'react';

/**
 * Constructs the programmatic headline for the state importance module.
 * @param {string} stateFips         - The FIPS code of the state that's highlighted
 * @param {string} party             - The party ("dem or "gop")
 * @returns {string}
 */

const moduleHeadlineFormatter = ({
  stateFips,
  partyName
}) => {
  const stateName = getStateName(stateFips, {
    format: 'name',
    possessive: true
  });
  return `${stateName} ${partyName} delegates in context`;
};
const moduleDescriptionFormatter = ({
  party,
  partyName
}) => {
  const adj = party === 'gop' ? 'Bound' : 'Pledged';
  return `${adj} ${partyName} delegates by state or territory`;
};
const useProgrammaticTitle = ({
  stateFips,
  party,
  headline
}) => useMemo(() => {
  if (headline) {
    return headline;
  }
  const partyName = getPartyName(party, {
    format: 'abbr'
  });
  return [moduleHeadlineFormatter({
    stateFips,
    partyName
  }), moduleDescriptionFormatter({
    party,
    partyName
  })];
}, [stateFips, party]);
export default useProgrammaticTitle;