import{a as l}from"./chunk-MWDJTJ3O.js";import{n as d,q as h}from"./chunk-TKVDP62Z.js";import{Fa as s,Tc as r,ga as p,k as c,na as f,ra as m}from"./chunk-GJDGQISV.js";var g=class u{httpService=m(h);toastr=m(d);breadcrumbPath=s("");fractionDataService=m(l);_formData=s({});_submitApi=s({});formData=r(()=>this._formData()?.Form);configDefault=r(()=>this._formData()?.ConfigDefault);options=r(()=>this._formData()?.Options??this._formData()?.options);submitApi=r(()=>this._submitApi());getFormData(t){return this.httpService.get(`/api/settings/${t}`)}initFormData(t){let i=t.pathFromRoot.slice().reverse().find(o=>o.snapshot.data&&"formData"in o.snapshot.data)?.snapshot.data.formData??null,n=`settings/${this.GenerateApiPath(t.snapshot)}`;i&&this._formData.set(i),n&&this._submitApi.set(n)}setFormData(t){this._formData.set(t??{})}submitSettings(t){let a=t??this.formData();return this.validateFractionConfig()?this.httpService.put(`/api/${this.submitApi()}`,a).pipe(p(()=>{(a.Amount||a.Quantity)&&this.updateFractionData(a)})):c}updateFractionData(t){let{quantity:a,amount:e}=this.fractionDataService,{Quantity:i,Amount:n}=t,o=a.maximumFraction!==i?.Maximum||a.minimumFraction!==i?.Minimum,D=e.maximumFraction!==n?.Maximum||e.minimumFraction!==n?.Minimum;!o&&!D||(this.fractionDataService.setQuantityFraction(i?.Minimum,i?.Maximum),this.fractionDataService.setAmountFraction(n?.Minimum,n?.Maximum))}validateFractionConfig(){let t=this.formData()?.Form?.Fraction,a=t?.Quantity,e=t?.Amount,i=!0;return a&&a.Maximum<a.Minimum&&(i=!1,this.toastr.error("Quantity fraction configuration is invalid. Maximum should be greater than or equal to Minimum.","Validation Error")),e&&e.Maximum<e.Minimum&&i&&(i=!1,this.toastr.error("Amount fraction configuration is invalid. Maximum should be greater than or equal to Minimum.","Validation Error")),i}setBreadcrumbPath(t){let e=t.split("#")[0].replace("/menu/Settings/","").replace("/"," > ").replace(/-/g," ");t.startsWith("/menu/Settings/")&&this.breadcrumbPath.set(e)}GenerateApiPath(t){return t.pathFromRoot.flatMap(n=>n.url.map(o=>o.path)).filter(Boolean).slice(-2).map(n=>n.replace(/-/g," ").split(" ").map(o=>o.charAt(0).toUpperCase()+o.slice(1)).join("")).join("/")}static \u0275fac=function(a){return new(a||u)};static \u0275prov=f({token:u,factory:u.\u0275fac,providedIn:"root"})};export{g as a};
