import{Gi as e,Jt as t,Xt as n,Yt as r,ln as i}from"./forms-CL2ODv4X.js";var a=function(){function a(t){this.options=e({},t.defaultOptions,t.options),this.mutationId=t.mutationId,this.mutationCache=t.mutationCache,this.observers=[],this.state=t.state||o(),this.meta=t.meta}var c=a.prototype;return c.setState=function(e){this.dispatch({type:`setState`,state:e})},c.addObserver=function(e){this.observers.indexOf(e)===-1&&this.observers.push(e)},c.removeObserver=function(e){this.observers=this.observers.filter(function(t){return t!==e})},c.cancel=function(){return this.retryer?(this.retryer.cancel(),this.retryer.promise.then(i).catch(i)):Promise.resolve()},c.continue=function(){return this.retryer?(this.retryer.continue(),this.retryer.promise):this.execute()},c.execute=function(){var e=this,n,r=this.state.status===`loading`,i=Promise.resolve();return r||(this.dispatch({type:`loading`,variables:this.options.variables}),i=i.then(function(){e.mutationCache.config.onMutate==null||e.mutationCache.config.onMutate(e.state.variables,e)}).then(function(){return e.options.onMutate==null?void 0:e.options.onMutate(e.state.variables)}).then(function(t){t!==e.state.context&&e.dispatch({type:`loading`,context:t,variables:e.state.variables})})),i.then(function(){return e.executeMutation()}).then(function(t){n=t,e.mutationCache.config.onSuccess==null||e.mutationCache.config.onSuccess(n,e.state.variables,e.state.context,e)}).then(function(){return e.options.onSuccess==null?void 0:e.options.onSuccess(n,e.state.variables,e.state.context)}).then(function(){return e.options.onSettled==null?void 0:e.options.onSettled(n,null,e.state.variables,e.state.context)}).then(function(){return e.dispatch({type:`success`,data:n}),n}).catch(function(n){return e.mutationCache.config.onError==null||e.mutationCache.config.onError(n,e.state.variables,e.state.context,e),t().error(n),Promise.resolve().then(function(){return e.options.onError==null?void 0:e.options.onError(n,e.state.variables,e.state.context)}).then(function(){return e.options.onSettled==null?void 0:e.options.onSettled(void 0,n,e.state.variables,e.state.context)}).then(function(){throw e.dispatch({type:`error`,error:n}),n})})},c.executeMutation=function(){var e=this;return this.retryer=new n({fn:function(){return e.options.mutationFn?e.options.mutationFn(e.state.variables):Promise.reject(`No mutationFn found`)},onFail:function(){e.dispatch({type:`failed`})},onPause:function(){e.dispatch({type:`pause`})},onContinue:function(){e.dispatch({type:`continue`})},retry:this.options.retry??0,retryDelay:this.options.retryDelay}),this.retryer.promise},c.dispatch=function(e){var t=this;this.state=s(this.state,e),r.batch(function(){t.observers.forEach(function(t){t.onMutationUpdate(e)}),t.mutationCache.notify(t)})},a}();function o(){return{context:void 0,data:void 0,error:null,failureCount:0,isPaused:!1,status:`idle`,variables:void 0}}function s(t,n){switch(n.type){case`failed`:return e({},t,{failureCount:t.failureCount+1});case`pause`:return e({},t,{isPaused:!0});case`continue`:return e({},t,{isPaused:!1});case`loading`:return e({},t,{context:n.context,data:void 0,error:null,isPaused:!1,status:`loading`,variables:n.variables});case`success`:return e({},t,{data:n.data,error:null,status:`success`,isPaused:!1});case`error`:return e({},t,{data:void 0,error:n.error,failureCount:t.failureCount+1,isPaused:!1,status:`error`});case`setState`:return e({},t,n.state);default:return t}}export{o as n,a as t};