import { getCandidatesSortedByResults } from "../../../utils/election/index.js";
import useResults from '../useResults';
import useContestCandidatesMetadata from '../useContestCandidatesMetadata';

/**
 * Hook to select the information necessary to sort candidates and then return
 * a list of candidate IDs sorted by their results status, falling back to
 * various metadata fields. See the `getCandidatesSortedByResults` utility
 * function for more details on how the candidates are sorted.
 *
 * @param {ContestId|CountyId} id
 * @returns {CandidateId[]}
 */
const useCandidatesSortedByResults = function useCandidatesSortedByResults(id) {
  const results = useResults(id);
  const candidatesMetadata = useContestCandidatesMetadata(id);
  return getCandidatesSortedByResults({
    results,
    candidatesMetadata
  });
};
export default useCandidatesSortedByResults;