import { getStateGovernorContestId, getStateGovernorStatus } from "../../../utils/election/index.js";
import useContestCollectionContests from '../useContestCollectionContests';
import useContestCollectionMetadata from '../useContestCollectionMetadata';
import useStatePopulations from '../useStatePopulations';
export default function useAggregateGovernors(collectionId) {
  const results = useContestCollectionContests(collectionId);
  const metadata = useContestCollectionMetadata(collectionId);
  const states = useStatePopulations();
  if (!results || !metadata || !states) {
    return undefined;
  }
  return Object.entries(states.incumbents).reduce((acc, [fips]) => {
    const contestId = getStateGovernorContestId(fips, metadata);
    const status = getStateGovernorStatus(fips, contestId, states.incumbents, results);
    acc[fips] = status;
    return acc;
  }, {});
}