import K from"./Ctk5M3hU.js";import Q from"./Bvs3L9q-.js";import X from"./BT_icyIK.js";import{u as Y,s as i,b as Z,a as tt,d as et,e as x,c as at,o as ot,n as st,r as o,I as rt,z as ct,f as d,h as nt,m as M,k as u,l as $,i as ut,A as B,t as R,p as e,w as lt,j as h,C as it,D as pt,G as mt,E as dt}from"./BCLrUOBx.js";import{u as ht}from"./D7xsgz5m.js";import{u as vt}from"./CCot8u0_.js";import"./CIjHryQ0.js";import"./a5umXhxZ.js";import"./Bxmfm8sn.js";import"./YMgwR3Gi.js";import"./Dq2bRmo2.js";import"./CRoN-P3i.js";import"./CWalxxGV.js";import"./NsFEV5ZM.js";import"./BC1gcnRu.js";import"./ScxedDBk.js";const _t={class:"container-fluid mtb-20 mtb-sm-15"},ft={class:"product-detail checkout-detail"},gt={class:"area detail-left pt-10 plr-20 plr-sm-15 pb-20 pb-sm-15 mr-20 mr-sm mb-sm-15"},yt={class:"b-b pb-10 mb-15 bold"},kt={class:"mt-15 btn-input"},bt=["placeholder"],wt={key:0,class:"error"},Kt={__name:"checkout",setup(Ct){var S;const T=Y(),{langCode:p}=i(T),v=Z(),{currencyIcon:Pt,setting:V,currency:St,paymentGateway:l,customScripts:xt,site_setting:_}=i(v),{setToastMessage:Mt,setToastError:$t,deleteRequest:Bt,getRequest:G,setPaymentGateway:j,postRequest:A}=v,f=ht(),{cartProducts:g}=i(f),{getCartByUser:D,subtractCartProductCount:Rt,emptyCartProduct:Tt}=f,E=tt(),{userAddressAll:Vt,getUserToken:y}=E,{t:I}=et(),{pageMeta:U,preloadScript:k}=vt();let b="";const w=({paypal_key:t})=>({link:[k(`https://www.paypal.com/sdk/js?client-id=${t}&components=buttons,marks&disable-funding=paylater,card`),k("https://checkout.flutterwave.com/v3.js")]});l.value&&(b=w(l.value)),x({...U({..._.value,meta_title:`${I("header.checkout")} | ${(S=_.value)==null?void 0:S.meta_title}`}),...b});const q=at(),{authenticated:N}=i(q);ot(async()=>{var t;if(!((t=V.value)!=null&&t.guest_checkout)&&!N.value)return st("/login");if(!l.value){const a=await G({params:"",api:"paymentGateway",lang:p.value});j(a.data),x(w(a.data))}}),o(!1);const r=o(""),s=o(null),c=o(null),m=o(!1);o(!1);const n=o(0);o(0),rt(r,()=>{c.value=null,s.value=null}),ct();const C=d(()=>n.value.totalPriceWithOffer+n.value.shippingPrice+n.value.tax),P=d(()=>C.value?C.value-n.value.voucher:0),z=d(()=>g.value.filter(t=>parseInt(t.selected)===1)),O=async()=>{var a;m.value=!0;const t=await A({params:{voucher:r.value,user_token:await y(),price:(a=n.value)==null?void 0:a.totalPriceWithOffer},lang:p.value,api:"voucherValidity"});m.value=!1,(t==null?void 0:t.status)===201?s.value=t.data.form[0]:c.value=t.data},W=t=>{n.value=t};return nt(async()=>{s.value=null,c.value=null,g.value.length===0&&await D({lang:p.value,params:{user_token:await y()}})}),(t,a)=>{const H=K,L=Q,F=X;return h(),M("div",_t,[u("div",ft,[u("div",gt,[u("h5",yt,R(t.$t("checkout.selectPayment")),1),e(l)&&e(P)?(h(),ut(H,{key:0,ref:"paymentGateways","total-price":e(P),voucher:e(c)},null,8,["total-price","voucher"])):B("",!0)]),$(F,{"route-link":"checkout","checked-product":e(z),"has-shipping":!0,"voucher-result":e(c),"hide-btn":!0,onCalculatedPrice:W},{checkout:lt(()=>[u("div",{class:it({invalid:!!e(s)})},[u("form",kt,[pt(u("input",{class:"pl-15 pr-80",placeholder:t.$t("checkout.voucherCode"),type:"text","onUpdate:modelValue":a[0]||(a[0]=J=>mt(r)?r.value=J:null)},null,8,bt),[[dt,e(r)]]),$(L,{class:"primary-btn plr-15",type:"button","fetching-data":e(m),"loading-text":"",disabled:!e(r)||!!e(s)||!!e(c),text:t.$t("checkout.apply"),onClicked:O},null,8,["fetching-data","disabled","text"])])],2),e(s)?(h(),M("span",wt,R(e(s)),1)):B("",!0)]),_:1},8,["checked-product","voucher-result"])])])}}};export{Kt as default};
