import{a as d}from"./chunk-IUBVOCNY.js";import{p as g}from"./chunk-7WGMNLRJ.js";import{i as l}from"./chunk-YMOV4UGM.js";import{$ as s,K as c,ga as h,la as p}from"./chunk-I3FGJX2C.js";import{a as u}from"./chunk-B7YGBANW.js";var f=(()=>{let r=class r{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}`)}};r.\u0275fac=function(e){return new(e||r)(p(l))},r.\u0275prov=h({token:r,factory:r.\u0275fac});let o=r;return o})();var j=(()=>{let r=class r{constructor(t,e){this._store=t,this._categoryServiceApi=e}getCategories(){return this._categoryServiceApi.getCategories().pipe(s(t=>this._store.dispatch(new d({categories:t}))),c(1))}deleteCategory(t){return this._categoryServiceApi.deleteCategory(t).pipe(s(()=>this.getCategories().subscribe()),c(1))}editCategory(t,e){let i={nameRu:e.name,nameKk:e.name,isQuick:e.isQuick,parentId:e.parentId,comment:e.comment};return this._categoryServiceApi.editCategory(t,i).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=[],i=n=>{for(let a of n)e.push(a.id),a.children?.length&&i(a.children)};return i(t),e}findCategoryChildren(t,e){for(let i of t){if(i.id===e)return i.children??[];if(i.children){let n=this.findCategoryChildren(i.children,e);if(n.length>0)return n}}return[]}_searchForParentId(t,e,i){for(let n of t){if(n.id===e)return i;if(n.children){let a=this._searchForParentId(n.children,e,n.id);if(a!==null)return a}}return null}};r.\u0275fac=function(e){return new(e||r)(p(g),p(f))},r.\u0275prov=h({token:r,factory:r.\u0275fac});let o=r;return o})();export{f as a,j as b};
//# sourceMappingURL=chunk-PBW2V4VL.js.map
