"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("react"),t=require("primereact/utils"),r=require("primereact/api");function n(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var o=n(e);function i(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function l(e,t){for(var r=0;r=this.value.length);e++)this.dataToRender.push(this.value[e]);0!==this.value.length&&(this.first=this.first+this.props.rows),this.setState({dataToRender:this.dataToRender})}}},{key:"reset",value:function(){this.first=0,this.dataToRender=[],this.setState({dataToRender:this.dataToRender}),this.load()}},{key:"isEmpty",value:function(){return!this.dataToRender||0===this.dataToRender.length}},{key:"createLazyLoadMetadata",value:function(){return{first:this.first,rows:this.props.rows}}},{key:"bindScrollListener",value:function(){var e=this;this.props.inline?(this.scrollFunction=function(){e.contentElement.scrollTop>=e.contentElement.scrollHeight*e.props.buffer-e.contentElement.clientHeight&&e.load()},this.contentElement.addEventListener("scroll",this.scrollFunction)):(this.scrollFunction=function(){var t=document.body,r=document.documentElement,n=window.pageYOffset||document.documentElement.scrollTop,o=r.clientHeight;n>=Math.max(t.scrollHeight,t.offsetHeight,o,r.scrollHeight,r.offsetHeight)*e.props.buffer-o&&e.load()},window.addEventListener("scroll",this.scrollFunction))}},{key:"unbindScrollListener",value:function(){this.scrollFunction&&(this.props.inline?(this.contentElement.removeEventListener("scroll",this.scrollFunction),this.contentElement=null):this.props.loader||window.removeEventListener("scroll",this.scrollFunction)),this.scrollFunction=null}},{key:"componentDidMount",value:function(){this.load(),this.props.loader||this.bindScrollListener()}},{key:"componentDidUpdate",value:function(e,t){var r=this.props.value;r&&this.value!==r&&(this.value=r,this.first=0,this.dataToRender=[],this.handleDataChange()),e.loader!==this.props.loader&&this.props.loader&&this.unbindScrollListener()}},{key:"componentWillUnmount",value:function(){this.scrollFunction&&this.unbindScrollListener()}},{key:"renderHeader",value:function(){return this.props.header?o.default.createElement("div",{className:"p-datascroller-header"},this.props.header):null}},{key:"renderFooter",value:function(){return this.props.footer?o.default.createElement("div",{className:"p-datascroller-footer"},this.props.footer):null}},{key:"renderItem",value:function(e,t){var r=this.props.itemTemplate?this.props.itemTemplate(e):e;return o.default.createElement("li",{key:t+"_datascrollitem"},r)}},{key:"renderEmptyMessage",value:function(){var e=t.ObjectUtils.getJSXElement(this.props.emptyMessage,this.props)||r.localeOption("emptyMessage");return o.default.createElement("li",null,e)}},{key:"renderContent",value:function(){var e=this,t=this.state.dataToRender&&this.state.dataToRender.length?this.state.dataToRender.map((function(t,r){return e.renderItem(t,r)})):this.renderEmptyMessage();return o.default.createElement("div",{ref:function(t){return e.contentElement=t},className:"p-datascroller-content",style:{maxHeight:this.props.scrollHeight}},o.default.createElement("ul",{className:"p-datascroller-list"},t))}},{key:"render",value:function(){var e=t.classNames("p-datascroller p-component",this.props.className,{"p-datascroller-inline":this.props.inline}),r=this.renderHeader(),n=this.renderFooter(),i=this.renderContent();return o.default.createElement("div",{id:this.props.id,className:e},r,i,n)}}])&&l(c.prototype,h),y&&l(c,y),Object.defineProperty(c,"prototype",{writable:!1}),v}();m={id:null,value:null,rows:0,inline:!1,scrollHeight:null,loader:!1,buffer:.9,style:null,className:null,onLazyLoad:null,emptyMessage:null,itemTemplate:null,header:null,footer:null,lazy:!1},(y="defaultProps")in(h=v)?Object.defineProperty(h,y,{value:m,enumerable:!0,configurable:!0,writable:!0}):h[y]=m,exports.DataScroller=v;