import{M as C,$ as x,r as L,aM as M,N,R as c,e,W as P,a8 as $,Y as r,V as d,Z as m,U as p,O as o}from"./vendor-CsGITfgk.js";import"./index-GCDRvGOr.js";import{a as b}from"./index-iyjCkFCp.js";import{u as I}from"./useLoyaltyBalance-Dw3zRT-6.js";const T={key:0},W={class:"md:py-3 md:text-left"},O=C({__name:"payment-processing-loyalty",props:{order:{}},emits:["success","fail"],setup(f,{emit:_}){const n=_,s=f,{t:B}=x(),l=L(!1),{fetchLoyaltyBalance:k,loading:g,currentBalance:i,resultBalance:a}=I();async function h(){l.value=!0;const{isSuccess:t,errorMessage:y=""}=await b({orderId:s.order.id,paymentId:s.order.inPayments[0].id});l.value=!1,t?n("success"):n("fail",y)}M(async()=>{await k(s.order.id)});async function v(){await h()}function V(){n("fail",B("loyalty.payment.loyalty.errors.insufficient_points",{currentBalance:i.value}))}return(t,y)=>{const u=p("VcButton"),w=p("VcLoaderWithText");return e(g)?(o(),c(w,{key:1})):(o(),N("div",T,[P("p",W,r(t.$t("loyalty.payment.loyalty.text",{currentBalance:e(i)})),1),e(a)!==null&&e(a)!==void 0&&e(a)>=0?(o(),c(u,{key:0,loading:l.value,onClick:v},{default:d(()=>[m(r(t.$t("loyalty.payment.loyalty.pay_now_button")),1)]),_:1},8,["loading"])):e(a)!==null&&e(a)!==void 0&&e(a)<0?(o(),c(u,{key:1,onClick:V},{default:d(()=>[m(r(t.$t("loyalty.payment.loyalty.pay_now_button")),1)]),_:1})):$("",!0)]))}}});export{O as default};
//# sourceMappingURL=payment-processing-loyalty-CIe0_2fy.js.map
