import{r as h}from"./index-BP8_t0zE.js";import{w,b,A as y}from"./defaultI18nProvider-C_r1y4tu.js";import{f as I,a as D,b as O,c as W,d as g}from"./Button-C3j8Wgdd.js";import{u as m,a as p}from"./useLogout-DAYYFX4P.js";var P=function(n,d,r,s){function o(t){return t instanceof r?t:new r(function(a){a(t)})}return new(r||(r=Promise))(function(t,a){function c(u){try{e(s.next(u))}catch(f){a(f)}}function i(u){try{e(s.throw(u))}catch(f){a(f)}}function e(u){u.done?t(u.value):o(u.value).then(c,i)}e((s=s.apply(n,d||[])).next())})},_=function(n,d){var r={label:0,sent:function(){if(t[0]&1)throw t[1];return t[1]},trys:[],ops:[]},s,o,t,a;return a={next:c(0),throw:c(1),return:c(2)},typeof Symbol=="function"&&(a[Symbol.iterator]=function(){return this}),a;function c(e){return function(u){return i([e,u])}}function i(e){if(s)throw new TypeError("Generator is already executing.");for(;a&&(a=0,e[0]&&(r=0)),r;)try{if(s=1,o&&(t=e[0]&2?o.return:e[0]?o.throw||((t=o.return)&&t.call(o),0):o.next)&&!(t=t.call(o,e[1])).done)return t;switch(o=0,t&&(e=[e[0]&2,t.value]),e[0]){case 0:case 1:t=e;break;case 4:return r.label++,{value:e[1],done:!1};case 5:r.label++,o=e[1],e=[0];continue;case 7:e=r.ops.pop(),r.trys.pop();continue;default:if(t=r.trys,!(t=t.length>0&&t[t.length-1])&&(e[0]===6||e[0]===2)){r=0;continue}if(e[0]===3&&(!t||e[1]>t[0]&&e[1]<t[3])){r.label=e[1];break}if(e[0]===6&&r.label<t[1]){r.label=t[1],t=e;break}if(t&&r.label<t[2]){r.label=t[2],r.ops.push(e);break}t[2]&&r.ops.pop(),r.trys.pop();continue}e=d.call(n,r)}catch(u){e=[6,u],o=0}finally{s=t=0}if(e[0]&5)throw e[1];return{value:e[0]?e[1]:void 0,done:!0}}},l,T=function(){var n=m(),d=p(),r=w(),s=b(),o=h.useCallback(function(t){return n?n.checkError(t).then(function(){return!1}).catch(function(a){return P(void 0,void 0,void 0,function(){var c,i,e,u;return _(this,function(f){return c=(u=a==null?void 0:a.logoutUser)!==null&&u!==void 0?u:!0,l?[2,!0]:(l=setTimeout(function(){l=void 0},0),i=a&&a.redirectTo!=null?a.redirectTo:t&&t.redirectTo?t.redirectTo:void 0,e=!(a&&a.message===!1||t&&t.message===!1||i!=null&&i.startsWith("http")),e&&n.checkAuth({}).then(function(){c?r(v(a,"ra.notification.logged_out"),{type:"error"}):r(v(a,"ra.notification.not_authorized"),{type:"error"})}).catch(function(){}),c?d({},i):i.startsWith("http")?window.location.href=i:s(i),[2,!0])})})}):A()},[n,d,r,s]);return o},A=function(){return Promise.resolve(!1)},v=function(n,d){return typeof n=="string"?n:typeof n>"u"||!n.message?d:n.message},k=["getList","getMany","getManyReference"],M=function(){var n=h.useContext(y)||g,d=T(),r=h.useMemo(function(){return new Proxy(n,{get:function(s,o){if(!(typeof o=="symbol"||o==="then"))return o==="supportAbortSignal"?n.supportAbortSignal:function(){for(var t=[],a=0;a<arguments.length;a++)t[a]=arguments[a];var c=o.toString();if(typeof n[c]!="function")throw new Error("Unknown dataProvider function: ".concat(c));try{return n[c].apply(n,t).then(function(i){return i}).catch(function(i){return d(i).then(function(e){if(e)return{data:k.includes(c)?[]:{}};throw i})})}catch{throw new Error("The dataProvider threw an error. It should return a rejected Promise instead.")}}}})},[n,d]);return r};export{T as a,M as u};
