const SWIPE_THRESHOLD = 48;

export function moveGalleryIndex(index, delta, count) {
  return Math.max(0, Math.min(Math.max(0, count - 1), index + delta));
}

export function galleryIndexAfterSwipe(index, startX, endX, count) {
  const distance = endX - startX;
  if (!isGallerySwipe(startX, endX)) return index;
  return moveGalleryIndex(index, distance < 0 ? 1 : -1, count);
}

export function isGallerySwipe(startX, endX) {
  return Math.abs(endX - startX) >= SWIPE_THRESHOLD;
}
