import t,{Component as e}from"react";import{classNames as i,UniqueComponentId as n,DomHandler as s}from"primereact/utils";import{Ripple as r}from"primereact/ripple";import a from"primereact/api";function o(t,e){(null==e||e>t.length)&&(e=t.length);for(var i=0,n=new Array(e);i0&&(i+=-1*this.remainingItems-this.state.numScroll*t,this.isRemainingItemsAdded=!0),this.itemsContainer&&(s.removeClass(this.itemsContainer,"p-items-hidden"),this.changePosition(i),this.itemsContainer.style.transition="transform 500ms ease 0s"),this.props.onPageChange?(this.setState({totalShiftedItems:i}),this.props.onPageChange({page:e})):this.setState({page:e,totalShiftedItems:i})}},{key:"calculatePosition",value:function(){if(this.itemsContainer&&this.responsiveOptions){for(var t=window.innerWidth,e={numVisible:this.props.numVisible,numScroll:this.props.numScroll},i=0;i=t&&(e=n)}var s={};if(this.state.numScroll!==e.numScroll){var r=this.getPage();r=Math.floor(r*this.state.numScroll/e.numScroll);var a=e.numScroll*r*-1;this.isCircular()&&(a-=e.numVisible),s={totalShiftedItems:a,numScroll:e.numScroll},this.props.onPageChange?this.props.onPageChange({page:r}):s=w(w({},s),{},{page:r})}this.state.numVisible!==e.numVisible&&(s=w(w({},s),{},{numVisible:e.numVisible})),Object.keys(s).length&&this.setState(s)}}},{key:"navBackward",value:function(t,e){(this.circular||0!==this.getPage())&&this.step(1,e),this.allowAutoplay=!1,t.cancelable&&t.preventDefault()}},{key:"navForward",value:function(t,e){(this.circular||this.getPage()i?this.navForward(t,e):ethis.swipeThreshold&&(e<0?this.navForward(t):this.navBackward(t))}},{key:"bindDocumentListeners",value:function(){var t=this;this.documentResizeListener||(this.documentResizeListener=function(){t.calculatePosition()},window.addEventListener("resize",this.documentResizeListener))}},{key:"unbindDocumentListeners",value:function(){this.documentResizeListener&&(window.removeEventListener("resize",this.documentResizeListener),this.documentResizeListener=null)}},{key:"isVertical",value:function(){return"vertical"===this.props.orientation}},{key:"isCircular",value:function(){return this.circular&&this.props.value.length>=this.state.numVisible}},{key:"getPage",value:function(){return this.props.onPageChange?this.props.page:this.state.page}},{key:"getTotalIndicators",value:function(){return this.props.value?Math.ceil((this.props.value.length-this.state.numVisible)/this.state.numScroll)+1:0}},{key:"isAutoplay",value:function(){return this.props.autoplayInterval&&this.allowAutoplay}},{key:"startAutoplay",value:function(){var t=this;this.interval=setInterval((function(){t.step(-1,t.state.page===t.totalIndicators-1?0:t.state.page+1)}),this.props.autoplayInterval)}},{key:"stopAutoplay",value:function(){this.interval&&clearInterval(this.interval)}},{key:"createStyle",value:function(){this.carouselStyle||(this.carouselStyle=s.createInlineStyle(a.nonce));var t,e="\n .p-carousel[".concat(this.attributeSelector,"] .p-carousel-item {\n flex: 1 0 ").concat(100/this.state.numVisible,"%\n }\n ");if(this.props.responsiveOptions){this.responsiveOptions=l(t=this.props.responsiveOptions)||c(t)||u(t)||p(),this.responsiveOptions.sort((function(t,e){var i=t.breakpoint,n=e.breakpoint;return-1*(null==i&&null!=n?-1:null!=i&&null==n?1:null==i&&null==n?0:"string"==typeof i&&"string"==typeof n?i.localeCompare(n,void 0,{numeric:!0}):in?1:0)}));for(var i=0;i=this.totalIndicators&&(r=this.totalIndicators-1,this.props.onPageChange?this.props.onPageChange({page:r}):this.setState({page:r}),n=!0),s=r*this.state.numScroll*-1,i&&(s-=this.state.numVisible),r===this.totalIndicators-1&&this.remainingItems>0?(s+=-1*this.remainingItems+this.state.numScroll,this.isRemainingItemsAdded=!0):this.isRemainingItemsAdded=!1,s!==this.state.totalShiftedItems&&(this.setState({totalShiftedItems:s}),n=!0),this.changePosition(s)}i&&(0===this.state.page?s=-1*this.state.numVisible:0===s&&(s=-1*this.props.value.length,this.remainingItems>0&&(this.isRemainingItemsAdded=!0)),s!==this.state.totalShiftedItems&&(this.setState({totalShiftedItems:s}),n=!0)),t.page!==this.props.page&&(this.props.page>t.page&&this.props.page<=this.totalIndicators-1?this.step(-1,this.props.page):this.props.page=s,start:r===s,end:a===s})}));return t.createElement(t.Fragment,null,n,a,s)}}},{key:"renderHeader",value:function(){return this.props.header?t.createElement("div",{className:"p-carousel-header"},this.props.header):null}},{key:"renderFooter",value:function(){return this.props.footer?t.createElement("div",{className:"p-carousel-footer"},this.props.footer):null}},{key:"renderContent",value:function(){var e=this,n=this.renderItems(),s=this.isVertical()?this.props.verticalViewPortHeight:"auto",r=this.renderBackwardNavigator(),a=this.renderForwardNavigator(),o=i("p-carousel-container",this.props.containerClassName);return t.createElement("div",{className:o},r,t.createElement("div",{className:"p-carousel-items-content",style:{height:s},onTouchStart:this.onTouchStart,onTouchMove:this.onTouchMove,onTouchEnd:this.onTouchEnd},t.createElement("div",{ref:function(t){return e.itemsContainer=t},className:"p-carousel-items-container",onTransitionEnd:this.onTransitionEnd},n)),a)}},{key:"renderBackwardNavigator",value:function(){var e=(!this.circular||this.props.value&&this.props.value.length