import{a as B}from"./chunk-QPCAJSKO.js";import{b as M}from"./chunk-TGWIHQDX.js";import{a as j}from"./chunk-YHVRQUSB.js";import{b as R,d as V,f as E}from"./chunk-S3ADKFO2.js";import{c as A,n as I}from"./chunk-I5MYHHJE.js";import{Ab as D,Bb as h,Db as b,Eb as y,Fb as C,Fc as p,Gb as o,Gc as d,Hb as a,Pb as v,S as w,Tb as _,Vb as l,Wa as r,f as S,gb as f,ha as u,ia as x,ic as c,jc as g,kc as P,lb as k,zb as T}from"./chunk-CKLXM6EG.js";import"./chunk-TSRGIXR5.js";function F(n,t){if(n&1){let e=v();o(0,"div",8),_("click",function(){let s=u(e).$implicit,m=l();return x(m._Permissions.hasPermission("update precision")?m.selectRule(s):null)}),c(1),p(2,"translate"),a()}if(n&2){let e=t.$implicit,i=l();C("ngClass",i.selectedRule==e?"orange-card":"default-card"),r(),P(" ",d(2,2,i.translatePrefix+"."+e)," ")}}function O(n,t){if(n&1){let e=v();o(0,"div",8),_("click",function(){let s=u(e).$implicit,m=l();return x(m._Permissions.hasPermission("update precision")?m.selectDecimal(s):null)}),c(1),p(2,"translate"),a()}if(n&2){let e=t.$implicit,i=l();C("ngClass",i.selectedDecimal==e?"orange-card":"default-card"),r(),P(" ",d(2,2,i.translatePrefix+"."+e)," ")}}function z(n,t){if(n&1){let e=v();o(0,"div",7)(1,"button",9),_("click",function(){u(e);let s=l();return x(s.submit())}),c(2),p(3,"translate"),a(),o(4,"button",10),_("click",function(){u(e);let s=l();return x(s.cancel())}),c(5),p(6,"translate"),a()()}if(n&2){let e=l();r(2),g(d(3,2,e.translatePrefix+".save")),r(3),g(d(6,4,e.translatePrefix+".cancel"))}}var $=class n{constructor(t,e,i,s){this.toast=t;this.apiService=e;this.translate=i;this._Permissions=s}ngOnInit(){this.getDetails()}getDetails(){this.apiService.Get("procurement/precision").pipe(w(this.destroy$)).subscribe({next:t=>{console.log(t.data),this.selectedRule=t.data.rounding_rule,this.selectedDecimal=t.data.decimals},error:t=>{console.error("Error fetching employee:",t)}})}translatePrefix="approximation";roundRule=["nearest","up","down"];decimals=[0,1,2,3];selectedRule;selectedDecimal;destroy$=new S;selectRule(t){this.selectedRule=t}selectDecimal(t){this.selectedDecimal=t}submit(){if(this.selectedRule){if(this.selectedDecimal==null){this.toast.error(this.translate.instant("approximation.choose_decimal_number"));return}}else{this.toast.error(this.translate.instant("approximation.choose_rounding_method"));return}let t={roundRule:this.selectedRule,decimals:this.selectedDecimal};return this.apiService.Post("procurement/precision/update",t).subscribe({next:e=>{console.log(e),this.toast.success(e.message,e.data.created_at,e.data.updated_at)},error:e=>{console.error(e),this.toast.error(e.error.message)}})}cancel(){this.selectedRule=null,this.selectedDecimal=null}static \u0275fac=function(e){return new(e||n)(f(M),f(j),f(R),f(B))};static \u0275cmp=k({type:n,selectors:[["app-approximation"]],decls:18,vars:7,consts:[[1,"my-5"],[1,""],[1,"title"],[1,"container-fluid","mt-4"],[1,"row","d-flex","gap-5"],[1,"col-md-2","col-sm-6",3,"ngClass"],[1,"mt-5","pt-4"],[1,"mt-5","d-flex","align-items-center","justify-content-center","gap-3","pt-5"],[1,"col-md-2","col-sm-6",3,"click","ngClass"],[1,"btn",3,"click"],[1,"btn","bg-secondary",3,"click"]],template:function(e,i){e&1&&(o(0,"div",0)(1,"div",1)(2,"p",2),c(3),p(4,"translate"),a(),o(5,"div",3)(6,"div",4),b(7,F,3,4,"div",5,h),a()()(),o(9,"div",6)(10,"p",2),c(11),p(12,"translate"),a(),o(13,"div",3)(14,"div",4),b(15,O,3,4,"div",5,h),a()()(),T(17,z,7,6,"div",7),a()),e&2&&(r(3),g(d(4,3,i.translatePrefix+".rounding_method")),r(4),y(i.roundRule),r(4),g(d(12,5,i.translatePrefix+".decimal_rounding")),r(4),y(i.decimals),r(2),D(i._Permissions.hasPermission("update precision")?17:-1))},dependencies:[E,I,A,V],styles:[".title[_ngcontent-%COMP%]{color:var(--black, #000);font-size:25px;font-style:normal;font-weight:700;line-height:normal}.orange-card[_ngcontent-%COMP%]{border-radius:8px;border:1px solid var(--secondary, #da5b30);background:#da5b3014;display:flex;padding:12px 16px;justify-content:center;color:var(--secondary, #da5b30);align-items:center;font-size:20px;font-style:normal;font-weight:700;line-height:normal;gap:10px;cursor:pointer}.default-card[_ngcontent-%COMP%]{display:flex;padding:12px 16px;justify-content:center;align-items:center;cursor:pointer;gap:10px;border-radius:8px;color:var(--gray, #808080);font-size:20px;font-style:normal;font-weight:700;line-height:normal;border:1px solid var(--gray, #808080);background:#80808014}.btn[_ngcontent-%COMP%]{display:flex;width:180px;height:49px;padding:10px 12px;justify-content:center;align-items:center;gap:10px;border-radius:16px;color:#fff;background:var(--secondary, #da5b30)}"]})};export{$ as Approximation};
