import{t as e}from"./http-BrugN6o-.js";import{n as t,t as n}from"./notification-BM55Quw3.js";import{t as r}from"./error-handling-CRDNZ9kr.js";var i=(i=!1)=>{let a=i?window.pinia.defineStore:t,{global:o}=window.i18n;return a(`taxType`,{state:()=>({taxTypes:[],currentTaxType:{id:null,name:``,calculation_type:`percentage`,percent:0,fixed_amount:0,description:``,compound_tax:!1,collective_tax:0}}),getters:{isEdit:e=>!!e.currentTaxType.id},actions:{resetCurrentTaxType(){this.currentTaxType={id:null,name:``,calculation_type:`percentage`,percent:0,fixed_amount:0,description:``,compound_tax:!1,collective_tax:0}},fetchTaxTypes(t){return new Promise((n,i)=>{e.get(`/api/v1/tax-types`,{params:t}).then(e=>{this.taxTypes=e.data.data,n(e)}).catch(e=>{r(e),i(e)})})},fetchTaxType(t){return new Promise((n,i)=>{e.get(`/api/v1/tax-types/${t}`).then(e=>{this.currentTaxType=e.data.data,n(e)}).catch(e=>{r(e),i(e)})})},addTaxType(t){let i=n();return new Promise((n,a)=>{e.post(`/api/v1/tax-types`,t).then(e=>{this.taxTypes.push(e.data.data),i.showNotification({type:`success`,message:o.t(`settings.tax_types.created_message`)}),n(e)}).catch(e=>{r(e),a(e)})})},updateTaxType(t){let i=n();return new Promise((n,a)=>{e.put(`/api/v1/tax-types/${t.id}`,t).then(e=>{if(e.data){let n=this.taxTypes.findIndex(t=>t.id===e.data.data.id);this.taxTypes[n]=t.taxTypes,i.showNotification({type:`success`,message:o.t(`settings.tax_types.updated_message`)})}n(e)}).catch(e=>{r(e),a(e)})})},fetchSalesTax(t){return new Promise((n,i)=>{e.post(`/api/m/sales-tax-us/current-tax`,t).then(e=>{if(e.data){let t=this.taxTypes.findIndex(e=>e.name===`SalesTaxUs`);t>-1&&this.taxTypes.splice(t,1),this.taxTypes.push({...e.data.data,tax_type_id:e.data.data.id})}n(e)}).catch(e=>{r(e),i(e)})})},deleteTaxType(t){return new Promise((i,a)=>{e.delete(`/api/v1/tax-types/${t}`).then(e=>{if(e.data.success){let e=this.taxTypes.findIndex(e=>e.id===t);this.taxTypes.splice(e,1),n().showNotification({type:`success`,message:o.t(`settings.tax_types.deleted_message`)})}i(e)}).catch(e=>{r(e),a(e)})})}}})()};export{i as t};