import{s as S}from"./chunk-LvLJmgfZ.js";import{n as _}from"./useEvent-WUlsM6MC.js";import{t as A}from"./react-Bj1aDYRI.js";import{t as D}from"./compiler-runtime-B3qBwwSJ.js";import{t as F}from"./invariant-awXiPaF0.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,l]=(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,f=!1;return l(x),c({previous:()=>{f=!0}}).then(b=>{i.signal.aborted||f||l(a.success(b))}).catch(b=>{i.signal.aborted||l(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 f;typeof i=="function"?(F(o.status==="success"||o.status==="loading","No previous state value."),f=i(o.data)):f=i,l(a.success(f))},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"?a.loading(e.data):a.pending()}export{w as n,q as t};
