import get from 'lodash/get';
import formatNumber from "../formatNumber/index.js";
const eevpStatus = function eevpStatus(opts) {
  const {
    status
  } = opts;
  if (!status) return undefined;
  const isOngoing = get(status, 'outcome') === 'none';
  const progress = get(status, 'progress');
  const mode = get(progress, 'mode');
  const rawPct = get(progress, 'pct', 0);
  if (!isOngoing) return undefined;
  if (mode !== 'eevp') return undefined;
  const pct = Math.round(rawPct * 100) / 100;
  const pctLeft = 1 - pct;
  const num = formatNumber(pct, {
    format: 'percent',
    maximumFractionDigits: 0
  });
  const numLeft = formatNumber(pctLeft, {
    format: 'percent',
    maximumFractionDigits: 0
  });
  if (pct === 0 || num === '0%') {
    return undefined;
  }
  if (pct < 0.2) {
    return `It’s still early in the count, with only ${num} of estimated votes counted`;
  }
  if (pct < 0.6) {
    return `Only ${num} of estimated votes have been counted`;
  }
  if (pct < 0.8) {
    return `There are still about ${numLeft} of estimated votes yet to be counted`;
  }
  if (pct >= 0.99 || num === '99%' || num === '100%') {
    return 'Less than 1% of votes have yet to be counted';
  }
  return `About ${numLeft} of estimated votes have yet to be counted`;
};
export default eevpStatus;