import { useMemo } from 'react';
import { governors } from "../../../atoms/election/index.js";
import useTimestampedData from '../useTimestampedData';
const useStatePopulations = function useStatePopulations() {
  const data = useTimestampedData(governors) || [];
  return useMemo(() => {
    const sumPopulation = data.reduce((sum, state) => sum + state.population, 0);
    const governorData = {
      popAsRaw: {},
      popAsPct: {},
      incumbents: {},
      sum: sumPopulation
    };
    data.forEach(state => {
      const fips = state.stateFips;
      governorData.popAsRaw[fips] = state.population;
      governorData.popAsPct[fips] = state.population / sumPopulation;
      governorData.incumbents[fips] = state.party;
    });
    return governorData;
  }, [data]);
};
export default useStatePopulations;