"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("react"),t=require("primereact/utils");function o(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var n=o(e);function r(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function a(e,t){for(var o=0;oparseInt(e["max-height"],10)?e["max-height"]:this.content.offsetHeight+parseFloat(e.paddingTop)+parseFloat(e.paddingBottom)+parseFloat(e.borderTopWidth)+parseFloat(e.borderBottomWidth)+"px")}},{key:"moveBar",value:function(){var e=this,o=this.content.scrollWidth,n=-1*(this.container.clientHeight-this.xBar.clientHeight);this.scrollXRatio=this.content.clientWidth/o;var r=this.content.scrollHeight,a=-1*(this.container.clientWidth-this.yBar.clientWidth);this.scrollYRatio=this.content.clientHeight/r,this.frame=this.requestAnimationFrame((function(){e.scrollXRatio>=1?t.DomHandler.addClass(e.xBar,"p-scrollpanel-hidden"):(t.DomHandler.removeClass(e.xBar,"p-scrollpanel-hidden"),e.xBar.style.cssText="width:"+Math.max(100*e.scrollXRatio,10)+"%; left:"+e.content.scrollLeft/o*100+"%;bottom:"+n+"px;"),e.scrollYRatio>=1?t.DomHandler.addClass(e.yBar,"p-scrollpanel-hidden"):(t.DomHandler.removeClass(e.yBar,"p-scrollpanel-hidden"),e.yBar.style.cssText="height:"+Math.max(100*e.scrollYRatio,10)+"%; top: calc("+e.content.scrollTop/r*100+"% - "+e.xBar.clientHeight+"px);right:"+a+"px;")}))}},{key:"onYBarMouseDown",value:function(e){this.isYBarClicked=!0,this.lastPageY=e.pageY,t.DomHandler.addClass(this.yBar,"p-scrollpanel-grabbed"),t.DomHandler.addClass(document.body,"p-scrollpanel-grabbed"),document.addEventListener("mousemove",this.onDocumentMouseMove),document.addEventListener("mouseup",this.onDocumentMouseUp),e.preventDefault()}},{key:"onXBarMouseDown",value:function(e){this.isXBarClicked=!0,this.lastPageX=e.pageX,t.DomHandler.addClass(this.xBar,"p-scrollpanel-grabbed"),t.DomHandler.addClass(document.body,"p-scrollpanel-grabbed"),document.addEventListener("mousemove",this.onDocumentMouseMove),document.addEventListener("mouseup",this.onDocumentMouseUp),e.preventDefault()}},{key:"onDocumentMouseMove",value:function(e){this.isXBarClicked?this.onMouseMoveForXBar(e):(this.isYBarClicked||this.onMouseMoveForXBar(e),this.onMouseMoveForYBar(e))}},{key:"onMouseMoveForXBar",value:function(e){var t=this,o=e.pageX-this.lastPageX;this.lastPageX=e.pageX,this.frame=this.requestAnimationFrame((function(){t.content.scrollLeft+=o/t.scrollXRatio}))}},{key:"onMouseMoveForYBar",value:function(e){var t=this,o=e.pageY-this.lastPageY;this.lastPageY=e.pageY,this.frame=this.requestAnimationFrame((function(){t.content.scrollTop+=o/t.scrollYRatio}))}},{key:"onDocumentMouseUp",value:function(e){t.DomHandler.removeClass(this.yBar,"p-scrollpanel-grabbed"),t.DomHandler.removeClass(this.xBar,"p-scrollpanel-grabbed"),t.DomHandler.removeClass(document.body,"p-scrollpanel-grabbed"),document.removeEventListener("mousemove",this.onDocumentMouseMove),document.removeEventListener("mouseup",this.onDocumentMouseUp),this.isXBarClicked=!1,this.isYBarClicked=!1}},{key:"requestAnimationFrame",value:function(e){return(window.requestAnimationFrame||this.timeoutFrame)(e)}},{key:"refresh",value:function(){this.moveBar()}},{key:"componentDidMount",value:function(){this.moveBar(),this.moveBar=this.moveBar.bind(this),window.addEventListener("resize",this.moveBar),this.calculateContainerHeight(),this.initialized=!0}},{key:"componentWillUnmount",value:function(){this.initialized&&window.removeEventListener("resize",this.moveBar),this.frame&&window.cancelAnimationFrame(this.frame)}},{key:"render",value:function(){var e=this,o=t.classNames("p-scrollpanel p-component",this.props.className);return n.default.createElement("div",{ref:function(t){return e.container=t},id:this.props.id,className:o,style:this.props.style},n.default.createElement("div",{className:"p-scrollpanel-wrapper"},n.default.createElement("div",{ref:function(t){return e.content=t},className:"p-scrollpanel-content",onScroll:this.moveBar,onMouseEnter:this.moveBar},this.props.children)),n.default.createElement("div",{ref:function(t){return e.xBar=t},className:"p-scrollpanel-bar p-scrollpanel-bar-x",onMouseDown:this.onXBarMouseDown}),n.default.createElement("div",{ref:function(t){return e.yBar=t},className:"p-scrollpanel-bar p-scrollpanel-bar-y",onMouseDown:this.onYBarMouseDown}))}}])&&a(h.prototype,m),f&&a(h,f),Object.defineProperty(h,"prototype",{writable:!1}),y}();f={id:null,style:null,className:null},(m="defaultProps")in(h=v)?Object.defineProperty(h,m,{value:f,enumerable:!0,configurable:!0,writable:!0}):h[m]=f,exports.ScrollPanel=v;