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

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

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

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

  // e.g., "N.M. Secretary of State"
  if (format === 'medium') {
    const stateName = getStateName(stateFips, {
      format: 'ap_abbr'
    });
    return `${stateName} Secretary of State`;
  }

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

  // e.g., "N.M. Secretary of State"
  const stateName = getStateName(stateFips, {
    format: 'ap_abbr'
  });
  return `${stateName} Secretary of State`;
};
export default stateSecOfStateContestName;