import{t as e}from"./http-BdoVLsWz.js";import{n as t,t as n}from"./notification-BM55Quw3.js";import{t as r}from"./error-handling-CuGxlkPL.js";var i=(i=!1)=>{let a=i?window.pinia.defineStore:t,{global:o}=window.i18n;return a(`category`,{state:()=>({categories:[],currentCategory:{id:null,name:``,description:``},editCategory:null}),getters:{isEdit:e=>!!e.currentCategory.id},actions:{fetchCategories(t){return new Promise((n,i)=>{e.get(`/api/v1/categories`,{params:t}).then(e=>{this.categories=e.data.data,n(e)}).catch(e=>{r(e),i(e)})})},fetchCategory(t){return new Promise((n,i)=>{e.get(`/api/v1/categories/${t}`).then(e=>{this.currentCategory=e.data.data,n(e)}).catch(e=>{r(e),i(e)})})},addCategory(t){return new Promise((i,a)=>{e.post(`/api/v1/categories`,t).then(e=>{this.categories.push(e.data.data),n().showNotification({type:`success`,message:o.t(`settings.expense_category.created_message`)}),i(e)}).catch(e=>{r(e),a(e)})})},updateCategory(t){return new Promise((i,a)=>{e.put(`/api/v1/categories/${t.id}`,t).then(e=>{if(e.data){let r=this.categories.findIndex(t=>t.id===e.data.data.id);this.categories[r]=t.categories,n().showNotification({type:`success`,message:o.t(`settings.expense_category.updated_message`)})}i(e)}).catch(e=>{r(e),a(e)})})},deleteCategory(t){return new Promise(i=>{e.delete(`/api/v1/categories/${t}`).then(e=>{let r=this.categories.findIndex(e=>e.id===t);this.categories.splice(r,1),n().showNotification({type:`success`,message:o.t(`settings.expense_category.deleted_message`)}),i(e)}).catch(e=>{r(e),console.error(e)})})}}})()};export{i as t};