import{j as l}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 F}from"./chunk-TGWIHQDX.js";import{d as r}from"./chunk-Q5KZV54I.js";import{a as b}from"./chunk-YHVRQUSB.js";import"./chunk-3Z7PXZF3.js";import{a as S}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 C}from"./chunk-S3ADKFO2.js";import{E as _}from"./chunk-I5MYHHJE.js";import{$b as y,Fb as s,Ib as f,S as a,Wa as c,Xc as g,Zb as v,_b as h,f as p,gb as n,lb as u}from"./chunk-CKLXM6EG.js";import"./chunk-TSRGIXR5.js";var w=class m{constructor(i,t,e,o,d){this.apiService=i;this.route=t;this.translate=e;this.cdr=o;this.toast=d}title;urlApi;titleKey="";translationPrefix="payment-intervals";fullWidthFields=["select","input","date","table","radio"];values;vendors;isEdit=!1;fields;destroy$=new p;mainFormComponent;titleOfButton;isShow;ngOnInit(){this.route.paramMap.subscribe(i=>{let t=this.route.snapshot.routeConfig?.path?.includes("show");this.isShow=t,console.log(t,"isShow");let e=this.route.snapshot.paramMap.get("id");e?t?(this.getDetails(e),this.title="show-payment-interval"):(this.getDetails(e),this.isEdit=!0,this.titleOfButton="edit",this.title="edit-payment-interval",this.urlApi=`procurement/payment-interval/update/${e}`):(this.isEdit=!1,this.titleOfButton="add",this.title="add-payment-interval",this.urlApi="procurement/payment-interval/store")}),this.fields=[{type:"input",title:"name_ar_payment",class:"col-6",controlName:"name_ar",validators:[r.required]},{type:"input",title:"name_en_payment",class:"col-6",controlName:"name_en",validators:[r.required]},{type:"input",title:"number_of_days",inputType:"number",class:"col-6",controlName:"number_of_days",validators:[r.required]},{type:"radio",title:"is_active",controlName:"status",class:"col-6",options:[{name:this.translate.instant("yes"),id:1},{name:this.translate.instant("no"),id:0}],validators:[r.required],RadioDefaultValue:1},{type:"radio",title:"all_vendors",controlName:"all_vendors",class:"col-6",options:[{name:this.translate.instant("all"),id:1},{name:this.translate.instant("custom"),id:0}],validators:[r.required]},{type:"checkbox",title:"vendor_ids",controlName:"vendor_ids",class:"col-6",dependsOn:"all_vendors",dependsValue:0,options:[],optionQueryParam:"id"}]}ngAfterViewInit(){setTimeout(()=>{this.mainFormComponent?.mainForm.get("all_vendors")?.valueChanges.subscribe(t=>{if(console.log("value",t),t==0)this.getDetailsOfVendors();else{let e=this.mainFormComponent.mainForm.get("vendor_ids");e&&e.reset()}})})}getDetails(i){this.apiService.Get(`procurement/payment-interval/show/${i}`).pipe(a(this.destroy$)).subscribe({next:t=>{this.values=t.data},error:t=>{console.error("Error fetching employee:",t)}})}getDetailsOfVendors(){this.apiService.Get("procurement/public/vendor").pipe(a(this.destroy$)).subscribe({next:i=>{console.log(i.data),this.vendors=i.data;let t=i.data.map(o=>({id:o.id,name:o.name})),e=this.fields.find(o=>o.controlName==="vendor_ids");if(console.log(e),e&&(e.options=t),this.isEdit||this.isShow){let o=this.values?.vendor_ids?.map(d=>d.id);console.log(o,"ids"),this.mainFormComponent.mainForm.patchValue({vendor_ids:o})}this.cdr.detectChanges()},error:i=>{console.error("Error fetching employee:",i)}})}static \u0275fac=function(t){return new(t||m)(n(b),n(_),n(C),n(g),n(F))};static \u0275cmp=u({type:m,selectors:[["app-payment-interval-actions"]],viewQuery:function(t,e){if(t&1&&v(l,5),t&2){let o;h(o=y())&&(e.mainFormComponent=o.first)}},decls:2,vars:10,consts:[[3,"title","Translationprefix","showTitle","showBreadcrumb"],["routeAfterSuccess","/finance/payment-intervals","titleOfButton2","cancel",3,"fields","url","readOnly","formValues","fullWidthFields","titleOfButton"]],template:function(t,e){t&1&&f(0,"app-page-title",0)(1,"app-main-form",1),t&2&&(s("title",e.title)("Translationprefix",e.translationPrefix)("showTitle",!0)("showBreadcrumb",!0),c(),s("fields",e.fields)("url",e.urlApi)("readOnly",e.isShow)("formValues",e.values)("fullWidthFields",e.fullWidthFields)("titleOfButton",e.titleOfButton))},dependencies:[l,S],styles:["[_nghost-%COMP%]     .custom-checkbox-group .form-check{flex-direction:column;gap:.5rem!important}"]})};export{w as PaymentIntervalActions};
