import{r as i,e as t,w as s,k as n,f as e,h as o,d as l,H as r,i as h}from"./p-5ab6b26f.js";import{s as a}from"./p-8d8e0c6f.js";class c{constructor(s){i(this,s),this.thrPx=0,this.thrPc=0,this.didFire=!1,this.isBusy=!1,this.isLoading=!1,this.threshold="15%",this.disabled=!1,this.position="bottom",this.onScroll=()=>{const i=this.scrollEl;if(!i||!this.canStart())return 1;const t=this.el.offsetHeight;if(0===t)return 2;const s=i.scrollTop,n=i.offsetHeight,e=0!==this.thrPc?n*this.thrPc:this.thrPx;if(("bottom"===this.position?i.scrollHeight-t-s-e-n:s-t-e)<0){if(!this.didFire)return this.isLoading=!0,this.didFire=!0,this.ionInfinite.emit(),3}else this.didFire=!1;return 4},this.ionInfinite=t(this,"ionInfinite",7)}thresholdChanged(){const i=this.threshold;i.lastIndexOf("%")>-1?(this.thrPx=0,this.thrPc=parseFloat(i)/100):(this.thrPx=parseFloat(i),this.thrPc=0)}disabledChanged(){const i=this.disabled;i&&(this.isLoading=!1,this.isBusy=!1),this.enableScrollEvents(!i)}async componentDidLoad(){const i=this.el.closest("ion-content");i&&(await i.componentOnReady(),this.scrollEl=await i.getScrollElement()),this.thresholdChanged(),this.disabledChanged(),"top"===this.position&&s(()=>{this.scrollEl&&(this.scrollEl.scrollTop=this.scrollEl.scrollHeight-this.scrollEl.clientHeight)})}componentDidUnload(){this.enableScrollEvents(!1),this.scrollEl=void 0}async complete(){const i=this.scrollEl;if(this.isLoading&&i&&(this.isLoading=!1,"top"===this.position)){this.isBusy=!0;const t=i.scrollHeight-i.scrollTop;requestAnimationFrame(()=>{n(()=>{const n=i.scrollHeight-t;requestAnimationFrame(()=>{s(()=>{i.scrollTop=n,this.isBusy=!1})})})})}}canStart(){return!(this.disabled||this.isBusy||!this.scrollEl||this.isLoading)}enableScrollEvents(i){this.scrollEl&&(i?this.scrollEl.addEventListener("scroll",this.onScroll):this.scrollEl.removeEventListener("scroll",this.onScroll))}render(){const i=e(this);return o(r,{class:{[i]:!0,"infinite-scroll-loading":this.isLoading,"infinite-scroll-enabled":!this.disabled}})}get el(){return l(this)}static get watchers(){return{threshold:["thresholdChanged"],disabled:["disabledChanged"]}}static get style(){return"ion-infinite-scroll{display:none;width:100%}.infinite-scroll-enabled{display:block}"}}class d{constructor(t){i(this,t)}componentDidLoad(){if(void 0===this.loadingSpinner){const i=e(this);this.loadingSpinner=h.get("infiniteLoadingSpinner",h.get("spinner","ios"===i?"lines":"crescent"))}}hostData(){const i=e(this);return{class:{[i]:!0,[`infinite-scroll-content-${i}`]:!0}}}__stencil_render(){return o("div",{class:"infinite-loading"},this.loadingSpinner&&o("div",{class:"infinite-loading-spinner"},o("ion-spinner",{name:this.loadingSpinner})),this.loadingText&&o("div",{class:"infinite-loading-text",innerHTML:a(this.loadingText)}))}render(){return o(r,this.hostData(),this.__stencil_render())}static get style(){return"ion-infinite-scroll-content{display:-ms-flexbox;display:flex;-ms-flex-direction:column;flex-direction:column;-ms-flex-pack:center;justify-content:center;min-height:84px;text-align:center;-webkit-user-select:none;-moz-user-select:none;-ms-user-select:none;user-select:none}.infinite-loading{margin-left:0;margin-right:0;margin-top:0;margin-bottom:32px;display:none;width:100%}.infinite-loading-text{margin-left:32px;margin-right:32px;margin-top:4px;margin-bottom:0}\@supports ((-webkit-margin-start:0) or (margin-inline-start:0)) or (-webkit-margin-start:0){.infinite-loading-text{margin-left:unset;margin-right:unset;-webkit-margin-start:32px;margin-inline-start:32px;-webkit-margin-end:32px;margin-inline-end:32px}}.infinite-scroll-loading ion-infinite-scroll-content>.infinite-loading{display:block}.infinite-scroll-content-md .infinite-loading-text{color:var(--ion-color-step-600,#666)}.infinite-scroll-content-md .infinite-loading-spinner .spinner-crescent circle,.infinite-scroll-content-md .infinite-loading-spinner .spinner-lines-md line,.infinite-scroll-content-md .infinite-loading-spinner .spinner-lines-small-md line{stroke:var(--ion-color-step-600,#666)}.infinite-scroll-content-md .infinite-loading-spinner .spinner-bubbles circle,.infinite-scroll-content-md .infinite-loading-spinner .spinner-circles circle,.infinite-scroll-content-md .infinite-loading-spinner .spinner-dots circle{fill:var(--ion-color-step-600,#666)}"}}export{c as ion_infinite_scroll,d as ion_infinite_scroll_content};