import e,{Component as t}from"react";import{DomHandler as n,ZIndexUtils as r,classNames as o,IconUtils as i}from"primereact/utils";import{CSSTransition as l}from"primereact/csstransition";import{Ripple as s}from"primereact/ripple";import c from"primereact/api";function p(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function u(e,t){for(var n=0;nthis.props.threshold})}},{key:"bindParentScrollListener",value:function(){var e=this;this.scrollListener=function(){e.checkVisibility(e.helper.parentElement.scrollTop)},this.helper.parentElement.addEventListener("scroll",this.scrollListener)}},{key:"bindDocumentScrollListener",value:function(){var e=this;this.scrollListener=function(){e.checkVisibility(n.getWindowScrollTop())},window.addEventListener("scroll",this.scrollListener)}},{key:"unbindParentScrollListener",value:function(){this.scrollListener&&(this.helper.parentElement.removeEventListener("scroll",this.scrollListener),this.scrollListener=null)}},{key:"unbindDocumentScrollListener",value:function(){this.scrollListener&&(window.removeEventListener("scroll",this.scrollListener),this.scrollListener=null)}},{key:"onEnter",value:function(){r.set("overlay",this.scrollElementRef.current,c.autoZIndex,c.zIndex.overlay)}},{key:"onEntered",value:function(){this.props.onShow&&this.props.onShow()}},{key:"onExited",value:function(){r.clear(this.scrollElementRef.current),this.props.onHide&&this.props.onHide()}},{key:"componentDidMount",value:function(){"window"===this.props.target?this.bindDocumentScrollListener():"parent"===this.props.target&&this.bindParentScrollListener()}},{key:"componentWillUnmount",value:function(){"window"===this.props.target?this.unbindDocumentScrollListener():"parent"===this.props.target&&this.unbindParentScrollListener(),r.clear(this.scrollElementRef.current)}},{key:"render",value:function(){var t=this,n=o("p-scrolltop p-link p-component",{"p-scrolltop-sticky":"window"!==this.props.target},this.props.className),r="parent"===this.props.target;return e.createElement(e.Fragment,null,e.createElement(l,{nodeRef:this.scrollElementRef,classNames:"p-scrolltop",in:this.state.visible,timeout:{enter:150,exit:150},options:this.props.transitionOptions,unmountOnExit:!0,onEnter:this.onEnter,onEntered:this.onEntered,onExited:this.onExited},e.createElement("button",{ref:this.scrollElementRef,type:"button",className:n,style:this.props.style,onClick:this.onClick},i.getJSXIcon(this.props.icon,{className:"p-scrolltop-icon"},{props:this.props}),e.createElement(s,null))),r&&e.createElement("span",{ref:function(e){return t.helper=e},className:"p-scrolltop-helper"}))}}])&&u(E.prototype,w),k&&u(E,k),Object.defineProperty(E,"prototype",{writable:!1}),S}();w={target:"window",threshold:400,icon:"pi pi-chevron-up",behavior:"smooth",className:null,style:null,transitionOptions:null,onShow:null,onHide:null},(E="defaultProps")in(v=k)?Object.defineProperty(v,E,{value:w,enumerable:!0,configurable:!0,writable:!0}):v[E]=w;export{k as ScrollTop};