import get from 'lodash/get';
const possessive = name => {
  if (name.endsWith('s')) return `${name}’`;
  return `${name}’s`;
};
const useHeadline = function useHeadline(opts) {
  const {
    candidates,
    canonicalTotals
  } = opts;
  const defaultHeadline = 'Presidential paths to victory';
  if (get(canonicalTotals, 'dem') >= 270) {
    const name = get(candidates, 'dem.name');
    return name ? `${possessive(name)} path to victory` : defaultHeadline;
  }
  if (get(canonicalTotals, 'gop') >= 270) {
    const name = get(candidates, 'gop.name');
    return name ? `${possessive(name)} path to victory` : defaultHeadline;
  }
  return defaultHeadline;
};
export default useHeadline;