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