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

/**
 * This component prints the name of an office.
 * We currently support `president`, `senate`, `house`, `governor`,
 * `stateLtGov`, `stateAttyGen`, and `stateSecOfState` .
 */
const OfficeName = function OfficeName(props) {
  const {
    id,
    format,
    customName
  } = props;
  const name = getOfficeName(id, {
    customName,
    format
  });
  if (!name) {
    return null;
  }
  return <>
      {name}
    </>;
};
OfficeName.defaultProps = {
  customName: undefined,
  format: 'name'
};
OfficeName.propTypes = {
  /**
   * The id of the body whose name you'd like to print.
   * If not one of our supported offices, the component will return null.
   */
  id: PropTypes.oneOf(['president', 'senate', 'house', 'governor', 'stateLtGov', 'stateAttyGen', 'stateSecOfState']).isRequired,
  /**
   * The format you'd like to use. Defaults to `name`.
   */
  format: PropTypes.oneOf(['letter', 'abbr', 'name']),
  /**
   * A custom name to override the default.
   */
  customName: PropTypes.string
};
export default OfficeName;