import{c5 as a,r as f,cv as Q,ba as U,bb as V,cW as v,gn as u,F as m,go as X,ei as Z,gp as I}from"./index-DQhyMeoV.js";var ee=function(t){return t===document||t===document.documentElement||t===document.body?Math.max(window.pageYOffset,document.documentElement.scrollTop,document.body.scrollTop):t.scrollTop},O=function(t){return t.scrollHeight||Math.max(document.documentElement.scrollHeight,document.body.scrollHeight)},re=function(t){return t.clientHeight||Math.max(document.documentElement.clientHeight,document.body.clientHeight)},oe=function(t,o){o===void 0&&(o={});var g=o.target,p=o.isNoMore,x=o.threshold,w=x===void 0?100:x,B=o.direction,P=B===void 0?"bottom":B,R=o.reloadDeps,W=R===void 0?[]:R,Y=o.manual,h=o.onBefore,_=o.onSuccess,M=o.onError,y=o.onFinally,D=a(f.useState(),2),c=D[0],E=D[1],L=a(f.useState(!1),2),b=L[0],i=L[1],T=P==="top",H=f.useRef(void 0),N=f.useRef(0),S=f.useMemo(function(){return p?p(c):!1},[c]),s=Q(function(r){return U(void 0,void 0,void 0,function(){var e,n,l,d;return V(this,function(C){switch(C.label){case 0:return[4,t(r)];case 1:return e=C.sent(),E(r?v(v({},e),{list:T?u(u([],a(e.list),!1),a((l=r.list)!==null&&l!==void 0?l:[]),!1):u(u([],a((d=r.list)!==null&&d!==void 0?d:[]),!1),a(e.list),!1)}):v(v({},e),{list:u([],a((n=e.list)!==null&&n!==void 0?n:[]),!1)})),[2,e]}})})},{manual:Y,onFinally:function(r,e,n){i(!1),y?.(e,n)},onBefore:function(){return h?.()},onSuccess:function(r){setTimeout(function(){if(T){var e=I(g);if(e=e===document?document.documentElement:e,e){var n=O(e);e.scrollTo(0,n-N.current)}}else z()}),_?.(r)},onError:function(r){return M?.(r)}}),j=s.loading,$=s.error,A=s.run,q=s.runAsync,k=s.cancel,F=m(function(){S||(i(!0),A(c))}),G=m(function(){return S?Promise.reject():(i(!0),q(c))}),J=function(){return i(!1),A()},K=function(){return i(!1),q()},z=function(){var r=I(g);if(r){var e=r===document?document.documentElement:r,n=ee(e),l=O(e),d=re(e);T?(H.current!==void 0&&H.current>n&&n<=w&&F(),H.current=n,N.current=l-n):l-n<=d+w&&F()}};return X("scroll",function(){j||b||z()},{target:g}),Z(function(){A()},u([],a(W),!1)),{data:c,loading:!b&&j,error:$,loadingMore:b,noMore:S,loadMore:F,loadMoreAsync:G,reload:m(J),reloadAsync:m(K),mutate:E,cancel:k}};export{oe as u};
