1import{r as d,j as e}from"./app-DCmRnz1M.js";import{l as C,E as I,b as B}from"./StripePayment-CEIOzPvM.js";import{a as N}from"./index-6fsxzwaN.js";import{O as M,a as O}from"./OrderSummaryCard-D7LoW7ET.js";import{B as D}from"./Button-X00moFao.js";import{N as z}from"./NoticeBox-DNvtQQla.js";import{C as L,I as R,S as q}from"./CheckoutLayout-xGdGD1Ad.js";import{d as b}from"./utils-DRFJABgr.js";import{c as T,a as W,h as F,N as S}from"./checkoutStore-CHRdHLVx.js";import{I as G}from"./IconCheck-B4W3fQPe.js";/* empty css */import"./index.esm-DXD71nLg.js";import"./CheckoutTitle-4xIVqiAQ.js";import"./checkbox-CqWJA5B_.js";import"./index-_JifkXZ6.js";import"./index--bH0ejcI.js";import"./index.esm-Cu_3Z7zA.js";import"./input-Dh_hg154.js";import"./IconChevronUp-CGDwff4G.js";import"./alert-onOjm6B_.js";function de({product:f,uuid:m,stripeKey:p,isAgentOrder:w}){const g=T(),s=W(),[l,A]=d.useState(null),[v,a]=d.useState([]),[j,i]=d.useState(!1);d.useEffect(()=>{p&&A(C(p))},[p]);const P=async(o,n,x)=>{if(!l)return;const c=await l;if(c)try{const{error:r,paymentIntent:t}=await c.handleCardAction(n);r?(a([r.message||"Payment authentication failed"]),i(!1)):t?await u({stripeCustomerId:o,paymentMethodId:x,paymentIntentId:t.id}):(a(["Payment authentication returned unexpected result"]),i(!1))}catch(r){const t=r instanceof Error?r.message:"An error occurred during payment authentication";a([t]),i(!1)}},u=async({stripeCustomerId:o,paymentMethodId:n,paymentIntentId:x})=>{i(!0),a([]);const c={...s.values,payment_method_id:n,payment_intent_id:x,stripe_customer_id:o,coupon:s.values.coupon?s.values.coupon.code:void 0,...m?{uuid:m}:{}};try{const r=await N.post(O.store().url,c);r.data&&(s.update({order_number:r.data.order_number,uuid:r.data.uuid,promo_code:r.data.promo_code,message:r.data.message,payment_method_id:n,stripe_customer_id:o}),i(!1),g("/confirmation"))}catch(r){if(i(!1),N.isAxiosError(r)&&r.response){const{data:t}=r.response;if(t.requires_action&&t.payment_intent_client_secret){await P(t.stripe_customer_id,t.payment_intent_client_secret,n||"");return}if(t.errors){const h=[];Object.values(t.errors).forEach(y=>{Array.isArray(y)&&h.push(...y)}),a(h.length>0?h:[t.message||"An error occurred"])}else t.message?a([t.message]):a(["An error occurred while processing your order"])}else{const t=r instanceof Error?r.message:"An unexpected error occurred";a([t])}window.scrollTo({top:0,behavior:"smooth"})}},_=s.values.first_payment||0,E=s.values.recurrent_payment||0,k=_>0||E>0;return!m&&(!s.values.product_id||!F(s.values,f.attributes))?e.jsx(S,{to:"/",replace:!0}):!w&&!s.values.shipping_option_id?e.jsx(S,{to:"/shipping",replace:!0}):e.jsxs(L,{sidebar:e.jsx(M,{product:f,shipping:s.values.selected_shipping,firstPayment:_}),children:[v.length>0&&e.jsx(z,{type:"error",children:v.join(", ")}),e.jsxs("div",{className:"flex flex-col gap-6 md:gap-8",children:[e.jsxs("div",{className:"flex w-full items-center gap-4",children:[e.jsx("div",{className:"flex size-12 shrink-0 items-center justify-center rounded-full border border-black",children:e.jsx(G,{className:"size-4",strokeWidth:3})}),e.jsx("p",{className:"flex-1 text-2xl",children:"Delivery"}),e.jsxs("button",{type:"button",onClick:()=>g("/shipping"),className:"flex items-center gap-1 text-sm hover:text-gray-90 hover:underline",children:[e.jsx(R,{className:"size-4"}),"Edit"]})]}),e.jsx("div",{className:"h-px bg-gray-20"}),e.jsx("div",{className:"rounded-lg border border-gray-20 bg-gray-5 p-6",children:e.jsxs("div",{className:"grid grid-cols-2 gap-6",children:[e.jsxs("div",{className:"flex flex-col gap-5",children:[!!s.values.shipping_address&&e.jsxs("div",{className:"flex flex-col gap-1",children:[e.jsx("p",{className:"text-xs",children:"Delivery Address"}),e.jsx("p",{className:"text-sm",children:s.values.shipping_method_tab==="collect_point"?[s.values.shipping_extras?.name,s.values.shipping_extras?.address].filter(Boolean).join(", "):b(s.values.shipping_address,s.values.details)})]}),!!s.values.billing_address&&e.jsxs("div",{className:"flex flex-col gap-1",children:[e.jsx("p",{className:"text-xs",children:"Billing Address"}),e.jsx("p",{className:"text-sm",children:b(s.values.billing_address,s.values.details)})]})]}),e.jsxs("div",{className:"flex flex-col gap-5",children:[s.values.selected_shipping&&e.jsxs("div",{className:"flex flex-col gap-1",children:[e.jsx("p",{className:"text-xs",children:"Delivery Method"}),e.jsx("p",{className:"text-sm",children:s.values.selected_shipping.name})]}),e.jsxs("div",{className:"flex flex-col gap-1",children:[e.jsx("p",{className:"text-xs",children:"Email Address"}),e.jsx("p",{className:"text-sm",children:s.values.details.email})]})]})]})})]}),e.jsx("div",{className:"h-px bg-gray-20"}),e.jsx(q,{stepNumber:2,title:"Payment",showMandatoryNote:!1}),k?l&&e.jsx(I,{stripe:l,children:e.jsx(B,{active:!j,onSetPaymentMethod:o=>{u({paymentMethodId:o.id})}})}):e.jsx(D,{type:"button",loading:j,onClick:()=>{u({})},className:"w-full",children:"Place order"})]})}
1export{de as default};
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.