import{y as M,o as W,p as g}from"./defaultI18nProvider-C_r1y4tu.js";import{r as f}from"./index-BP8_t0zE.js";import{u as $}from"./useQuery-DJhJ3Hj4.js";import{u as X}from"./useDataProvider-BTi1EEZL.js";function j(e,r){return e===r?e!==0||r!==0||1/e===1/r:e!==e&&r!==r}var x=function(e,r){if(j(e,r))return!0;if(typeof e!="object"||e===null||typeof r!="object"||r===null)return!1;var n=Object.keys(e),a=Object.keys(r);if(n.length!==a.length)return!1;for(var t=0;t<n.length;t++)if(!Object.prototype.hasOwnProperty.call(r,n[t])||!j(e[n[t]],r[n[t]]))return!1;return!0},v=function(){return v=Object.assign||function(e){for(var r,n=1,a=arguments.length;n<a;n++){r=arguments[n];for(var t in r)Object.prototype.hasOwnProperty.call(r,t)&&(e[t]=r[t])}return e},v.apply(this,arguments)},z=function(e){return e&&Object.prototype.toString.call(e)==="[object Object]"},J=function(e){return e instanceof Date?!1:e===""||e===null||e===void 0||x(e,{})},D=function(e){return Object.keys(e).reduce(function(r,n){var a,t=e[n];return z(e[n])&&(t=D(e[n])),J(t)?r:v(v({},r),(a={},a[n]=t,a))},{})},w=function(e,r){return Object.keys(e).reduce(function(n,a){var t;return a!==r?Object.assign({},n,(t={},t[a]=e[a],t)):n},{})},A=function(e,r){var n,a=r.split(".");if(a.length===1)return w(e,r);var t=a[0];if(e[t]===void 0)return e;var l=A(e[t],a.slice(1).join("."));return Object.keys(l).length===0?w(e,t):Object.assign({},e,(n={},n[t]=l,n))},i=function(){return i=Object.assign||function(e){for(var r,n=1,a=arguments.length;n<a;n++){r=arguments[n];for(var t in r)Object.prototype.hasOwnProperty.call(r,t)&&(e[t]=r[t])}return e},i.apply(this,arguments)},U="SET_SORT",q="ASC",C="DESC",Y="SET_PAGE",Z="SET_PER_PAGE",B="SET_FILTER",ee="SHOW_FILTER",re="HIDE_FILTER",ne=function(e){return e===C?q:C},de=function(e,r){var n,a;switch(r.type){case U:return r.payload.field===e.sort?i(i({},e),{order:(a=r.payload.order)!==null&&a!==void 0?a:ne(e.order),page:1}):i(i({},e),{sort:r.payload.field,order:r.payload.order||q,page:1});case Y:return i(i({},e),{page:r.payload});case Z:return i(i({},e),{page:1,perPage:r.payload});case B:return i(i({},e),{page:1,filter:r.payload.filter,displayedFilters:r.payload.displayedFilters?r.payload.displayedFilters:e.displayedFilters});case ee:return e.displayedFilters&&e.displayedFilters[r.payload.filterName]?e:i(i({},e),{filter:typeof r.payload.defaultValue<"u"?M(e.filter,r.payload.filterName,r.payload.defaultValue):e.filter,displayedFilters:i(i({},e.displayedFilters),(n={},n[r.payload.filterName]=!0,n))});case re:return i(i({},e),{filter:D(A(e.filter,r.payload)),displayedFilters:e.displayedFilters?Object.keys(e.displayedFilters).reduce(function(t,l){var s;return l!==r.payload?i(i({},t),(s={},s[l]=!0,s)):t},{}):e.displayedFilters});default:return e}},p=function(){return p=Object.assign||function(e){for(var r,n=1,a=arguments.length;n<a;n++){r=arguments[n];for(var t in r)Object.prototype.hasOwnProperty.call(r,t)&&(e[t]=r[t])}return e},p.apply(this,arguments)},te=function(e,r){var n={};for(var a in e)Object.prototype.hasOwnProperty.call(e,a)&&r.indexOf(a)<0&&(n[a]=e[a]);if(e!=null&&typeof Object.getOwnPropertySymbols=="function")for(var t=0,a=Object.getOwnPropertySymbols(e);t<a.length;t++)r.indexOf(a[t])<0&&Object.prototype.propertyIsEnumerable.call(e,a[t])&&(n[a[t]]=e[a[t]]);return n},ae=100,se=function(e,r,n){r===void 0&&(r={}),n===void 0&&(n={});var a=r.pagination,t=a===void 0?{page:1,perPage:25}:a,l=r.sort,s=l===void 0?{field:"id",order:"DESC"}:l,_=r.filter,O=_===void 0?{}:_,o=r.meta,m=X(),h=W(),F=n.onError,H=F===void 0?E:F,T=n.onSuccess,G=T===void 0?E:T,P=n.onSettled,K=P===void 0?E:P,N=te(n,["onError","onSuccess","onSettled"]),b=g(G),R=g(H),S=g(K),u=$(p({queryKey:[e,"getList",{pagination:t,sort:s,filter:O,meta:o}],queryFn:function(c){return m.getList(e,{pagination:t,sort:s,filter:O,meta:o,signal:m.supportAbortSignal===!0?c.signal:void 0}).then(function(d){var y=d.data,V=d.total,k=d.pageInfo,Q=d.meta;return{data:y,total:V,pageInfo:k,meta:Q}})}},N)),I=f.useRef(o),L=f.useRef(e);return f.useEffect(function(){I.current=o},[o]),f.useEffect(function(){L.current=e},[e]),f.useEffect(function(){var c;u.data===void 0||u.error!=null||u.isFetching||(!((c=u.data)===null||c===void 0)&&c.data&&u.data.data.length<=ae&&u.data.data.forEach(function(d){h.setQueryData([L.current,"getOne",{id:String(d.id),meta:I.current}],function(y){return y??d})}),b(u.data))},[b,h,u.data,u.error,u.isFetching]),f.useEffect(function(){u.error==null||u.isFetching||R(u.error)},[R,u.error,u.isFetching]),f.useEffect(function(){u.status==="pending"||u.isFetching||S(u.data,u.error)},[S,u.data,u.error,u.status,u.isFetching]),f.useMemo(function(){return u.data?p(p({},u),u.data):u},[u])},E=function(){};export{re as H,q as S,C as a,Y as b,U as c,Z as d,B as e,ee as f,de as q,D as r,x as s,se as u};
