"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.getPaginationLayout = getPaginationLayout;
const DOTS = '...';
function range(start, end) {
  return Array.from({
    length: end - start || 1
  }).map((_, index) => start + index);
}
function getPaginationLayout({
  selectedPage,
  pageCount
}) {
  const siblingsCount = 1;
  const MAX_ELEMENTS = 2 * siblingsCount + 5; // selected, right sibling, left sibling, first, last, 2 dots

  // if the number of pages is less than MAX_ELEMENTS - render all numbers
  if (pageCount <= MAX_ELEMENTS) {
    return range(0, pageCount);
  }
  const isLeftDotsVisible = selectedPage - siblingsCount > 2;
  const isRightDotsVisible = pageCount - 1 - (selectedPage + siblingsCount) > 2;
  if (isLeftDotsVisible && isRightDotsVisible) {
    return [0, DOTS, selectedPage - 1, selectedPage, selectedPage + 1, DOTS, pageCount - 1];
  }
  if (isRightDotsVisible) {
    return [...range(0, MAX_ELEMENTS - 2), DOTS, pageCount - 1];
  }
  if (isLeftDotsVisible) {
    return [0, DOTS, ...range(pageCount - (MAX_ELEMENTS - 2), pageCount)];
  }
  return [];
}