import{a as T}from"./chunk-VDYEJOPW.js";import{v as b}from"./chunk-POWTZQEB.js";import"./chunk-AZNUVYH2.js";import"./chunk-4SQIPONB.js";import"./chunk-OMYRNWA7.js";import"./chunk-DQZNL7BK.js";import{a as F}from"./chunk-BAEZMG5T.js";import{a as g}from"./chunk-C72E7DYO.js";import"./chunk-WIPHIZE3.js";import"./chunk-LXYD2H4H.js";import"./chunk-IEDTWYT7.js";import"./chunk-TMA5MVRB.js";import"./chunk-VRBUVT76.js";import"./chunk-VUFRXBL5.js";import"./chunk-AG5UR6GS.js";import"./chunk-XXT62TCF.js";import"./chunk-YUC4NXDM.js";import"./chunk-6P3ZDNP3.js";import"./chunk-VP22RGQG.js";import"./chunk-3FDFNYAA.js";import"./chunk-3HDMTDNY.js";import"./chunk-YR6PJKN6.js";import"./chunk-HVO2LBIZ.js";import"./chunk-JU53QNJX.js";import"./chunk-EMJJQSXR.js";import"./chunk-2G4GCCRX.js";import"./chunk-KAJE4RE3.js";import"./chunk-H6QVTBMZ.js";import"./chunk-XNR6WIGX.js";import"./chunk-5KOP4ULD.js";import"./chunk-F2X3VGZZ.js";import{d}from"./chunk-RYV2RH4B.js";import"./chunk-CV2ZWZQE.js";import"./chunk-R2UR7BVM.js";import{q as v}from"./chunk-HKLJ6VPZ.js";import"./chunk-MQ46LYK7.js";import"./chunk-PQ5Q7HJL.js";import"./chunk-72CHOCZD.js";import{Eb as c,Fb as y,G as n,Gb as P,O as u,Ua as h,Y as t,f as m,gb as f,tb as l}from"./chunk-56X5LYJH.js";import{a,b as r}from"./chunk-TSRGIXR5.js";var A=class p{actionType="add";destroy$=new m;loading=!0;userId;submitBtnTitle="save";readOnly=!0;title="addNewPermission";detail;put=!1;permissionsEndPoint="role";addPermissionsFields=[];route=t(v);_apiService=t(g);permissionFormService=t(T);ngOnInit(){this.getPageType(),this.buildFormFields()}getPageType(){let i=this.route.snapshot.routeConfig?.path;i?.startsWith("add")?(this.actionType="add",this.submitBtnTitle="save",this.readOnly=!1,this.title="addNewPermission",this.put=!1,this.permissionsEndPoint="role"):i?.startsWith("update")?(this.actionType="update",this.userId=this.route.snapshot.paramMap.get("id"),this.submitBtnTitle="update",this.permissionsEndPoint="role/"+this.userId,this.readOnly=!1,this.put=!0,this.title="updatePermision",this.loadDetail()):i?.startsWith("showUserPermission")&&(this.actionType="show",this.userId=this.route.snapshot.paramMap.get("id"),this.submitBtnTitle="",this.readOnly=!0,this.title="showUserPermission",this.loadDetail())}buildFormFields(){this.addPermissionsFields=[{type:"input",controlName:"name",title:"permission_name",validators:[d.required]},{type:"select",options:[],optionsUrl:"facilities",controlName:"facility_id",title:"facilities",validators:[d.required]}],this.loadPermissions()}loadPermissions(){this.loading=!1,this.permissionFormService.loadPermissionsAsAccordion().pipe(n(()=>this.loading=!0)).subscribe(i=>{this.addPermissionsFields=[...this.addPermissionsFields,...i]})}loadDetail(){this.userId&&(this.loading=!1,this._apiService.GetById("permission",this.userId).pipe(u(this.destroy$),n(()=>this.loading=!0)).subscribe({next:i=>{if(i.facilities&&Array.isArray(i.facilities)){let s=i.facilities.map(e=>r(a({},e),{permissions:(e.permissions??[]).map(o=>o.id),roles:(e.roles??[]).map(o=>o.id)}));this.detail=r(a({},i),{facilities:s})}},error:i=>{console.error("Error fetching user permission details",i)}}))}static \u0275fac=function(s){return new(s||p)};static \u0275cmp=f({type:p,selectors:[["app-manual-permissions-actions"]],decls:2,vars:11,consts:[["appShowLoaderUntilPageLoaded","",3,"isReady"],["translationPrefix","manualPermissions","routeAfterSuccess","/home/permissions/all","fileNameTranslated","shared",3,"titleOfPage","readOnly","fields","ApplySubTranslationprefixTitle","Put","url","formValues","titleOfButton","ApplyTranslationprefix","useMethodPut"]],template:function(s,e){s&1&&(c(0,"div",0),P(1,"app-main-form",1),y()),s&2&&(l("isReady",e.loading),h(),l("titleOfPage",e.title)("readOnly",e.readOnly)("fields",e.addPermissionsFields)("ApplySubTranslationprefixTitle",!1)("Put",e.put)("url",e.permissionsEndPoint)("formValues",e.detail)("titleOfButton",e.submitBtnTitle)("ApplyTranslationprefix",!0)("useMethodPut",!0))},dependencies:[b,F],encapsulation:2})};export{A as ManualPermissionsActionsComponent};
