import{d as O}from"./chunk-7EAWKBIV.js";import{$b as n,Hc as u,I as p,Ic as M,_b as v,fd as E,na as d,rd as N}from"./chunk-ATD4AEXQ.js";import{Qc as f,Y as S,_c as j,ca as l,fa as a,g as b,gd as g,l as h}from"./chunk-BXH3QC5E.js";var y=(()=>{class r{restService;constructor(e){this.restService=e}getMenus(e,t){let i=new f;return i=i.append("userGroupID",e),i=i.append("plantID",t),this.restService.get(p.MENUS,i)}getMenuGroupsAndItems(e,t){let i=new f;return i=i.append("userGroupID",t),this.restService.get(`${p.MENUS}/menuID:${e}`,i)}getReadonlyDialogsV10(e,t){let i=new f;return i=i.append("menuIDs",e.toString()),i=i.append("userGroupID",t),this.restService.get(`${p.MENU_ITEMS}`,i)}static \u0275fac=function(t){return new(t||r)(a(O))};static \u0275prov=l({token:r,factory:r.\u0275fac,providedIn:"root"})}return r})();var T=(()=>{class r{menusService;constructor(e){this.menusService=e}getMenus(e,t){return this.menusService.getMenus(e,t)}getMenuGroupsAndItems(e,t){return this.menusService.getMenuGroupsAndItems(e,t)}getReadOnlyDialogsV10(e,t){return this.menusService.getReadonlyDialogsV10(e,t)}static \u0275fac=function(t){return new(t||r)(a(y))};static \u0275prov=l({token:r,factory:r.\u0275fac,providedIn:"root"})}return r})();var I=(()=>{class r{menusFacade;router;dialogTilesService;toastMessageService;translateService;menusListSubject=new h([]);selectedMenuSubject=new h(null);menusList$=this.menusListSubject.asObservable();selectedMenu$=this.selectedMenuSubject.asObservable();menuIDs;constructor(e,t,i,o,s){this.menusFacade=e,this.router=t,this.dialogTilesService=i,this.toastMessageService=o,this.translateService=s}loadMenusOnResolver(e,t){return new Promise((i,o)=>this.menusFacade.getMenus(e,t).pipe(S(s=>(this.menusListSubject.next(s),this.fillDefaultMenuOnSessionIfEmpty(s),this.menuIDs=s.map(m=>m.id),this.menusFacade.getReadOnlyDialogsV10(this.menuIDs,e))),S(s=>(this.dialogTilesService.fillReadOnlyInfoDialogs(this.menuIDs,s),n.isNullOrUndefinedOrEmpty(u.getSelectedMenuID())?this.menusFacade.getMenuGroupsAndItems(this.getDefaultMenu().id,e):this.menusFacade.getMenuGroupsAndItems(Number(u.getSelectedMenuID()),e)))).subscribe({next:s=>{this.showNoMenuGroupDefinedError(s);let m=u.getSelectedMenuID(),c;n.isNullOrUndefinedOrEmpty(m)?c=this.getDefaultMenu():c=this.menusListSubject.value.find(U=>U.id.toString()===m),n.isNullOrUndefined(c)||(c.menuGroups=s,this.selectedMenuSubject.next(c),u.setSelectedMenuID(c.id)),i(this.menusListSubject.value)},error:s=>{o(s)}}))}loadMenuGroupsAndItems(e,t){this.menusFacade.getMenuGroupsAndItems(e,t).subscribe({next:i=>{this.showNoMenuGroupDefinedError(i),Number(u.getSelectedMenuID())!==e&&u.setSelectedMenuID(e);let o=this.menusListSubject.value.find(s=>s.id===Number(u.getSelectedMenuID()));o.menuGroups=i,this.router.navigate([d.Dashboard.path],{state:{bypassBackNavigationGuard:!0}}).then(()=>{this.selectedMenuSubject.next(o)}).catch(n.EMPTY_REJECTION_HANDLER)}})}getDefaultMenu(){return this.menusListSubject.value.find(e=>e.defaultMenu)}getSelectedMenu(){return this.selectedMenu$}getMenus(){return this.menusList$}fillDefaultMenuOnSessionIfEmpty(e){if(n.isNullOrUndefinedOrEmpty(u.getSelectedMenuID())){let t=e.find(o=>o.defaultMenu),i;n.isNullOrUndefined(t)?(t=e.length>0?e[0]:null,i=t!==null?t.id:-1):i=t.id,this.selectedMenuSubject.next(t),u.setSelectedMenuID(i)}}getCurrentSelectedMenuDescription(){return this.selectedMenuSubject.value?.description}showNoMenuGroupDefinedError(e){n.isNullOrEmptyArray(e)&&this.toastMessageService.showToastPanel(E.getErrorDefaultConfig().withMessage(this.translateService.instant("MSG_NO_MENU_GROUP_DEFINED")))}static \u0275fac=function(t){return new(t||r)(a(T),a(g),a(M),a(N),a(j))};static \u0275prov=l({token:r,factory:r.\u0275fac,providedIn:"root"})}return r})();var P=(()=>{class r{dialogTilesService;menusManager;router;constructor(e,t,i){this.dialogTilesService=e,this.menusManager=t,this.router=i}resolve(e,t){return b(this,null,function*(){let i=yield this.menusManager.loadMenusOnResolver(v.getSystemUser().userGroup.id,v.getBusinessUnit().plant.id);if(t.url.includes(`/${d.Dashboard.path}`))return Promise.resolve();let o=this.dialogTilesService.findDialogConfigForUrlPath(t.url),s=this.dialogTilesService.isDevDialog(t.url);return!n.isNullOrUndefined(o)&&!this.dialogTilesService.isDialogReadOnly(o.dialogCode)&&this.isMenuAvailable(o,i)||s||this.router.navigate([d.Dashboard.path]).catch(n.EMPTY_REJECTION_HANDLER),Promise.resolve()})}isMenuAvailable(e,t){return!n.isNullOrUndefined(t.find(i=>!n.isNullOrUndefined(i.menuGroups)&&!n.isNullOrUndefined(i.menuGroups.find(o=>!n.isNullOrUndefined(o.dialogs.find(s=>s.dialogCode===e.dialogCode))))))}static \u0275fac=function(t){return new(t||r)(a(M),a(I),a(g))};static \u0275prov=l({token:r,factory:r.\u0275fac,providedIn:"root"})}return r})();export{I as a,P as b};
