import{g as L,p as N,J as R,K as w,i as _,s as $,a3 as E,I as B,bZ as D,n as A,o as c,q as H,r as W,x as J,b$ as K,R as v,cq as O,cr as U,L as Z,E as g,bh as j,b8 as q,M as G}from"./index-BRUnowC8.js";const Q=N({color:String,direction:{type:String,default:"vertical",validator:e=>["vertical","horizontal"].includes(e)},side:{type:String,default:"end",validator:e=>["start","end","both"].includes(e)},mode:{type:String,default:"intersect",validator:e=>["intersect","manual"].includes(e)},margin:[Number,String],loadMoreText:{type:String,default:"$vuetify.infiniteScroll.loadMore"},emptyText:{type:String,default:"$vuetify.infiniteScroll.empty"},...K(),...J()},"VInfiniteScroll"),x=O({name:"VInfiniteScrollIntersect",props:{side:{type:String,required:!0},rootMargin:String},emits:{intersect:(e,d)=>!0},setup(e,d){let{emit:o}=d;const{intersectionRef:S,isIntersecting:i}=U();return Z(i,async a=>{o("intersect",e.side,a)}),A(()=>g("div",{class:"v-infinite-scroll-intersect",style:{"--v-infinite-margin-size":e.rootMargin},ref:S},[j(" ")])),{}}}),Y=L()({name:"VInfiniteScroll",props:Q(),emits:{load:e=>!0},setup(e,d){let{slots:o,emit:S}=d;const i=R(),a=w("ok"),f=w("ok"),b=_(()=>$(e.margin)),y=w(!1);function m(t){if(!i.value)return;const n=e.direction==="vertical"?"scrollTop":"scrollLeft";i.value[n]=t}function k(){if(!i.value)return 0;const t=e.direction==="vertical"?"scrollTop":"scrollLeft";return i.value[t]}function u(){if(!i.value)return 0;const t=e.direction==="vertical"?"scrollHeight":"scrollWidth";return i.value[t]}function z(){if(!i.value)return 0;const t=e.direction==="vertical"?"clientHeight":"clientWidth";return i.value[t]}E(()=>{i.value&&(e.side==="start"?m(u()):e.side==="both"&&m(u()/2-z()/2))});function h(t,n){t==="start"?a.value=n:t==="end"?f.value=n:t==="both"&&(a.value=n,f.value=n)}function C(t){return t==="start"?a.value:f.value}let I=0;function V(t,n){y.value=n,y.value&&s(t)}function s(t){if(e.mode!=="manual"&&!y.value)return;const n=C(t);if(!i.value||["empty","loading"].includes(n))return;I=u(),h(t,"loading");function l(r){h(t,r),v(()=>{r==="empty"||r==="error"||(r==="ok"&&t==="start"&&m(u()-I+k()),e.mode!=="manual"&&v(()=>{window.requestAnimationFrame(()=>{window.requestAnimationFrame(()=>{window.requestAnimationFrame(()=>{s(t)})})})}))})}S("load",{side:t,done:l})}const{t:T}=B();function M(t,n){if(e.side!==t&&e.side!=="both")return;const l=()=>s(t),r={side:t,props:{onClick:l,color:e.color}};return n==="error"?o.error?.(r):n==="empty"?o.empty?.(r)??g("div",null,[T(e.emptyText)]):e.mode==="manual"?n==="loading"?o.loading?.(r)??c(q,{indeterminate:!0,color:e.color},null):o["load-more"]?.(r)??c(G,{variant:"outlined",color:e.color,onClick:l},{default:()=>[T(e.loadMoreText)]}):o.loading?.(r)??c(q,{indeterminate:!0,color:e.color},null)}const{dimensionStyles:F}=D(e);A(()=>{const t=e.tag,n=e.side==="start"||e.side==="both",l=e.side==="end"||e.side==="both",r=e.mode==="intersect";return c(t,{ref:i,class:W(["v-infinite-scroll",`v-infinite-scroll--${e.direction}`,{"v-infinite-scroll--start":n,"v-infinite-scroll--end":l}]),style:H(F.value)},{default:()=>[g("div",{class:"v-infinite-scroll__side"},[M("start",a.value)]),n&&r&&c(x,{key:"start",side:"start",onIntersect:V,rootMargin:b.value},null),o.default?.(),l&&r&&c(x,{key:"end",side:"end",onIntersect:V,rootMargin:b.value},null),g("div",{class:"v-infinite-scroll__side"},[M("end",f.value)])]})});function P(t){const n=t??e.side;h(n,"ok"),v(()=>{n!=="end"&&m(u()-I+k()),e.mode!=="manual"&&v(()=>{window.requestAnimationFrame(()=>{window.requestAnimationFrame(()=>{window.requestAnimationFrame(()=>{n==="both"?(s("start"),s("end")):s(n)})})})})})}return{reset:P}}});export{Y as V};
