import{_ as S}from"./SmartDataTable-2Nc3Ohem.js";import{T as C,U as $,H as x,d as k,f as w,h,i as c,c as o,a0 as F,D as v,V as B,y as g,v as r,S as R,P as D,r as _,C as U,G as A,L as I,R as N}from"./index-C5GbdPxY.js";import{u as E}from"./form-B2je8iBR.js";import{V as z}from"./VDialog-Dr29crN8.js";import{V as G}from"./VForm-BZc3SavJ.js";import{c as H,V as L,a as M,b as P}from"./VCard-DptrO3GI.js";import{V as j}from"./VTextField-DxEUpn3-.js";import{V as q}from"./VSpacer-79sITyKz.js";import"./VAvatar-RkAR0u0e.js";import"./VImg-BlqLjeEy.js";import"./VSelect-vtfYszIh.js";import"./forwardRefs-CB8NoG9r.js";import"./VList-C3dIUnee.js";import"./index-XcTykuv2.js";import"./VMenu-CT0Fri-T.js";import"./VOverlay-DlJb3QlW.js";import"./getScrollParent-DE35ecf2.js";import"./VVirtualScroll-BUlcGoHW.js";import"./VChip-CsS_5IS6.js";import"./confirmDialog-CDDTmj30.js";import"./_plugin-vue_export-helper-DlAUqK2U.js";import"./lodash-kem28dbC.js";import"./_commonjsHelpers-_d1bhYXs.js";import"./VCheckbox-rNAD_QU_.js";import"./VDatePicker-DHBX-k2T.js";import"./VBadge-DZHesqMo.js";import"./VTooltip-DPhSY2Qe.js";import"./TableAgent.vue_vue_type_script_setup_true_lang-XA6R7TPe.js";import"./TableEnum.vue_vue_type_script_setup_true_lang-5ITYgflT.js";import"./TableStatus.vue_vue_type_script_setup_true_lang-BRbfAU0T.js";import"./RoleBadge.vue_vue_type_script_setup_true_lang-Ctl8Qye7.js";import"./VDataTable-BFiF8jPV.js";import"./VTable-M43pjJD_.js";import"./filter-DERJvhSS.js";function J(){return C.put("/v1/currency-rates/refresh")}function K(n){return C.get(`/v1/currency-rates/${n}`)}function O(n,a){return C.put(`/v1/currency-rates/${n}`,{rate:a})}function T(){const n=$(),{t:a}=x();return{refresh:async()=>{var t,l;try{const e=await J();n.success(e.data.message)}catch(e){n.error(((l=(t=e.response)==null?void 0:t.data)==null?void 0:l.message)||a("core::errors.an_unexpected_error_occurred"))}},getCurrencyRate:async t=>{try{return await K(t)}catch{}return!1},updateCurrencyRate:O}}const Q=k({__name:"Edit",props:{modelValue:{type:Boolean},item:{}},emits:["update:modelValue","saved"],setup(n,{emit:a}){var f;const u=n,i=a,{t}=x(),{updateCurrencyRate:l}=T(),e=E({rate:((f=u.item)==null?void 0:f.rate)||""});function d(){i("update:modelValue",!1)}const p=async()=>{e.state.rate&&!e.loading.value&&await e.submit(()=>l(u.item.id,e.state.rate))&&(i("saved"),d())};return(b,m)=>(h(),w(z,{"max-width":"500","model-value":b.modelValue,persistent:"","onUpdate:modelValue":m[1]||(m[1]=s=>i("update:modelValue",s))},{default:c(()=>[o(G,{onSubmit:F(p,["prevent"])},{default:c(()=>[o(H,null,{default:c(()=>[o(L,{class:"border-b pb-2 mb-4 d-flex align-center gap-1 font-weight-bold text-h6"},{default:c(()=>[o(B,{icon:"ic-outline-edit",size:"20"}),v(" "+g(r(t)("admin::resource.edit",{resource:r(t)("currency::currency_rates.currency_rate")})),1)]),_:1}),o(M,{class:"pt-0"},{default:c(()=>{var s,y;return[o(j,{modelValue:r(e).state.rate,"onUpdate:modelValue":m[0]||(m[0]=V=>r(e).state.rate=V),error:!!((s=r(e).errors.value)!=null&&s.rate),"error-messages":(y=r(e).errors.value)==null?void 0:y.rate,label:r(t)("currency::attributes.currency_rates.rate"),type:"number"},null,8,["modelValue","error","error-messages","label"])]}),_:1}),o(P,null,{default:c(()=>[o(q),o(R,{color:"default",disabled:r(e).loading.value,onClick:d},{default:c(()=>[v(g(r(t)("admin::admin.buttons.cancel")),1)]),_:1},8,["disabled"]),o(R,{color:"primary",disabled:!r(e).state.rate||r(e).loading.value,loading:r(e).loading.value,onClick:p},{default:c(()=>[v(g(r(t)("admin::admin.buttons.update")),1)]),_:1},8,["disabled","loading"])]),_:1})]),_:1})]),_:1})]),_:1},8,["model-value"]))}}),Fe=k({__name:"Index",setup(n){const{t:a}=x(),{can:u}=D(),{refresh:i}=T(),t=_(!1),l=_(null),e=_(),d=[{title:a("currency::currency_rates.table.currency"),value:"currency_name",sortable:!1},{title:a("currency::currency_rates.table.code"),value:"currency",sortable:!0},{title:a("currency::currency_rates.table.rate"),value:"rate",sortable:!0},{title:a("currency::currency_rates.table.last_updated"),value:"updated_at",sortable:!0}],p=_([{key:"refresh_rates",label:a("currency::currency_rates.refresh_rates"),icon:"ic-baseline-currency-exchange",tooltip:a("currency::currency_rates.tooltips.refresh_exchange_rates"),permission:"admin.currency_rates.edit",onClick:i}]),f=(m,s)=>{u("admin.currency_rates.edit")&&(l.value=s.item,t.value=!0)},b=()=>{e.value.refresh()};return(m,s)=>{const y=S;return h(),U(N,null,[o(y,{ref_key:"smartTableRef",ref:e,"api-uri":"/v1/currency-rates","header-actions":r(p),headers:d,module:"currency",name:"currency_rate","on-row-click":r(u)("admin.currency_rates.edit")?f:null,resource:"currency_rates"},null,8,["header-actions","on-row-click"]),r(t)&&r(u)("admin.currency_rates.edit")?(h(),w(Q,{key:0,modelValue:r(t),"onUpdate:modelValue":s[0]||(s[0]=V=>I(t)?t.value=V:null),item:r(l),onSaved:b},null,8,["modelValue","item"])):A("",!0)],64)}}});export{Fe as default};
