type SPREADING_PAGE_SYMBOL_TYPE = '-';
const SPREADING_SYMBOL = '-';

const generatePages = ({
  current,
  total,
}: {
  current: number;
  total: number;
}): (number | SPREADING_PAGE_SYMBOL_TYPE)[] => {
  if (total <= 7) {
    return Array.from({ length: total }, (_, i) => i + 1);
  }

  if (current < 5) {
    return [1, 2, 3, 4, 5, SPREADING_SYMBOL, total];
  }

  if (current > total - 4) {
    return [
      1,
      SPREADING_SYMBOL,
      total - 4,
      total - 3,
      total - 2,
      total - 1,
      total,
    ];
  }

  return [
    1,
    SPREADING_SYMBOL,
    current - 1,
    current,
    current + 1,
    SPREADING_SYMBOL,
    total,
  ];
};

const getDisplayState = ({
  current,
  pageNumber,
}: {
  current: number;
  pageNumber: number | SPREADING_PAGE_SYMBOL_TYPE;
}): 'pageNumber' | 'activePage' | 'spreading' => {
  if (pageNumber === SPREADING_SYMBOL) {
    return 'spreading';
  }

  if (current === pageNumber) {
    return 'activePage';
  }

  return 'pageNumber';
};

export { SPREADING_SYMBOL, generatePages, getDisplayState };
