import{d as V,b as _}from"./main.465728e1.js";import{u as D}from"./exchange-rate.85b564e2.js";import{B as p,k as u,C as l,b1 as F,r as d,K as N,u as n,o as x,l as A,w as h,e as G,q,f as v,m as L,j as C,h as b,t as E}from"./vendor.d12b5734.js";const O={key:0},U={class:"text-gray-500 sm:text-sm"},z={class:"text-gray-400 text-xs mt-2 font-light"},M={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(r){const e=r,m=V(),B=_(),g=D(),f=p(!1);let a=p(!1);m.fetchCurrencies();const s=u(()=>B.selectedCompanyCurrency),c=u(()=>m.currencies.find(t=>t.id===e.store[e.storeProp].currency_id)),P=u(()=>s.value.id!==e.customerCurrency);l(()=>e.store[e.storeProp].customer,t=>{R(t)},{deep:!0}),l(()=>e.store[e.storeProp].currency_id,t=>{$(t)},{immediate:!0}),l(()=>e.customerCurrency,t=>{t&&e.isEdit&&w()},{immediate:!0});function w(){P.value&&g.checkForActiveProvider(e.customerCurrency).then(t=>{t.data.success&&(f.value=!0)})}function R(t){t?e.store[e.storeProp].currency_id=t.currency.id:e.store[e.storeProp].currency_id=s.value.id}async function $(t){t!==s.value.id?(!e.isEdit&&t&&await y(t),e.store.showExchangeRate=!0):e.store.showExchangeRate=!1}function y(t){a.value=!0,g.getCurrentExchangeRate(t).then(o=>{o.data&&!o.data.error?e.store[e.storeProp].exchange_rate=o.data.exchangeRate[0]:e.store[e.storeProp].exchange_rate="",a.value=!1}).catch(o=>{a.value=!1})}return F(()=>{e.store.showExchangeRate=!1}),(t,o)=>{const k=d("BaseIcon"),S=d("BaseInput"),I=d("BaseInputGroup"),j=N("tooltip");return r.store.showExchangeRate&&n(c)?(x(),A(I,{key:0,"content-loading":n(a)&&!r.isEdit,label:t.$t("settings.exchange_rate.exchange_rate"),error:r.v.exchange_rate.$error&&r.v.exchange_rate.$errors[0].$message,required:""},{labelRight:h(()=>[f.value&&r.isEdit?(x(),G("div",O,[q(v(k,{name:"RefreshIcon",class:L(`h-4 w-4 text-primary-500 cursor-pointer outline-none ${n(a)?" animate-spin rotate-180 cursor-not-allowed pointer-events-none ":""}`),onClick:o[0]||(o[0]=i=>y(r.customerCurrency))},null,8,["class"]),[[j,{content:"Fetch Latest Exchange rate"}]])])):C("",!0)]),default:h(()=>[v(S,{modelValue:r.store[r.storeProp].exchange_rate,"onUpdate:modelValue":o[1]||(o[1]=i=>r.store[r.storeProp].exchange_rate=i),"content-loading":n(a)&&!r.isEdit,addon:`1 ${n(c).code} =`,disabled:n(a),onInput:o[2]||(o[2]=i=>r.v.exchange_rate.$touch())},{right:h(()=>[b("span",U,E(n(s).code),1)]),_:1},8,["modelValue","content-loading","addon","disabled"]),b("span",z,E(t.$t("settings.exchange_rate.exchange_help_text",{currency:n(c).code,baseCurrency:n(s).code})),1)]),_:1},8,["content-loading","label","error"])):C("",!0)}}};export{M as _};
