import{a as d}from"./chunk-7E4GTVCE.js";import{m as l}from"./chunk-OWZ5YAMH.js";import{j as u}from"./chunk-GQAU5ACB.js";import{S as a,fa as c,la as h,pa as s}from"./chunk-ISMRT7VU.js";import{a as p}from"./chunk-M5TX2NVG.js";var g=(()=>{class n{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",p({},t))}editCategory(t,e){return this._http.put(`/api/category/${t}`,p({},e))}deleteCategory(t){return this._http.delete(`/api/category/${t}`)}static{this.\u0275fac=function(e){return new(e||n)(s(u))}}static{this.\u0275prov=h({token:n,factory:n.\u0275fac})}}return n})();var k=(()=>{class n{constructor(t,e){this._store=t,this._categoryServiceApi=e}getCategories(){return this._categoryServiceApi.getCategories().pipe(c(t=>this._store.dispatch(new d({categories:t}))),a(1))}deleteCategory(t){return this._categoryServiceApi.deleteCategory(t).pipe(c(()=>this.getCategories().subscribe()),a(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(c(()=>this.getCategories().subscribe()),a(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(c(()=>this.getCategories().subscribe()),a(1))}findParentId(t,e){return e?this._searchForParentId(t,e,null):null}collectAllCategoryIds(t){if(!t?.length)return[];let e=[],r=i=>{for(let o of i)e.push(o.id),o.children?.length&&r(o.children)};return r(t),e}findCategoryChildren(t,e){for(let r of t){if(r.id===e)return r.children??[];if(r.children){let i=this.findCategoryChildren(r.children,e);if(i.length>0)return i}}return[]}findCategoryName(t,e){for(let r of t){if(r.id===e)return r.name;if(r.children?.length){let i=this.findCategoryName(r.children,e);if(i)return i}}}_searchForParentId(t,e,r){for(let i of t){if(i.id===e)return r;if(i.children){let o=this._searchForParentId(i.children,e,i.id);if(o!==null)return o}}return null}static{this.\u0275fac=function(e){return new(e||n)(s(l),s(g))}}static{this.\u0275prov=h({token:n,factory:n.\u0275fac})}}return n})();export{g as a,k as b};
//# sourceMappingURL=chunk-Y3XNTQMS.js.map
