import{s as S}from"./chunk-LvLJmgfZ.js";import{n as _}from"./useEvent-D91BmmQi.js";import{t as A}from"./react-Bj1aDYRI.js";import{t as D}from"./compiler-runtime-B3qBwwSJ.js";import{t as F}from"./invariant-CkiqGLcK.js";var E=D(),y=S(A(),1),a={error(e,s){return{status:"error",data:s,error:e,isPending:!1,isFetching:!1}},success(e){return{status:"success",data:e,error:void 0,isPending:!1,isFetching:!1}},loading(e){return{status:"loading",data:e,error:void 0,isPending:!1,isFetching:!0}},pending(){return{status:"pending",data:void 0,error:void 0,isPending:!0,isFetching:!0}}};function q(...e){F(e.length>0,"combineAsyncData requires at least one response");let s=()=>{e.forEach(r=>r.refetch())},t=e.find(r=>r.status==="error");if(t!=null&&t.error)return{...a.error(t.error),refetch:s};if(e.every(r=>r.status==="success"))return{...a.success(e.map(r=>r.data)),refetch:s};let n=e.some(r=>r.status==="loading"),v=e.every(r=>r.data!==void 0);return n&&v?{...a.loading(e.map(r=>r.data)),refetch:s}:{...a.pending(),refetch:s}}function w(e,s){let t=(0,E.c)(17),[n,v]=(0,y.useState)(0),r;t[0]===Symbol.for("react.memo_cache_sentinel")?(r=a.pending(),t[0]=r):r=t[0];let[o,f]=(0,y.useState)(r),g;t[1]===e?g=t[2]:(g=typeof e=="function"?{fetch:e}:e,t[1]=e,t[2]=g);let c=_(g.fetch),p;t[3]===c?p=t[4]:(p=()=>{let i=new AbortController,l=!1;return f(x),c({previous:()=>{l=!0}}).then(b=>{i.signal.aborted||l||f(a.success(b))}).catch(b=>{i.signal.aborted||f(P=>a.error(b,P.data))}),()=>{i.abort()}},t[3]=c,t[4]=p);let h;t[5]!==s||t[6]!==c||t[7]!==n?(h=[...s,n,c],t[5]=s,t[6]=c,t[7]=n,t[8]=h):h=t[8],(0,y.useEffect)(p,h);let u;t[9]===o?u=t[10]:(u=i=>{let l;typeof i=="function"?(F(o.status==="success"||o.status==="loading","No previous state value."),l=i(o.data)):l=i,f(a.success(l))},t[9]=o,t[10]=u);let d;t[11]===n?d=t[12]:(d=()=>v(n+1),t[11]=n,t[12]=d);let m;return t[13]!==o||t[14]!==u||t[15]!==d?(m={...o,setData:u,refetch:d},t[13]=o,t[14]=u,t[15]=d,t[16]=m):m=t[16],m}function x(e){return e.status==="success"||e.status==="loading"?a.loading(e.data):a.pending()}export{w as n,q as t};
