import PropTypes from 'prop-types';
import useCandidateMetadata from "../../../hooks/election/useCandidateMetadata/index.js";

/**
 * A label marking a candidate as an incumbent.
 *
 * The component will render an asterisk if the candidate is an incumbent,
 * or it will return null if the candidate is not an incumbent. It can be used
 * together with [the `ContestIncumbentLabel` component][contest-incumbent], which renders
 * the corresponding footnote.
 *
 * [contest-incumbent]: ./?path=/story/components-election-contestincumbentlabel--basic
 */
const CandidateIncumbentLabel = function CandidateIncumbentLabel(props) {
  const {
    id
  } = props;
  const metadata = useCandidateMetadata(id);
  if (!metadata) return null;
  const {
    isIncumbent
  } = metadata;
  if (!isIncumbent) {
    return null;
  }
  return <>
      *
    </>;
};
CandidateIncumbentLabel.propTypes = {
  /**
   * The ID of the candidate whose incumbency you'd like to note
   */
  id: PropTypes.string.isRequired
};
export default CandidateIncumbentLabel;