import{u as w}from"./useResourceDefinitionContext-mEDLreK0.js";import{h as P,p as j,s as x}from"./colorManipulator-DXmmM2jC.js";import{u as A}from"./Button-C3j8Wgdd.js";import{r as f}from"./index-BP8_t0zE.js";import{u as F}from"./useQuery-DJhJ3Hj4.js";import{u as O,a as D,d as k}from"./useLogout-DAYYFX4P.js";import{q as z,w as L,p as m,ah as R}from"./defaultI18nProvider-C_r1y4tu.js";var T=function(){return w().definitions},H=function(){var e=A(),o=T();return function(r,t){t===void 0&&(t=2);var a=o[r],c=e("resources.".concat(r,".name"),{smart_count:t,_:a&&a.options&&a.options.label?e(a.options.label,{smart_count:t,_:a.options.label}):P(t>1?j(r):x(r))});return c}},u=function(){return u=Object.assign||function(e){for(var o,r=1,t=arguments.length;r<t;r++){o=arguments[r];for(var a in o)Object.prototype.hasOwnProperty.call(o,a)&&(e[a]=o[a])}return e},u.apply(this,arguments)},M=function(e,o){var r={};for(var t in e)Object.prototype.hasOwnProperty.call(e,t)&&o.indexOf(t)<0&&(r[t]=e[t]);if(e!=null&&typeof Object.getOwnPropertySymbols=="function")for(var a=0,t=Object.getOwnPropertySymbols(e);a<t.length;a++)o.indexOf(t[a])<0&&Object.prototype.propertyIsEnumerable.call(e,t[a])&&(r[t[a]]=e[t[a]]);return r},_={},J=function(e,o,r){e===void 0&&(e=_),o===void 0&&(o=!1),r===void 0&&(r=_);var t=O(),a=D(),c=z(),E=L(),l=r.onSuccess,v=r.onError,d=r.onSettled,S=M(r,["onSuccess","onError","onSettled"]),n=F(u({queryKey:["auth","checkAuth",e],queryFn:function(i){var h=i.signal;return t?t.checkAuth(u(u({},e),{signal:h})).then(function(){return!0}).catch(function(s){throw s??new Error}):!0},retry:!1},S)),g=m(l??b),p=m(d??b),y=m(v??function(i){var h=R("".concat(c,"/").concat(k.loginUrl));if(o){a({},i&&i.redirectTo!=null?i.redirectTo:h);var s=i&&i.message===!1;!s&&E(U(i,"ra.auth.auth_check_error"),{type:"error"})}});return f.useEffect(function(){n.data===void 0||n.isFetching||g(n.data)},[g,n.data,n.isFetching]),f.useEffect(function(){n.error==null||n.isFetching||y(n.error)},[y,n.error,n.isFetching]),f.useEffect(function(){n.status==="pending"||n.isFetching||p(n.data,n.error)},[p,n.data,n.error,n.status,n.isFetching]),f.useMemo(function(){var i;return u(u({},n),{authenticated:((i=n.data)!==null&&i!==void 0?i:n.isLoading)?!0:t==null})},[t,n])},U=function(e,o){return typeof e=="string"?e:typeof e>"u"||!e.message?o:e.message},b=function(){};export{J as a,H as b,T as u};
