import{c as g}from"./chunk-GH7I4V3C.js";import{a as h}from"./chunk-JXRZRBWK.js";import{d,g as p,t as E}from"./chunk-2YE7XEKS.js";import{M as u,ka as f,p as a,pa as o,re as m,s as l}from"./chunk-UNHECMG2.js";var b=(()=>{class e{constructor(){this.toastService=o(h),this.translate=o(m)}notifyHttpError(t){switch(t.status){case 401:case 403:return;case 404:return this.notifyNotFound();case 0:case 503:case 504:return this.notifyUnavailable();case 409:return this.notifyConflict(t);default:return this.notifyServerError()}}notifyNoAccess(){this.notifyMessage("noaccess")}notifyNotFound(){this.notifyMessage("notfound")}notifyUnavailable(){this.notifyMessage("unavailable")}notifyServerError(){this.notifyMessage("server")}notifyConflict(t){let s=this.translate.instant("global.rest-errors.conflict-message"),i=this.parseConflictIssues(t);this.toastService.error(i.length>0?i.join(`
`):s,this.translate.instant("global.rest-errors.conflict-title"))}notifyMessage(t){this.toastService.error(this.translate.instant(`global.rest-errors.${t}-message`),this.translate.instant(`global.rest-errors.${t}-title`))}parseConflictIssues(t){return Array.isArray(t.error?.Issues)?t.error.Issues.map(s=>s?.Message).filter(g):[]}static{this.\u0275fac=function(s){return new(s||e)}}static{this.\u0275prov=f({token:e,factory:e.\u0275fac,providedIn:"root"})}}return e})();var y=new d(()=>({disableErrorHandling:!1,disableErrorHandlingForStatus:[],disableErrorHandlingExceptForStatus:[]}));function k(){return(e,n)=>{let t=e.context.get(y);return n(e).pipe(u(S(t)))}}function S(e){let n=o(E),t=o(b);return r=>{if(r instanceof p&&!(e.disableErrorHandling||s(e,r.status)||i(e,r.status)))switch(r.status){case 401:return t.notifyNoAccess(),n.navigate(["/unauthenticated"]),a;case 403:return t.notifyNoAccess(),n.navigate(["/dashboard"]),a;default:return t.notifyHttpError(r),a}return l(()=>r)};function s(r,c){return!r.disableErrorHandlingForStatus||r.disableErrorHandlingForStatus.length===0?!1:r.disableErrorHandlingForStatus.includes(c)}function i(r,c){return!r.disableErrorHandlingExceptForStatus||r.disableErrorHandlingExceptForStatus.length===0?!1:!r.disableErrorHandlingExceptForStatus.includes(c)}}export{b as a,y as b,k as c};
