import { getStateName } from "../index.js";

/**
 * Utility to format names of Governor contests
 *
 * @param {Object} metadata
 * @param {Object} opts
 * @param {string} opts.format
 * @returns {string}
 */
const govContestName = function govContestName(metadata, opts = {}) {
  const {
    stateFips
  } = metadata;
  const {
    format = 'long'
  } = opts;

  // e.g., "NM"
  if (format === 'tiny') {
    return getStateName(stateFips, {
      format: 'abbr'
    });
  }

  // e.g., "NM Gov."
  if (format === 'short') {
    return `${getStateName(stateFips, {
      format: 'abbr'
    })} Gov.`;
  }

  // e.g., "New Mexico Governor"
  if (format === 'medium') {
    return `${getStateName(stateFips, {
      format: 'name'
    })} Governor`;
  }

  // e.g., "Governor"
  if (format === 'no-state') {
    return 'Governor';
  }

  // e.g., "Governor, New Mexico"
  return `Governor, ${getStateName(stateFips, {
    format: 'name'
  })}`;
};
export default govContestName;