import{a as g}from"./chunk-FKH5Y42R.js";import{p as d}from"./chunk-JBWPPKX4.js";import{i as l}from"./chunk-NDLDFKR2.js";import{$ as s,K as c,fa as p,ka as h}from"./chunk-PVUKHE45.js";import{a as u}from"./chunk-MZPAXKJS.js";var f=(()=>{let i=class i{constructor(t){this._http=t}getCategories(){return this._http.get("/api/category")}getCategoryById(t){return this._http.get(`/api/category/${t}`)}createCategory(t){return this._http.post("/api/category",u({},t))}editCategory(t,e){return this._http.put(`/api/category/${t}`,u({},e))}deleteCategory(t){return this._http.delete(`/api/category/${t}`)}};i.\u0275fac=function(e){return new(e||i)(h(l))},i.\u0275prov=p({token:i,factory:i.\u0275fac});let o=i;return o})();var j=(()=>{let i=class i{constructor(t,e){this._store=t,this._categoryServiceApi=e}getCategories(){return this._categoryServiceApi.getCategories().pipe(s(t=>this._store.dispatch(new g({categories:t}))),c(1))}deleteCategory(t){return this._categoryServiceApi.deleteCategory(t).pipe(s(()=>this.getCategories().subscribe()),c(1))}editCategory(t,e){let r={nameRu:e.name,nameKk:e.name,isQuick:e.isQuick,parentId:e.parentId,comment:e.comment};return this._categoryServiceApi.editCategory(t,r).pipe(s(()=>this.getCategories().subscribe()),c(1))}createCategory(t){let e={nameRu:t.name,nameKk:t.name,isQuick:t.isQuick,parentId:t.parentId,comment:t.comment};return this._categoryServiceApi.createCategory(e).pipe(s(()=>this.getCategories().subscribe()),c(1))}findParentId(t,e){return e?this._searchForParentId(t,e,null):null}collectAllCategoryIds(t){if(!t?.length)return[];let e=[],r=n=>{for(let a of n)e.push(a.id),a.children?.length&&r(a.children)};return r(t),e}findCategoryChildren(t,e){for(let r of t){if(r.id===e)return r.children??[];if(r.children){let n=this.findCategoryChildren(r.children,e);if(n.length>0)return n}}return[]}findCategoryName(t,e){for(let r of t){if(r.id===e)return r.name;if(r.children?.length){let n=this.findCategoryName(r.children,e);if(n)return n}}}_searchForParentId(t,e,r){for(let n of t){if(n.id===e)return r;if(n.children){let a=this._searchForParentId(n.children,e,n.id);if(a!==null)return a}}return null}};i.\u0275fac=function(e){return new(e||i)(h(d),h(f))},i.\u0275prov=p({token:i,factory:i.\u0275fac});let o=i;return o})();export{f as a,j as b};
//# sourceMappingURL=chunk-NAZFOLJX.js.map
