import e,{Component as t}from"react";import{DomHandler as n,classNames as r}from"primereact/utils";function i(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n0&&(t=n+Math.floor(t/this.props.step-n/this.props.step)*this.props.step)}else t=Math.floor(t);return this.updateValue(e,t)}},{key:"updateValue",value:function(e,t){var n,r=parseFloat(t.toFixed(10)),i=r;return this.props.range?(0===this.handleIndex?rthis.value[1]&&(r=this.value[1]):r>this.props.max?r=this.props.max:rthis.props.max&&(r=this.props.max),i=r,this.props.onChange&&this.props.onChange({originalEvent:e,value:i})),i}},{key:"componentWillUnmount",value:function(){this.unbindDragListeners(),this.unbindTouchListeners()}},{key:"renderHandle",value:function(t,n,i){var s=this,o=r("p-slider-handle",{"p-slider-handle-start":0===i,"p-slider-handle-end":1===i,"p-slider-handle-active":this.handleIndex===i});return e.createElement("span",{onMouseDown:function(e){return s.onMouseDown(e,i)},onTouchStart:function(e){return s.onTouchStart(e,i)},onKeyDown:function(e){return s.onKeyDown(e,i)},tabIndex:this.props.tabIndex,className:o,style:{transition:this.dragging?"none":null,left:null!==t&&t+"%",bottom:n&&n+"%"},role:"slider","aria-valuemin":this.props.min,"aria-valuemax":this.props.max,"aria-valuenow":t||n,"aria-labelledby":this.props.ariaLabelledBy})}},{key:"renderRangeSlider",value:function(){var t=this.value,n="horizontal"===this.props.orientation,r=100*(t[0]this.props.max?100:t[1]-this.props.min)/(this.props.max-this.props.min),s=n?this.renderHandle(r,null,0):this.renderHandle(null,r,0),o=n?this.renderHandle(i,null,1):this.renderHandle(null,i,1);return e.createElement(e.Fragment,null,e.createElement("span",{className:"p-slider-range",style:n?{left:r+"%",width:i-r+"%"}:{bottom:r+"%",height:i-r+"%"}}),s,o)}},{key:"renderSingleSlider",value:function(){var t,n=this.value;t=nthis.props.max?100:100*(n-this.props.min)/(this.props.max-this.props.min);var r="horizontal"===this.props.orientation?{width:t+"%"}:{height:t+"%"},i="horizontal"===this.props.orientation?this.renderHandle(t,null,null):this.renderHandle(null,t,null);return e.createElement(e.Fragment,null,e.createElement("span",{className:"p-slider-range",style:r}),i)}},{key:"render",value:function(){var t=this,n=r("p-slider p-component",this.props.className,{"p-disabled":this.props.disabled,"p-slider-horizontal":"horizontal"===this.props.orientation,"p-slider-vertical":"vertical"===this.props.orientation}),i=this.props.range?this.renderRangeSlider():this.renderSingleSlider();return e.createElement("div",{id:this.props.id,ref:function(e){return t.el=e},style:this.props.style,className:n,onClick:this.onBarClick},i)}}])&&h(y.prototype,b),L&&h(y,L),Object.defineProperty(y,"prototype",{writable:!1}),w}();L={id:null,value:null,min:0,max:100,orientation:"horizontal",step:null,range:!1,style:null,className:null,disabled:!1,tabIndex:0,ariaLabelledBy:null,onChange:null,onSlideEnd:null},(b="defaultProps")in(y=E)?Object.defineProperty(y,b,{value:L,enumerable:!0,configurable:!0,writable:!0}):y[b]=L;export{E as Slider};