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,s=n();return a(`exchange-rate`,{state:()=>({supportedCurrencies:[],drivers:[],activeUsedCurrencies:[],providers:[],currencies:null,currentExchangeRate:{id:null,driver:``,key:``,active:!0,currencies:[]},currencyConverter:{type:``,url:``},bulkCurrencies:[]}),getters:{isEdit:e=>!!e.currentExchangeRate.id},actions:{fetchProviders(t){return new Promise((n,i)=>{e.get(`/api/v1/exchange-rate-providers`,{params:t}).then(e=>{this.providers=e.data.data,n(e)}).catch(e=>{r(e),i(e)})})},fetchDefaultProviders(){return new Promise((t,n)=>{e.get(`/api/v1/config?key=exchange_rate_drivers`).then(e=>{this.drivers=e.data.exchange_rate_drivers,t(e)}).catch(e=>{r(e),n(e)})})},fetchProvider(t){return new Promise((n,i)=>{e.get(`/api/v1/exchange-rate-providers/${t}`).then(e=>{this.currentExchangeRate=e.data.data,this.currencyConverter=e.data.data.driver_config,n(e)}).catch(e=>{r(e),i(e)})})},addProvider(t){return new Promise((n,i)=>{e.post(`/api/v1/exchange-rate-providers`,t).then(e=>{s.showNotification({type:`success`,message:o.t(`settings.exchange_rate.created_message`)}),n(e)}).catch(e=>{r(e),i(e)})})},updateProvider(t){return new Promise((n,i)=>{e.put(`/api/v1/exchange-rate-providers/${t.id}`,t).then(e=>{s.showNotification({type:`success`,message:o.t(`settings.exchange_rate.updated_message`)}),n(e)}).catch(e=>{r(e),i(e)})})},deleteExchangeRate(t){return new Promise((n,i)=>{e.delete(`/api/v1/exchange-rate-providers/${t}`).then(e=>{let r=this.drivers.findIndex(e=>e.id===t);this.drivers.splice(r,1),e.data.success?s.showNotification({type:`success`,message:o.t(`settings.exchange_rate.deleted_message`)}):s.showNotification({type:`error`,message:o.t(`settings.exchange_rate.error`)}),n(e)}).catch(e=>{r(e),i(e)})})},fetchCurrencies(t){return new Promise((n,i)=>{e.get(`/api/v1/supported-currencies`,{params:t}).then(e=>{this.supportedCurrencies=e.data.supportedCurrencies,n(e)}).catch(e=>{r(e),i(e)})})},fetchActiveCurrency(t){return new Promise((n,i)=>{e.get(`/api/v1/used-currencies`,{params:t}).then(e=>{this.activeUsedCurrencies=e.data.activeUsedCurrencies,n(e)}).catch(e=>{r(e),i(e)})})},fetchBulkCurrencies(){return new Promise((t,n)=>{e.get(`/api/v1/currencies/used`).then(e=>{this.bulkCurrencies=e.data.currencies.map(e=>(e.exchange_rate=null,e)),t(e)}).catch(e=>{r(e),n(e)})})},updateBulkExchangeRate(t){return new Promise((n,i)=>{e.post(`/api/v1/currencies/bulk-update-exchange-rate`,t).then(e=>{n(e)}).catch(e=>{r(e),i(e)})})},getCurrentExchangeRate(t){return new Promise((n,r)=>{e.get(`/api/v1/currencies/${t}/exchange-rate`).then(e=>{n(e)}).catch(e=>{r(e)})})},getCurrencyConverterServers(){return new Promise((t,n)=>{e.get(`/api/v1/config?key=currency_converter_servers`).then(e=>{t(e)}).catch(e=>{r(e),n(e)})})},checkForActiveProvider(t){return new Promise((n,r)=>{e.get(`/api/v1/currencies/${t}/active-provider`).then(e=>{n(e)}).catch(e=>{r(e)})})}}})()};export{i as t};