import * as React from "react" ; import { CarouselInternalState , CarouselProps } from "../types" ; import { getSlidesToSlide } from "./common" ; import { isInRightEnd } from "./common" ; function populatePreviousSlides ( state , props , slidesHavePassed = 0 ) { const { currentSlide , itemWidth , slidesToShow } = state ; const { children , showDots , infinite } = props ; const slidesToSlide = getSlidesToSlide ( state , props ) ; let nextSlides ; let nextPosition ; const nextMaximumSlides = currentSlide - slidesHavePassed - ( slidesHavePassed > 0 ? 0 : slidesToSlide ! ) ; const childrenArr = React . Children . toArray ( children ) ; const additionalSlides = ( childrenArr . length - slidesToShow ) % slidesToSlide ! ; if ( nextMaximumSlides >= 0 ) { nextSlides = nextMaximumSlides ; if ( showDots && ! infinite && additionalSlides > 0 && isInRightEnd ( state ) ) { nextSlides = currentSlide - additionalSlides ; } nextPosition = - ( itemWidth * nextSlides ) ; } else if ( nextMaximumSlides < 0 && currentSlide !== 0 ) { nextSlides = 0 ; nextPosition = 0 ; } else { nextSlides = undefined ; nextPosition = undefined ; } return { nextSlides , nextPosition } ; } export { populatePreviousSlides } ;