import{f as g}from"./chunk-LBZE4AC4.js";import{a as h}from"./chunk-F4GTCTBH.js";import{m as p}from"./chunk-OWZ5YAMH.js";import{a as v}from"./chunk-KXX3UDJ3.js";import{f as d,j as f}from"./chunk-GQAU5ACB.js";import{S as s,da as m,fa as a,la as o,pa as c,x as l}from"./chunk-ISMRT7VU.js";import{a as u}from"./chunk-M5TX2NVG.js";var n=(function(i){return i[i.Text=0]="Text",i[i.List=1]="List",i})(n||{}),b={[n.Text]:"\u0422\u0435\u043A\u0441\u0442",[n.List]:"\u0421\u043F\u0438\u0441\u043E\u043A"};var _=(()=>{class i{constructor(t,e){this._http=t,this._store=e}get(t){let e=new d;return t!==void 0&&(e=e.append("onlyList",t)),this._http.post("/api/characteristic/all",{},{headers:v,params:e}).pipe(a(r=>{this._store.dispatch(new h({characteristics:[...r]}))}))}getById(t){return this._http.get(`/api/characteristic/${t}`)}create(t){return this._http.post("/api/characteristic",u({},t))}edit(t,e){return this._http.put(`/api/characteristic/${e}`,u({},t))}delete(t){return this._http.delete(`/api/characteristic/${t}`)}static{this.\u0275fac=function(e){return new(e||i)(c(f),c(p))}}static{this.\u0275prov=o({token:i,factory:i.\u0275fac})}}return i})();var D=(()=>{class i{constructor(t,e){this._characteristicService=t,this._store=e}get(){return this._characteristicService.get().pipe(s(1),a(t=>{this._store.dispatch(new h({characteristics:[...t.sort((e,r)=>r.id-e.id)]}))}))}create(t){return this._characteristicService.create(t).pipe(m(()=>this.get()),s(1),l(()=>{}))}edit(t,e){return this._characteristicService.edit(t,e).pipe(a(()=>this.get().subscribe()),s(1))}delete(t){return this._characteristicService.delete(t).pipe(a(()=>this.get().subscribe()),s(1))}checkForDuplicates(t){let e=t.get("values")?.value.map(w=>w.new),r=new Set(e);return e?.length!==r.size}checkValid(t){let e=t.get("values")?.value.map(r=>r.new).findIndex(r=>r.length==0||r.length>g.max);return!t.valid||t.get("type")?.value===n.List&&!t.get("values")?.value.length||e!==-1}isFormValid(t){return!this.checkValid(t)&&!this.checkForDuplicates(t)}mappedValues(t){return t.values?.map(e=>e.old.length?{newValue:e.new,oldValue:e.old}:{newValue:e.new})}static{this.\u0275fac=function(e){return new(e||i)(c(_),c(p))}}static{this.\u0275prov=o({token:i,factory:i.\u0275fac})}}return i})();export{n as a,b,_ as c,D as d};
//# sourceMappingURL=chunk-GLJE673O.js.map
