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

/**
 * The name of a candidate.
 */
const CandidateName = function CandidateName(props) {
  const {
    id,
    format
  } = props;
  const metadata = useCandidateMetadata(id);
  const name = getCandidateName(metadata, {
    format
  });
  if (!name) return null;
  return <>
      {name}
    </>;
};
CandidateName.defaultProps = {
  format: 'full'
};
CandidateName.propTypes = {
  /**
   * The ID of the candidate whose name you want to format.
   */
  id: PropTypes.string.isRequired,
  /**
   * The name format to use.
   */
  format: PropTypes.oneOf(['short', 'full'])
};
export default CandidateName;