import{aJ as u,c8 as d,dr as E,ds as f}from"./app-k0jcl5PQ.js";const g=400;function H(e){const l=()=>{if(!e.isFetching){if(e.scrollContainer){const{scrollContainer:r}=e,n=r.getBoundingClientRect().height+r.scrollTop,a=r.scrollHeight-g;if(n<a)return}else{const r=window.innerHeight+document.documentElement.scrollTop,n=document.documentElement.scrollHeight-g;if(r<n)return}e.fetchNextPage()}};u.useEffect(()=>{const r=d.throttle(l,200),n=e.scrollContainer||window;return e.hasMore&&n.addEventListener("scroll",r),()=>n.removeEventListener("scroll",r)},[e.hasMore,e.fetchNextPage,e.scrollContainer])}function P(e,l,r,n,a,C){const[m,o]=u.useState(0),s=l;function F(c){if(!e)return null;const i=e(c);return i?i.key:null}const t=E(F,n,a);function S(){if(!(!l||!e||!t))return o(c=>c+1),s(t.nextCursor)}return H({fetchNextPage:S,hasMore:!!(t!=null&&t.nextCursor),isFetching:t==null?void 0:t.isFetching,scrollContainer:C}),u.useEffect(()=>{t&&t.shouldInitialFetch&&l&&(s(),o(c=>c+1))},[t==null?void 0:t.shouldInitialFetch,l]),u.useEffect(()=>{var i,h;if(!(t!=null&&t.statusCode)||!d.isFunction(r))return;const c=+((h=(i=t.statusCode)==null?void 0:i.toString())==null?void 0:h.substr(0,1));c!==f.ClientError&&c!==f.ServerError||r(m,t.statusCode)},[t==null?void 0:t.statusCode]),{items:t==null?void 0:t.items,hasMore:!!(t!=null&&t.nextCursor),nextCursor:t==null?void 0:t.nextCursor,isFetching:t==null?void 0:t.isFetching,totalItems:t==null?void 0:t.totalItems,hasFirstPageCompleted:t==null?void 0:t.hasFirstPageCompleted}}export{P as u};
//# sourceMappingURL=CnmbO5oy.chunk.js.map
