import{j as s}from"./chunk-JBNKEIUX.js";import"./chunk-5SW267PH.js";import"./chunk-PU7DBJLZ.js";import"./chunk-3DDBG3AR.js";import"./chunk-5MLUVH77.js";import"./chunk-SMMBZMNL.js";import"./chunk-S5GA3KRV.js";import"./chunk-EFONMPAR.js";import"./chunk-YQXLYYOT.js";import"./chunk-6RITFGP2.js";import"./chunk-HGXDKXJP.js";import"./chunk-WQUXAKOL.js";import"./chunk-LYNKRDJC.js";import"./chunk-SKY4LXUD.js";import"./chunk-BZT47AWD.js";import"./chunk-5WQBRAHK.js";import"./chunk-4FTRQKHH.js";import"./chunk-TTWRMELT.js";import"./chunk-EMJ4QQUL.js";import"./chunk-QPCAJSKO.js";import"./chunk-QV67LFVX.js";import"./chunk-4O3FVBGX.js";import{b as O}from"./chunk-TGWIHQDX.js";import{d as o}from"./chunk-Q5KZV54I.js";import{a as b}from"./chunk-YHVRQUSB.js";import"./chunk-3Z7PXZF3.js";import{a as M}from"./chunk-43BLBOSI.js";import"./chunk-IWSLIKCG.js";import"./chunk-2DXJE6G7.js";import"./chunk-7RP244JU.js";import"./chunk-LHGSJXTX.js";import"./chunk-ZKNPBXGB.js";import{b as g}from"./chunk-S3ADKFO2.js";import{E as S}from"./chunk-I5MYHHJE.js";import{$b as _,Fb as l,I as c,Ib as f,S as u,Wa as h,Zb as v,_b as w,f as m,gb as r,lb as y}from"./chunk-CKLXM6EG.js";import{a as d,b as p}from"./chunk-TSRGIXR5.js";var A=class n{constructor(i,t,e,a){this.apiService=i;this.route=t;this.toast=e;this.translate=a}title;urlApi;titleKey="";mode;isEdit=!1;isShowMode=!1;translationPrefix="my-team";fullWidthFields=["select","input","date","table"];fields;titleOfButton;employee;mainFormComponent;destroy$=new m;extraPayload;ngOnInit(){this.route.paramMap.subscribe(i=>{let t=i.get("id");this.isShowMode=this.route.snapshot.routeConfig?.path?.includes("show")??!1,t?(this.getEmployeeDetails(t),this.isShowMode?(this.title="show-employee",this.urlApi=`procurement/employees/show/${t}`,this.mode="show"):(this.isEdit=!0,this.mode="edit",this.titleOfButton="edit",this.title="edit-employee",this.urlApi=`procurement/employees/update/${t}`)):(this.isEdit=!1,this.mode="add",this.titleOfButton="add",this.title="add_employee",this.urlApi="procurement/employees/create")}),this.fields=[{type:"input",title:"full_name",class:"col-6",controlName:"full_name",placeholder:"full_name",validators:[o.required],readOnly:this.isShowMode},{type:"input",class:"col-6",title:"national_id",placeholder:"national_id",controlName:"national_id",validators:[o.required],readOnly:this.isShowMode},{type:"select",class:"col-2",title:"country_code",controlName:"country_code",placeholder:"country_code",optionsUrl:"country",optionName:"phone_code",optionLabel:"name",optionQueryParam:"phone_code",options:[],validators:[o.required],readOnly:this.isShowMode},{type:"input",class:"col-4",title:"phone_number",controlName:"phone_number",placeholder:"phone_number",validators:[o.required],readOnly:this.isShowMode},{type:"input",title:"email",class:"col-6",controlName:"email",placeholder:"email",validators:[o.required,o.email,o.pattern("^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\\.[a-zA-Z]{2,}$")],readOnly:this.isShowMode},{type:"select",class:"col-6",title:"department",controlName:"department",placeholder:"department",optionsUrl:"procurement/public/departments",options:[],validators:[o.required],readOnly:this.isShowMode},{type:"input",class:"col-6",title:"position",placeholder:"position",controlName:"position",validators:[o.required],readOnly:this.isShowMode},{type:"select",title:"role",class:"col-6",controlName:"role",placeholder:"role",optionsUrl:"procurement/employees/listRoles",options:[],readOnly:this.isShowMode},{type:"input",title:"employee_code",class:"col-6",controlName:"employee_code",placeholder:"employee_code",validators:[o.required],readOnly:this.isShowMode},{type:"radio",title:"is_active",controlName:"status",validators:[o.required],readOnly:this.isShowMode,class:"col-12",RadioDefaultValue:1,options:[{name:this.translate.instant("active"),id:1},{name:this.translate.instant("inactive"),id:7},{name:this.translate.instant("stopped"),id:5}]}]}test(){console.log("test button clicked"),this.toast.success(`\u062A\u0645 \u0627\u0644\u0636\u063A\u0637 \u0639\u0644\u0649 \u0632\u0631 \u0627\u0644\u0627\u062E\u062A\u0628\u0627\u0631
\u062A\u0627\u0631\u064A\u062E \u0627\u0644\u062A\u0646\u0641\u064A\u0630: ${new Date().toISOString().slice(0,10)}`)}ngAfterViewInit(){this.mainFormComponent.mainForm.get("role").valueChanges.pipe(c(),u(this.destroy$)).subscribe(t=>{t===null&&(this.extraPayload={role:null},console.log(this.extraPayload,"extraPayload"))})}data;getEmployeeDetails(i){this.apiService.Get(`procurement/public/employees/show/${i}`).subscribe({next:t=>{let e=t.data;this.employee=p(d({},e),{phone_number:e.phone||"",country_code:e.country_code||"",department:e?.department?.id||"",role:e.role?.id||""}),this.isShowMode&&this.fields.push({type:"input",title:"created_at",class:"col-6",controlName:"created_at",readOnly:!0,value:e.created_at},{type:"input",title:"updated_at",class:"col-6",controlName:"last_update",readOnly:!0,value:e.last_update}),console.log("Mapped employee:",this.employee)},error:t=>{console.error("Error fetching employee:",t)}})}static \u0275fac=function(t){return new(t||n)(r(b),r(S),r(O),r(g))};static \u0275cmp=y({type:n,selectors:[["app-employee-actions"]],viewQuery:function(t,e){if(t&1&&v(s,5),t&2){let a;w(a=_())&&(e.mainFormComponent=a.first)}},decls:2,vars:13,consts:[[3,"title","Translationprefix","showTitle","showBreadcrumb"],["routeAfterSuccess","/my-team","titleOfButton2","delete",3,"fields","url","titleOfButton","formValues","forTableTest","readOnly","fullWidthFields","resetButtonClass","extraPayload"]],template:function(t,e){t&1&&f(0,"app-page-title",0)(1,"app-main-form",1),t&2&&(l("title",e.title)("Translationprefix",e.translationPrefix)("showTitle",!0)("showBreadcrumb",!0),h(),l("fields",e.fields)("url",e.urlApi)("titleOfButton",e.titleOfButton)("formValues",e.employee)("forTableTest",e.employee)("readOnly",e.isShowMode)("fullWidthFields",e.fullWidthFields)("resetButtonClass","reset-btn-style")("extraPayload",e.extraPayload))},dependencies:[M,s],styles:["[_nghost-%COMP%]     .reset-btn-style{width:188px;border-radius:10px;background-color:#9aa0a6;color:#fff;margin-left:10px}"]})};export{A as EmployeeActions};
