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 S}from"./chunk-TGWIHQDX.js";import{d as r}from"./chunk-Q5KZV54I.js";import{a as w}from"./chunk-YHVRQUSB.js";import"./chunk-3Z7PXZF3.js";import{a as _}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}from"./chunk-S3ADKFO2.js";import{E as g}from"./chunk-I5MYHHJE.js";import{$b as v,Fb as n,Ib as m,S as s,Wa as c,Xc as y,Zb as h,_b as f,f as p,gb as a,lb as u}from"./chunk-CKLXM6EG.js";import"./chunk-TSRGIXR5.js";var O=class d{constructor(t,e,i,o,A){this.apiService=t;this.route=e;this.translate=i;this.cdr=o;this.toast=A}title;urlApi;translationPrefix="brands";fullWidthFields=["select","input","date","table","radio","textarea"];values;isEdit=!1;isShowMode=!1;fields;destroy$=new p;titleOfButton;extraPayload={remove_image:0};ngOnInit(){this.route.paramMap.subscribe(t=>{let e=t.get("id");this.isShowMode=this.route.snapshot.routeConfig?.path?.includes("show")??!1,e?(this.getDetails(e),this.isShowMode?(this.title="show-brand",this.urlApi=`procurement/brands/show/${e}`):(this.isEdit=!0,this.titleOfButton="edit",this.title="edit-brand",this.urlApi=`procurement/brands/update/${e}`)):(this.isEdit=!1,this.titleOfButton="add",this.title="add-brand",this.urlApi="procurement/brands/store")}),this.fields=[{type:"input",title:"name_ar",inputType:"text",class:"col-6",controlName:"name_ar",validators:[r.required,r.maxLength(50)],readOnly:this.isShowMode},{type:"input",title:"name_en",inputType:"text",class:"col-6",controlName:"name_en",validators:[r.required,r.maxLength(50)],readOnly:this.isShowMode},{type:"textarea",title:"description_ar",inputType:"text",class:"col-6",controlName:"description_ar",readOnly:this.isShowMode},{type:"textarea",title:"description_en",inputType:"text",class:"col-6",controlName:"description_en",readOnly:this.isShowMode},{type:"media",title:"brand_logo",class:"col-6",controlName:"logo_path",readOnly:this.isShowMode},{type:"radio",title:"active",controlName:"is_active",class:"col-6",options:[{name:this.translate.instant("yes"),id:1},{name:this.translate.instant("no"),id:0}],validators:[r.required],readOnly:this.isShowMode,RadioDefaultValue:1}]}mainFormComponent;ngAfterViewInit(){let t=this.mainFormComponent.mainForm.get("logo_path");setTimeout(()=>{let e=t?.value;console.log(e,"logo_path value"),t&&e&&typeof e=="string"&&t?.setValue(null,{emitEvent:!1})},2e3),t?.valueChanges.pipe(s(this.destroy$)).subscribe(e=>{e==null?this.extraPayload={remove_image:1}:this.extraPayload={remove_image:0}})}getDetails(t){this.apiService.Get(`procurement/brands/show/${t}`).pipe(s(this.destroy$)).subscribe({next:e=>{this.values=e.data,this.isShowMode&&this.fields.push({type:"input",title:"created_at",class:"col-6",controlName:"created_at",readOnly:!0,value:this.values.created_at},{type:"input",title:"updated_at",class:"col-6",controlName:"updated_at",readOnly:!0,value:this.values.updated_at})},error:e=>{console.error(e)}})}static \u0275fac=function(e){return new(e||d)(a(w),a(g),a(b),a(y),a(S))};static \u0275cmp=u({type:d,selectors:[["app-brand-actions"]],viewQuery:function(e,i){if(e&1&&h(l,5),e&2){let o;f(o=v())&&(i.mainFormComponent=o.first)}},decls:2,vars:11,consts:[[3,"title","Translationprefix","showTitle","showBreadcrumb"],["routeAfterSuccess","/settings/brands","titleOfButton2","cancel",3,"fields","url","formValues","fullWidthFields","readOnly","titleOfButton","extraPayload"]],template:function(e,i){e&1&&m(0,"app-page-title",0)(1,"app-main-form",1),e&2&&(n("title",i.title)("Translationprefix",i.translationPrefix)("showTitle",!0)("showBreadcrumb",!0),c(),n("fields",i.fields)("url",i.urlApi)("formValues",i.values)("fullWidthFields",i.fullWidthFields)("readOnly",i.isShowMode)("titleOfButton",i.titleOfButton)("extraPayload",i.extraPayload))},dependencies:[_,l],encapsulation:2})};export{O as BrandActions};
