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

/**
 * The name of a party, formatted as specified.
 *
 * We currently support four parties: `dem`, `gop`, `independent` and `other-party`.
 * Additionally, `fallback` will return the value for other party.
 *
 * There are three formatting options for parties:
 * 1. `letter`: The shortest version (e.g., D for Democrat)
 * 2. `abbr`: An abbreviation of the party (e.g., Dem for Democrat)
 * 3. `name`: The full name of the party (e.g., Democrat)
 */
const PartyName = function PartyName(props) {
  const {
    id,
    format,
    fullPartyName
  } = props;
  const name = getPartyName(id, {
    format,
    fullPartyName
  });
  if (!name) {
    return null;
  }
  return <>
      {name}
    </>;
};
PartyName.defaultProps = {
  id: undefined,
  format: 'abbr',
  fullPartyName: undefined
};
PartyName.propTypes = {
  /**
   * The ID of the party you want to format.
   * If the ID is undefined, or not one of our four supported parties,
   * the component will return null.
   */
  id: PropTypes.oneOf(['dem', 'gop', 'independent', 'other-party', 'yes', 'no']),
  /**
   * The format to use.
   */
  format: PropTypes.oneOf(['letter', 'letter-parenthesis', 'abbr', 'name']),
  /**
   * A custom full party name to use as an override. Mostly used when getting
   * a candidate's party.
   */
  fullPartyName: PropTypes.string
};
export default PartyName;