import get from 'lodash/get';
import { resolveContestId } from "../../../utils/election/index.js";
import { cycleCandidateMetadata, contest } from "../../../atoms/election/index.js";
import useTimestampedData from '../useTimestampedData';
const useCandidateMetadata = function useCandidateMetadata(id) {
  const isCycle = id && id.startsWith('cycle');
  const atom = isCycle ? cycleCandidateMetadata(id) : contest(resolveContestId(id));
  const value = useTimestampedData(atom);
  return isCycle ? value : get(value, `combinedMetadata.candidates.${id}`);
};
export default useCandidateMetadata;