import{r as m}from"./index-BP8_t0zE.js";import{o as j,p as q}from"./defaultI18nProvider-C_r1y4tu.js";import{u as Q}from"./useMutation-DBpLFNEy.js";import{u as R}from"./useDataProvider-BTi1EEZL.js";var c=function(){return c=Object.assign||function(u){for(var o,e=1,t=arguments.length;e<t;e++){o=arguments[e];for(var n in o)Object.prototype.hasOwnProperty.call(o,n)&&(u[n]=o[n])}return u},c.apply(this,arguments)},E=function(u,o){var e={};for(var t in u)Object.prototype.hasOwnProperty.call(u,t)&&o.indexOf(t)<0&&(e[t]=u[t]);if(u!=null&&typeof Object.getOwnPropertySymbols=="function")for(var n=0,t=Object.getOwnPropertySymbols(u);n<t.length;n++)o.indexOf(t[n])<0&&Object.prototype.propertyIsEnumerable.call(u,t[n])&&(e[t[n]]=u[t[n]]);return e},W=function(u,o,e){o===void 0&&(o={}),e===void 0&&(e={});var t=R(),n=j(),g=m.useRef(o),h=m.useRef(!1),O=m.useRef(!1),S=m.useRef(!1),_=e.getMutateWithMiddlewares,b=E(e,["getMutateWithMiddlewares"]),v=Q(c(c({mutationFn:function(a){var r=a===void 0?{}:a,i=r.resource,f=i===void 0?u:i,d=r.data,s=d===void 0?g.current.data:d,w=r.meta,M=w===void 0?g.current.meta:w;if(!f)throw new Error("useCreate mutation requires a non-empty resource");if(!s)throw new Error("useCreate mutation requires a non-empty data object");if(_){var P=_(t.create.bind(t));return P(f,{data:s,meta:M}).then(function(y){var l=y.data;return l})}return t.create(f,{data:s,meta:M}).then(function(y){var l=y.data;return l})}},b),{onError:function(a,r,i){if(e.onError&&!h.current)return e.onError(a,r,i)},onSuccess:function(a,r,i){r===void 0&&(r={});var f=r.resource,d=f===void 0?u:f;n.setQueryData([d,"getOne",{id:String(a.id)}],a),n.invalidateQueries({queryKey:[d,"getList"]}),n.invalidateQueries({queryKey:[d,"getInfiniteList"]}),n.invalidateQueries({queryKey:[d,"getMany"]}),n.invalidateQueries({queryKey:[d,"getManyReference"]}),e.onSuccess&&!O.current&&e.onSuccess(a,r,i)},onSettled:function(a,r,i,f){if(e.onSettled&&!S.current)return e.onSettled(a,r,i,f)}})),C=function(a,r,i){a===void 0&&(a=u),r===void 0&&(r={}),i===void 0&&(i={});var f=i.returnPromise,d=f===void 0?e.returnPromise:f,s=E(i,["returnPromise"]);return h.current=!!s.onError,O.current=!!s.onSuccess,S.current=!!s.onSettled,d?v.mutateAsync(c({resource:a},r),s):v.mutate(c({resource:a},r),s)},p=m.useMemo(function(){return c({isLoading:v.isPending},v)},[v]);return[q(C),p]};export{W as u};
