import get from 'lodash/get';
import getIsEarly from './getIsEarly';
const getLeaderParty = function getLeaderParty({
  bop,
  office
}) {
  if (!bop) return undefined;
  const isEarly = getIsEarly({
    bop,
    office
  });
  if (isEarly) return undefined;
  const calledDem = get(bop, 'bop.calledDem', 0);
  const calledGop = get(bop, 'bop.calledGop', 0);
  const totalDem = calledDem + get(bop, 'bop.seatedDem', 0);
  const totalGop = calledGop + get(bop, 'bop.seatedGop', 0);
  const hasWins = calledDem + calledGop > 0;
  const isTied = totalDem === totalGop;
  if (!hasWins) return undefined;
  if (isTied) return undefined;
  const bopLeader = get(bop, 'leader.party');
  if (bopLeader) return bopLeader;
  if (totalDem > totalGop) return 'dem';
  if (totalGop > totalDem) return 'gop';
  return undefined;
};
export default getLeaderParty;