import { useRef } from 'react';

var usePaginationDots = function usePaginationDots(_ref) {
  var items = _ref.items,
    index = _ref.index,
    _ref$visibleItems = _ref.visibleItems,
    visibleItems = _ref$visibleItems === void 0 ? 7 : _ref$visibleItems;
  var activeId = items[index].id;
  var prevIndex = useRef(null);
  var direction = 0;
  if (prevIndex.current !== null) {
    direction = index > prevIndex.current ? 1 : -1;
  }
  var start;
  var end;
  if (direction === 1) {
    end = Math.min(Math.max(index + 2, visibleItems), items.length);
    start = Math.max(end - visibleItems, 0);
  } else if (direction === -1) {
    start = Math.min(Math.max(index - 1, 0), items.length - visibleItems);
    end = start + visibleItems;
  } else {
    start = Math.max(index - Math.floor(visibleItems / 2), 0);
    end = Math.min(start + visibleItems, items.length);
    start = end - visibleItems;
  }
  var sliced = items.slice(start, end);
  prevIndex.current = index;
  return {
    sliced: sliced,
    activeId: activeId
  };
};

export { usePaginationDots };
