import{$ as e,C as t,F as n,G as r,K as i,Wt as a,Z as o,_ as s,dt as c,et as l,g as u,h as d,v as f,vt as p,y as m,z as h,zt as g}from"./vue.runtime.esm-bundler-DAWRyTnP.js";import{t as _}from"./company-BhXg3qcB.js";import{t as v}from"./global-BGJPTjg4.js";import{t as y}from"./exchange-rate-0U3r-MDx.js";var b={key:0},x={class:`text-gray-500 sm:text-sm`},S={class:`text-gray-400 text-xs mt-2 font-light`},C={__name:`ExchangeRateConverter`,props:{v:{type:Object,default:null},isLoading:{type:Boolean,default:!1},store:{type:Object,default:null},storeProp:{type:String,default:``},isEdit:{type:Boolean,default:!1},customerCurrency:{type:[String,Number],default:null}},setup(C){let w=C,T=v(),E=_(),D=y(),O=c(!1),k=c(!1);T.fetchCurrencies();let A=d(()=>E.selectedCompanyCurrency),j=d(()=>T.currencies.find(e=>e.id===w.store[w.storeProp].currency_id)),M=d(()=>A.value.id!==w.customerCurrency);o(()=>w.store[w.storeProp].customer,e=>{P(e)},{deep:!0}),o(()=>w.store[w.storeProp].currency_id,e=>{F(e)},{immediate:!0}),o(()=>w.customerCurrency,e=>{e&&w.isEdit&&N(e)},{immediate:!0});function N(){M.value&&D.checkForActiveProvider(w.customerCurrency).then(e=>{e.data.success&&(O.value=!0)})}function P(e){e?w.store[w.storeProp].currency_id=e.currency.id:w.store[w.storeProp].currency_id=A.value.id}async function F(e){e===A.value.id?w.store.showExchangeRate=!1:(!w.isEdit&&e&&await I(e),w.store.showExchangeRate=!0)}function I(e){k.value=!0,D.getCurrentExchangeRate(e).then(e=>{e.data&&!e.data.error?w.store[w.storeProp].exchange_rate=e.data.exchangeRate[0]:w.store[w.storeProp].exchange_rate=``,k.value=!1}).catch(e=>{k.value=!1})}return n(()=>{w.store.showExchangeRate=!1}),(n,o)=>{let c=r(`BaseIcon`),d=r(`BaseInput`),_=r(`BaseInputGroup`),v=i(`tooltip`);return C.store.showExchangeRate&&j.value?(h(),s(_,{key:0,"content-loading":p(k)&&!C.isEdit,label:n.$t(`settings.exchange_rate.exchange_rate`),error:C.v.exchange_rate.$error&&C.v.exchange_rate.$errors[0].$message,required:``},{labelRight:e(()=>[O.value&&C.isEdit?(h(),m(`div`,b,[l(t(c,{name:`ArrowPathIcon`,class:g(`h-4 w-4 text-primary-500 cursor-pointer outline-hidden ${p(k)?` animate-spin rotate-180 cursor-not-allowed pointer-events-none `:``}`),onClick:o[0]||=e=>I(C.customerCurrency)},null,8,[`class`]),[[v,{content:`Fetch Latest Exchange rate`}]])])):f(``,!0)]),default:e(()=>[t(d,{modelValue:C.store[C.storeProp].exchange_rate,"onUpdate:modelValue":o[1]||=e=>C.store[C.storeProp].exchange_rate=e,"content-loading":p(k)&&!C.isEdit,addon:`1 ${j.value.code} =`,disabled:p(k),onInput:o[2]||=e=>C.v.exchange_rate.$touch()},{right:e(()=>[u(`span`,x,a(A.value.code),1)]),_:1},8,[`modelValue`,`content-loading`,`addon`,`disabled`]),u(`span`,S,a(n.$t(`settings.exchange_rate.exchange_help_text`,{currency:j.value.code,baseCurrency:A.value.code})),1)]),_:1},8,[`content-loading`,`label`,`error`])):f(``,!0)}}};export{C as t};