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 DistrictName = function DistrictName(props) {
  const {
    stateFips,
    districtNumber,
    format = 'long'
  } = props;
  const name = getDistrictName({
    districtNumber,
    stateFips,
    format
  });
  if (!name) return null;
  return <>
      {name}
    </>;
};
DistrictName.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 DistrictName;