import PropTypes from 'prop-types';
import { useContestSummaryResults } from "../../../hooks/election/index.js";
import { getContestElectoralVotes } from "../../../utils/election/index.js";

/**
 * A contest's electoral votes.
 *
 * This component takes a contest id and renders the electoral votes up for grabs in that contest.
 * If the contest is not a presidential race, the component returns null.
 */
const ContestElectoralVotes = function ContestElectoralVotes(props) {
  const {
    id,
    format
  } = props;
  const summary = useContestSummaryResults(id);
  if (!summary) return null;
  const electoralVotes = getContestElectoralVotes(summary, {
    format
  });
  if (!electoralVotes) {
    return null;
  }
  return <>
      {electoralVotes}
    </>;
};
ContestElectoralVotes.defaultProps = {
  format: 'long'
};
ContestElectoralVotes.propTypes = {
  /**
   * The ID of the contest whose electoral votes you'd like to show.
   */
  id: PropTypes.string.isRequired,
  /**
   * The format to use.
   */
  format: PropTypes.oneOf(['number-only', 'long', 'short'])
};
export default ContestElectoralVotes;