import{d as f,a1 as o,o as p,a as L,O as r,W as a,l as e,f as l,u as h}from"./main-DtyiNRRn.js";const s={READY:0,LOADING:1,COMPLETE:2,ERROR:3};var u=f({name:"InfiniteLoading",setup(){const t=o(),i=o(),n=o(!1),d=o(s.READY);return{stateChanger:t,scrollParent:i,isFirstLoad:n,status:d}},computed:{isShowSpinner(){return this.status===s.LOADING},isShowError(){return this.status===s.ERROR},isShowNoResults(){return this.status===s.COMPLETE&&this.isFirstLoad},isShowNoMore(){return this.status===s.COMPLETE&&!this.isFirstLoad}},mounted(){this.scrollParent=this.getScrollParent(),this.stateChanger={loaded:()=>{this.isFirstLoad=!1,this.infinityLoad()},complete:()=>{this.status=s.COMPLETE,this.removeEventListener()},reset:()=>{this.status=s.READY,this.isFirstLoad=!0,this.addEventListener(),setTimeout(()=>{this.infinityLoad()},1)},error:()=>{this.status=s.ERROR}},setTimeout(()=>{this.infinityLoad(),this.addEventListener()})},beforeUnmount(){this.removeEventListener()},methods:{addEventListener(){this.scrollParent&&this.scrollParent.addEventListener("scroll",this.scrollHandler)},removeEventListener(){this.scrollParent&&this.scrollParent.removeEventListener("scroll",this.scrollHandler)},getCurrentDistance(){var t;const i=this.$el.getBoundingClientRect().top,n=this.scrollParent===window?window.innerHeight:(t=this.scrollParent)===null||t===void 0?void 0:t.getBoundingClientRect().bottom;return i-(n||0)},isVisible(t){return t.offsetWidth+t.offsetHeight>0},getScrollParent(t){t||(t=this.$el);let i;return t.tagName==="BODY"?i=window:(t.hasAttribute("infinite-wrapper")||t.hasAttribute("data-infinite-wrapper"))&&(i=t),i||this.getScrollParent(t.parentNode)},infinityLoad(){this.status!==s.COMPLETE&&this.isVisible(this.$el)&&this.getCurrentDistance()<=100?(this.status=s.LOADING,this.$emit("infinite",this.stateChanger)):this.status===s.LOADING&&(this.status=s.READY)},scrollHandler(){this.status===s.READY&&this.infinityLoad()}}});const E={class:"infinite-loading-container"},m={class:"infinite-status-prompt"},v=h(" Loading... "),g={class:"infinite-status-prompt"},w=h(" No results :( "),R={class:"infinite-status-prompt"},O=h(" No more data :) "),P={class:"infinite-status-prompt"},S=h(" Opps, something went wrong :( ");function C(t,i,n,d,N,D){return p(),L("div",E,[r(e("div",m,[l(t.$slots,"spinner",{},()=>[v])],512),[[a,t.isShowSpinner]]),r(e("div",g,[l(t.$slots,"no-results",{},()=>[w])],512),[[a,t.isShowNoResults]]),r(e("div",R,[l(t.$slots,"no-more",{},()=>[O])],512),[[a,t.isShowNoMore]]),r(e("div",P,[l(t.$slots,"error",{},()=>[S,e("button",{class:"btn-try-infinite",onClick:i[1]||(i[1]=(...c)=>t.infinityLoad&&t.infinityLoad(...c))},"Retry")])],512),[[a,t.isShowError]])])}u.render=C;var $=(()=>{const t=u;return t.install=i=>{i.component("InfiniteLoadingVue3Ts",t)},t})();export{$ as e};