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

/**
 * The name of district, formatted as specified.
 *
 * This component takes a state FIPS code and district number and
 * renders the a title for the district.
 *
 */
const ContestName = function ContestName(props) {
  const {
    stateFips,
    districtNumber,
    format
  } = props;
  const name = getDistrictName({
    districtNumber,
    stateFips,
    format
  });
  if (!name) return null;
  return <>
      {name}
    </>;
};
ContestName.defaultProps = {
  format: 'full'
};
ContestName.propTypes = {
  /**
   * The FIPS code of the state the district is in
   */
  stateFips: PropTypes.string.isRequired,
  /**
   * The district number
   */
  districtNumber: PropTypes.string.isRequired,
  /**
   * The format to use
   */
  format: PropTypes.oneOf(['ordinal', 'abbr', 'full'])
};
export default ContestName;