import sortBy from "../../../../../utils/sorting/sortBy.js";
import { getStateGovernorContestId, getStateGovernorStatus } from "../../../../../utils/election/index.js";
const STATUS_SORT_ORDER = {
  seatedGop: 4,
  calledGop: 3,
  notCalled: 2,
  calledDem: 1,
  seatedDem: 0
};
export default function mergeWithResults(states, incumbents, results, metadata) {
  if (!states || !results || !metadata) {
    return [];
  }
  const stateWithStatus = states.map(state => {
    const contestId = getStateGovernorContestId(state.fips, metadata);
    const status = getStateGovernorStatus(state.fips, contestId, incumbents, results);
    return {
      ...state,
      contestId,
      status,
      statusSortOrder: STATUS_SORT_ORDER[status]
    };
  });
  return sortBy(stateWithStatus, ['statusSortOrder', {
    comparison: 'portionCount',
    direction: 'desc'
  }, 'fips']);
}