var x=i=>{throw TypeError(i)};var C=(i,t,s)=>t.has(i)||x("Cannot "+s);var e=(i,t,s)=>(C(i,t,"read from private field"),s?s.call(i):t.get(i)),b=(i,t,s)=>t.has(i)?x("Cannot add the same private member more than once"):t instanceof WeakSet?t.add(i):t.set(i,s),p=(i,t,s,r)=>(C(i,t,"write to private field"),r?r.call(i,s):t.set(i,s),s),m=(i,t,s)=>(C(i,t,"access private method"),s);import{a3 as U,a4 as k,a5 as w,a6 as q,a7 as R,h as L,r as f,a8 as j,a9 as A}from"./index-D5aSL5Lk.js";var n,l,h,o,a,g,M,K,D=(K=class extends U{constructor(t,s){super();b(this,a);b(this,n);b(this,l);b(this,h);b(this,o);p(this,n,t),this.setOptions(s),this.bindMethods(),m(this,a,g).call(this)}bindMethods(){this.mutate=this.mutate.bind(this),this.reset=this.reset.bind(this)}setOptions(t){var r;const s=this.options;this.options=e(this,n).defaultMutationOptions(t),k(this.options,s)||e(this,n).getMutationCache().notify({type:"observerOptionsUpdated",mutation:e(this,h),observer:this}),s!=null&&s.mutationKey&&this.options.mutationKey&&w(s.mutationKey)!==w(this.options.mutationKey)?this.reset():((r=e(this,h))==null?void 0:r.state.status)==="pending"&&e(this,h).setOptions(this.options)}onUnsubscribe(){var t;this.hasListeners()||(t=e(this,h))==null||t.removeObserver(this)}onMutationUpdate(t){m(this,a,g).call(this),m(this,a,M).call(this,t)}getCurrentResult(){return e(this,l)}reset(){var t;(t=e(this,h))==null||t.removeObserver(this),p(this,h,void 0),m(this,a,g).call(this),m(this,a,M).call(this)}mutate(t,s){var r;return p(this,o,s),(r=e(this,h))==null||r.removeObserver(this),p(this,h,e(this,n).getMutationCache().build(e(this,n),this.options)),e(this,h).addObserver(this),e(this,h).execute(t)}},n=new WeakMap,l=new WeakMap,h=new WeakMap,o=new WeakMap,a=new WeakSet,g=function(){var s;const t=((s=e(this,h))==null?void 0:s.state)??q();p(this,l,{...t,isPending:t.status==="pending",isSuccess:t.status==="success",isError:t.status==="error",isIdle:t.status==="idle",mutate:this.mutate,reset:this.reset})},M=function(t){R.batch(()=>{var s,r,u,v,c,y,E,S;if(e(this,o)&&this.hasListeners()){const d=e(this,l).variables,O=e(this,l).context;(t==null?void 0:t.type)==="success"?((r=(s=e(this,o)).onSuccess)==null||r.call(s,t.data,d,O),(v=(u=e(this,o)).onSettled)==null||v.call(u,t.data,null,d,O)):(t==null?void 0:t.type)==="error"&&((y=(c=e(this,o)).onError)==null||y.call(c,t.error,d,O),(S=(E=e(this,o)).onSettled)==null||S.call(E,void 0,t.error,d,O))}this.listeners.forEach(d=>{d(e(this,l))})})},K);function Q(i,t){const s=L(),[r]=f.useState(()=>new D(s,i));f.useEffect(()=>{r.setOptions(i)},[r,i]);const u=f.useSyncExternalStore(f.useCallback(c=>r.subscribe(R.batchCalls(c)),[r]),()=>r.getCurrentResult(),()=>r.getCurrentResult()),v=f.useCallback((c,y)=>{r.mutate(c,y).catch(j)},[r]);if(u.error&&A(r.options.throwOnError,[u.error]))throw u.error;return{...u,mutate:v,mutateAsync:u.mutate}}export{Q as u};