import { useStatePopulations, useAggregateGovernors } from "../../../hooks/election/index.js";
export default function useBopToplines(collectionId) {
  const statePops = useStatePopulations();
  const governors = useAggregateGovernors(collectionId);
  if (!governors) {
    return undefined;
  }
  const bop = Object.entries(statePops.popAsRaw).reduce((acc, [fips, popCount]) => {
    const stateStatus = governors[fips];
    if (stateStatus in acc) {
      acc[stateStatus] += popCount;
    } else {
      acc[stateStatus] = popCount;
    }
    return acc;
  }, {
    calledDem: 0,
    calledGop: 0,
    seatedDem: 0,
    seatedGop: 0
  });
  const seatedGopStates = Object.entries(governors).filter(([, s]) => s === 'seatedGop').length;
  const seatedDemStates = Object.entries(governors).filter(([, s]) => s === 'seatedDem').length;
  return {
    ...bop,
    total: statePops.sum,
    demTotal: bop.calledDem + bop.seatedDem,
    gopTotal: bop.calledGop + bop.seatedGop,
    seatedDemStates,
    seatedGopStates
  };
}