import{c7 as a,r as f,cx as V,bc as W,bd as X,cY as v,fs as u,aU as m,ft as Z,fu as $,fv as C}from"./index-Y-QvttbJ.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},I=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,F=o.isNoMore,p=o.threshold,w=p===void 0?100:p,B=o.direction,O=B===void 0?"bottom":B,R=o.reloadDeps,P=R===void 0?[]:R,U=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),T=L[0],i=L[1],b=O==="top",H=f.useRef(void 0),N=f.useRef(0),S=f.useMemo(function(){return F?F(c):!1},[c]),s=V(function(r){return W(void 0,void 0,void 0,function(){var e,n,l,d;return X(this,function(z){switch(z.label){case 0:return[4,t(r)];case 1:return e=z.sent(),E(r?v(v({},e),{list:b?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:U,onFinally:function(r,e,n){i(!1),y?.(e,n)},onBefore:function(){return h?.()},onSuccess:function(r){setTimeout(function(){if(b){var e=C(g);if(e=e===document?document.documentElement:e,e){var n=I(e);e.scrollTo(0,n-N.current)}}else q()}),_?.(r)},onError:function(r){return M?.(r)}}),Y=s.loading,k=s.error,A=s.run,j=s.runAsync,G=s.cancel,x=m(function(){S||(i(!0),A(c))}),J=m(function(){return S?Promise.reject():(i(!0),j(c))}),K=function(){return i(!1),A()},Q=function(){return i(!1),j()},q=function(){var r=C(g);if(r){var e=r===document?document.documentElement:r,n=ee(e),l=I(e),d=re(e);b?(H.current!==void 0&&H.current>n&&n<=w&&x(),H.current=n,N.current=l-n):l-n<=d+w&&x()}};return Z("scroll",function(){Y||T||q()},{target:g}),$(function(){A()},u([],a(P),!1)),{data:c,loading:!T&&Y,error:k,loadingMore:T,noMore:S,loadMore:x,loadMoreAsync:J,reload:m(K),reloadAsync:m(Q),mutate:E,cancel:G}};export{oe as u};
