import{a as g}from"./chunk-VDYEJOPW.js";import{v as P}from"./chunk-POWTZQEB.js";import"./chunk-AZNUVYH2.js";import"./chunk-4SQIPONB.js";import"./chunk-OMYRNWA7.js";import"./chunk-DQZNL7BK.js";import{a as v}from"./chunk-BAEZMG5T.js";import{a as y}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"./chunk-RYV2RH4B.js";import"./chunk-CV2ZWZQE.js";import"./chunk-R2UR7BVM.js";import{q as f}from"./chunk-HKLJ6VPZ.js";import"./chunk-MQ46LYK7.js";import"./chunk-PQ5Q7HJL.js";import"./chunk-72CHOCZD.js";import{Eb as u,Fb as h,G as o,Gb as c,N as l,O as d,Ua as p,Y as s,f as r,gb as m,tb as n}from"./chunk-56X5LYJH.js";import"./chunk-TSRGIXR5.js";var F=class a{actionType="add";destroy$=new r;loading=!0;roleId=null;submitBtnTitle="save";readOnly=!0;title="addNewPermission";detail;put=!1;permissionsEndPoint="role";addPermissionsFields=[];route=s(f);apiService=s(y);permissionFormService=s(g);ngOnInit(){this.getPageType()}ngOnDestroy(){this.destroy$.next(),this.destroy$.complete()}getPageType(){let i=this.route.snapshot.routeConfig?.path;i?.startsWith("add")?(this.actionType="add",this.readOnly=!1,this.put=!1,this.title="addNewPermission",this.submitBtnTitle="save",this.loadPermissions()):(i?.startsWith("update")||i?.startsWith("showUserPermission"))&&(this.actionType=i?.startsWith("update")?"update":"show",this.roleId=this.route.snapshot.paramMap.get("id"),this.readOnly=this.actionType==="show",this.put=this.actionType==="update",this.permissionsEndPoint=i?.startsWith("update")?`role/${this.roleId}`:"role",this.submitBtnTitle=this.actionType==="update"?"update":"",this.title=this.actionType==="update"?"updatePermission":"showUserPermission",this.loadPermissionsAndDetail())}buildBaseFormFields(){this.addPermissionsFields=[{type:"input",controlName:"name",title:"permission_name"},{type:"select",controlName:"facility_id",title:"facilities",options:[],optionsUrl:"facilities"}]}loadPermissions(){this.loading=!0,this.buildBaseFormFields(),this.permissionFormService.loadPermissionsAsAccordion().pipe(o(()=>this.loading=!1)).subscribe(i=>{this.addPermissionsFields.push(...i)})}loadPermissionsAndDetail(){this.roleId&&(this.loading=!1,this.buildBaseFormFields(),this.permissionFormService.loadPermissionsAsAccordionWithID(Number(this.roleId)).pipe(l(i=>(this.addPermissionsFields=[...this.addPermissionsFields,...i],this.apiService.GetById("role",this.roleId))),o(()=>this.loading=!0),d(this.destroy$)).subscribe({next:i=>{this.detail=this.handleRoleToForm(i.data)},error:i=>console.error("Error loading role data",i)}))}handleRoleToForm(i){return{facility_id:i.facility_id,name:i.name,permissions_ids:i.permissions.map(t=>t.id)}}static \u0275fac=function(t){return new(t||a)};static \u0275cmp=m({type:a,selectors:[["app-single-manual-permission-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(t,e){t&1&&(u(0,"div",0),c(1,"app-main-form",1),h()),t&2&&(n("isReady",e.loading),p(),n("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:[v,P],encapsulation:2})};export{F as SingleManualPermissionActionsComponent};
