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 w}from"./chunk-C72E7DYO.js";import"./chunk-WIPHIZE3.js";import"./chunk-LXYD2H4H.js";import"./chunk-IEDTWYT7.js";import"./chunk-TMA5MVRB.js";import{a as v,b as S}from"./chunk-4N5DMUBB.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 r}from"./chunk-RYV2RH4B.js";import"./chunk-CV2ZWZQE.js";import"./chunk-R2UR7BVM.js";import{q as y}from"./chunk-HKLJ6VPZ.js";import"./chunk-MQ46LYK7.js";import"./chunk-PQ5Q7HJL.js";import"./chunk-72CHOCZD.js";import{Eb as f,Fb as u,O as s,Pb as h,Y as o,f as p,gb as c,tb as m}from"./chunk-56X5LYJH.js";import{a as n,b as l}from"./chunk-TSRGIXR5.js";var F=class d{destroy$=new p;actionType;periodId;title;submitBtnTitle;readOnly=!1;fields;put=!1;loading=!0;financialEndPoint="financial-periods";detail;api=o(w);route=o(y);switcherFactory=o(S);switcherState;componentId=v.periodSwitcher;ngOnInit(){this.switcherState=this.switcherFactory.create(this.componentId),this.resolveActionType(),this.initFormFields()}ngOnDestroy(){this.destroy$.next(),this.destroy$.complete()}resolveActionType(){this.route.url.pipe(s(this.destroy$)).subscribe(i=>{let[t,e]=i.map(a=>a.path);if(t==="add"){this.actionType="add",this.periodId=void 0,this.initViewByType();return}if(t==="update"&&e){let a=+e;this.periodId!==a&&(this.periodId=a,this.actionType="update",this.initViewByType(),this.loadDetail());return}console.warn("Invalid financial-period route:",i)})}initViewByType(){let i={add:{title:"add_new_financialPeriod",submitBtnTitle:"save",put:!1,financialEndPoint:"financial-periods"},update:{title:"edit_financialPeriod",submitBtnTitle:"update",put:!0,financialEndPoint:`financial-periods/${this.periodId}`}};Object.assign(this,i[this.actionType])}initFormFields(){this.fields=[{title:"name",type:"input",controlName:"name_ar",validators:[r.required]},{title:"from",type:"date",controlName:"from",validators:[r.required],class:"col-12 col-md-6"},{title:"to",type:"date",controlName:"to",validators:[r.required],minDateControl:"from",class:"col-12 col-md-6"},{title:"description",type:"textarea",controlName:"description"}]}loadDetail(){this.periodId&&(this.loading=!0,this.api.Get(this.financialEndPoint).pipe(s(this.destroy$)).subscribe({next:i=>{i.status&&(this.detail=l(n({},i.data),{name_ar:i.data.name})),this.loading=!1},error:i=>{console.error("Failed to load financial period:",i),this.loading=!1}}))}onSubmitSuccess(i){this.actionType==="add"&&this.applyAddToSwitcher(i),this.actionType==="update"&&this.applyUpdateToSwitcher(i)}applyAddToSwitcher(i){let t={id:i.id,name:i.name};this.switcherState.addItem(n({},t))}applyUpdateToSwitcher(i){let t={id:i.id,name:i.name};this.switcherState.updateItem(n({},t)),this.switcherState.currentItem()?.id===t.id&&this.switcherState.setCurrentItem(n({},t))}static \u0275fac=function(t){return new(t||d)};static \u0275cmp=c({type:d,selectors:[["app-financial-periods-actions"]],decls:1,vars:10,consts:[["fileNameTranslated","shared","routeAfterSuccess","/home/financialPeriods/all","translationPrefix","financialPeriods","titleImgSrc","assets/images/addNewPeriod.png",3,"resValue","titleOfPage","readOnly","fields","Put","url","formValues","titleOfButton","ApplyTranslationprefix","useMethodPut","appearResetButton"]],template:function(t,e){t&1&&(f(0,"app-main-form",0),h("resValue",function(T){return e.onSubmitSuccess(T)}),u()),t&2&&m("titleOfPage",e.title)("readOnly",e.readOnly)("fields",e.fields)("Put",e.put)("url",e.financialEndPoint)("formValues",e.detail)("titleOfButton",e.submitBtnTitle)("ApplyTranslationprefix",!0)("useMethodPut",!0)("appearResetButton",!0)},dependencies:[P],encapsulation:2})};export{F as FinancialPeriodsActionsComponent};
