import{v as U}from"./chunk-POWTZQEB.js";import"./chunk-AZNUVYH2.js";import"./chunk-4SQIPONB.js";import"./chunk-OMYRNWA7.js";import"./chunk-DQZNL7BK.js";import{a as D}from"./chunk-BAEZMG5T.js";import{a as T}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 as P}from"./chunk-RYV2RH4B.js";import"./chunk-CV2ZWZQE.js";import"./chunk-R2UR7BVM.js";import{j as v,q as b}from"./chunk-HKLJ6VPZ.js";import"./chunk-MQ46LYK7.js";import"./chunk-PQ5Q7HJL.js";import"./chunk-72CHOCZD.js";import{Eb as h,Fb as y,G as u,Gb as g,O as n,Ua as c,Y as l,f as m,gb as f,tb as d}from"./chunk-56X5LYJH.js";import{a as r,b as o}from"./chunk-TSRGIXR5.js";var F=class p{actionType="add";destroy$=new m;loading=!0;userId;submitBtnTitle="save";readOnly=!1;title="addNewUser";detail=void 0;tableData;put=!1;usersEndPoint="permission";addUserFields=[];route=l(b);_apiService=l(T);ngOnInit(){this.getPageType(),this.buildFormFields()}getPageType(){let t=this.route.snapshot.routeConfig?.path;t?.startsWith("add")?(this.actionType="add",this.submitBtnTitle="save",this.readOnly=!1,this.title="addNewUser",this.put=!1,this.usersEndPoint="permission",this.loadEncryptedParentData()):t?.startsWith("update")?(this.actionType="update",this.userId=this.route.snapshot.paramMap.get("id"),this.submitBtnTitle="update",this.usersEndPoint="permission/update/"+this.userId,this.readOnly=!1,this.put=!0,this.title="updateUser",this.loadDetail()):t?.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.addUserFields=[{type:"select",options:[],optionsUrl:"employees/getAllEmployee",optionName:"full_name",controlName:"employee_id",title:"employee",validators:[P.required],note:"financialEmployeesWithoutAccount"},{type:"table",controlName:"facilities",fields:[{type:"select",options:[],optionsUrl:"facilities",title:"facility",controlName:"id",disappearFieldTitle:!0},{type:"multi-select",options:[],optionsUrl:"permission/fixed",controlName:"permissions",title:"fixed",disappearFieldTitle:!0},{type:"multi-select",options:[],optionsUrl:"permission/manual",dependsOn:"id",controlName:"roles",title:"manual",optionName:"name_role",disappearFieldTitle:!0}]},{type:"toggle",controlName:"is_active",title:"activeAccount",value:!1}]}loadDetail(){this.userId&&(this.loading=!1,this._apiService.GetById("permission",this.userId).pipe(n(this.destroy$),u(()=>this.loading=!0)).subscribe({next:t=>{let e=t.data;if(e.facilities&&Array.isArray(e.facilities)){let i=e.facilities.map(s=>o(r({},s),{id:s.id,permissions:(s.permissions??[]).map(a=>a.id),roles:(s.roles??[]).map(a=>a.id)}));this.tableData=i,this.detail=o(r({},e),{facilities:i})}},error:t=>{console.error("Error fetching user permission details",t)}}))}loadEncryptedParentData(){this.route.queryParams.pipe(n(this.destroy$)).subscribe(t=>{if(!t.state)return;let e=this.decryptData(t.state);console.log("state",e),e&&(this.detail={employee_id:e.parentId})})}decryptData(t){try{let e=t.split("").reverse().join(""),i=decodeURIComponent(atob(e));return JSON.parse(i)}catch(e){return console.error("Decryption failed:",e),null}}static \u0275fac=function(e){return new(e||p)};static \u0275cmp=f({type:p,selectors:[["app-users-actions"]],decls:2,vars:11,consts:[["appShowLoaderUntilPageLoaded","",1,"",3,"isReady"],["translationPrefix","userAndPermissions","routeAfterSuccess","/home/userAndPermissions/all","fileNameTranslated","shared",3,"titleOfPage","readOnly","fields","Put","url","formValues","titleOfButton","ApplyTranslationprefix","useMethodPut","forTableData"]],template:function(e,i){e&1&&(h(0,"div",0),g(1,"app-main-form",1),y()),e&2&&(d("isReady",i.loading),c(),d("titleOfPage",i.title)("readOnly",i.readOnly)("fields",i.addUserFields)("Put",i.put)("url",i.usersEndPoint)("formValues",i.detail)("titleOfButton",i.submitBtnTitle)("ApplyTranslationprefix",!0)("useMethodPut",!0)("forTableData",i.tableData))},dependencies:[U,D,v],encapsulation:2})};export{F as UsersActionsComponent};
