1import{hG as I,hJ as R,hM as M,hN as _,hO as T,hL as w,j as e,hP as $}from"./vendor-data-eBPZki-Z.js";import{f as E,r}from"./vendor-react-BgtJhS2O.js";import{fh as F,fi as z,u as v,a0 as C,fj as O,fd as q,fg as L,dR as B,fk as Q,fl as A,m as D}from"./index-DTQGL8n8.js";import{gz as G,gy as H,gF as U,ev as f,eu as J}from"./vendor-zod-Bei2Z9MS.js";import{u as K}from"./useTrackScreen-BLOOZkQ_.js";import{S as V}from"./ShopHeader-FNfC5L9p.js";import{c as W,g as X}from"./checkoutContext-BJvytwtB.js";import{P as Y}from"./PaymentErrorCard-D9Q2lnnQ.js";function Z({intent:t,customer:c,address:a,estimate:i}){const n=F(),s=z(),u=E(),p=v(d=>d.user),m=I(),o=r.useMemo(()=>m.data?.items??[],[m.data?.items]),y=R(),b=r.useMemo(()=>G(o),[o]),g=r.useMemo(()=>H(o),[o]),h=r.useMemo(()=>U({subtotal:t.subtotal,taxTotal:t.taxTotal,shippingTotal:t.shippingTotal,total:t.total},i,g),[t,i,g]),[k,N]=r.useState(!1),[x,j]=r.useState(null),S=r.useRef(!1),l=r.useCallback(async()=>{if(!S.current&&!(!n||!s)){S.current=!0,j(null),N(!0);try{const{error:d}=await n.confirmPayment({elements:s,confirmParams:{return_url:`${window.location.origin}/shop/confirmation?orderId=${encodeURIComponent(t.orderId)}`,payment_method_data:{billing_details:{name:`${c.first_name} ${c.last_name}`.trim(),email:c.email,phone:c.phone,address:{line1:a.address_1,line2:a.address_2,city:a.city,state:a.state,postal_code:a.postal_code,country:a.country}}}},redirect:"if_required"});if(d){j(d.message??"Payment failed. Please try again.");return}await M(t.orderId,t.paymentIntentId,_(o,{userId:p?.id,checkoutStep:"submit",paymentMethod:"stripe"})),y.mutate(),W(),u(`/shop/confirmation?orderId=${encodeURIComponent(t.orderId)}`,{replace:!0})}catch(d){j(T(w(d,"Payment failed. Please try again.")))}finally{S.current=!1,N(!1)}}},[n,s,t,c,a,o,p?.id,y,u]);return e.jsxs("div",{className:"space-y-5",children:[e.jsx(ee,{totals:h,merchantGroups:b,isMultiMerchant:b.length>1}),e.jsxs("section",{className:"rounded-2xl border border-border-light dark:border-border-dark bg-bg dark:bg-bg-dark p-5 space-y-4",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(C,{size:16,className:"text-text-secondary dark:text-text-secondary-dark"}),e.jsx("h2",{className:"text-base font-semibold text-text dark:text-text-dark",children:"Payment details"})]}),e.jsx(O,{}),e.jsx("p",{className:"text-xs text-text-secondary dark:text-text-secondary-dark text-center",children:"Payments processed securely via Stripe."})]}),x&&e.jsx("div",{role:"alert",className:"rounded-xl border border-red-500/40 bg-red-500/10 px-4 py-3 text-sm text-red-600 dark:text-red-400",children:x}),e.jsx("button",{type:"button",onClick:l,disabled:!n||!s||k,className:"group w-full inline-flex items-center justify-center gap-2 rounded-full bg-brand text-text-on-brand font-medium py-3 px-6 transition-colors hover:bg-brand/90 disabled:opacity-50 disabled:cursor-not-allowed",children:k?"Processingâ¦":e.jsxs(e.Fragment,{children:[e.jsx(C,{size:16}),"Pay ",f(h.total),e.jsx(q,{size:16,className:"transition-transform group-hover:translate-x-0.5"})]})})]})}function ee({totals:t,merchantGroups:c,isMultiMerchant:a}){return e.jsxs("section",{className:"rounded-2xl border border-border-light dark:border-border-dark bg-bg dark:bg-bg-dark p-5 space-y-4",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(L,{size:18,className:"text-brand"}),e.jsx("h2",{className:"text-base font-semibold text-text dark:text-text-dark",children:"Order summary"})]}),c.map(i=>e.jsxs("div",{className:"space-y-1.5",children:[a&&e.jsx("p",{className:"text-xs font-semibold text-text dark:text-text-dark",children:i.merchant_name}),e.jsx("ul",{className:"space-y-1",children:i.items.map((n,s)=>{const u=J(String(n.name??"")),p=Number(n.quantity??1),m=Number(n.price??0),o=n.variant_display?String(n.variant_display):null;return e.jsxs("li",{className:"flex items-baseline justify-between gap-3 text-sm",children:[e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("p",{className:"text-text dark:text-text-dark truncate",children:u}),o&&e.jsx("p",{className:"text-xs text-text-secondary dark:text-text-secondary-dark truncate",children:o})]}),e.jsxs("span",{className:"text-text-secondary dark:text-text-secondary-dark whitespace-nowrap",children:[p>1?`${p} à `:"",f(m)]})]},n.id??n.sku_id??`${i.merchant_id}-${s}`)})})]},i.merchant_id)),e.jsxs("dl",{className:"space-y-1.5 text-sm pt-3 border-t border-border-light dark:border-border-dark",children:[e.jsx(P,{label:"Subtotal",value:f(t.subtotal)}),e.jsx(P,{label:"Shipping",value:t.shippingTotal>0?f(t.shippingTotal):"Free"}),e.jsx(P,{label:"Tax",value:f(t.taxTotal)})]}),e.jsx("div",{className:"pt-3 border-t border-border-light dark:border-border-dark",children:e.jsx(P,{label:"Total",value:f(t.total),emphasis:!0})})]})}function P({label:t,value:c,emphasis:a}){return e.jsxs("div",{className:"flex items-baseline justify-between",children:[e.jsx("dt",{className:a?"font-semibold text-text dark:text-text-dark":"text-text-secondary dark:text-text-secondary-dark",children:t}),e.jsx("dd",{className:a?"font-semibold":"",children:c})]})}function de(){K("Payment");const t=E(),c=v(l=>l.isLoggedIn),a=v(l=>l.user),{isDark:i}=B(),s=r.useRef(X()).current,u=I({enabled:c}),p=u.data?.count??0,[m,o]=r.useState(null),[y,b]=r.useState(null),[g,h]=r.useState(null),[k,N]=r.useState(0),x=!!(s.customer&&s.address);r.useEffect(()=>{x||t("/shop/cart",{replace:!0})},[x,t]),r.useEffect(()=>{if(!x||!s.customer||!s.address||!u.isSuccess||m&&k===0)return;let l=!1;return h(null),(async()=>{try{const d=await $({address:{...s.address,address_2:s.address.address_2??""},customer:s.customer,shipping_methods:s.shippingMethods,requestContext:_(u.data?.items??[],{userId:a?.id,checkoutStep:"payment-intent",paymentMethod:"stripe"})});if(l)return;o(d),b(Q(d.publishableKey))}catch(d){if(l)return;h(w(d,"Could not start payment. Please try again."))}})(),()=>{l=!0}},[x,u.isSuccess,k]);const j=r.useCallback(()=>{t("/shop/checkout")},[t]),S=r.useCallback(()=>{o(null),b(null),h(null),N(l=>l+1)},[]);return x?e.jsxs(e.Fragment,{children:[e.jsx(V,{cartCount:p,onBack:j,title:"Payment",showSearch:!1}),e.jsx("div",{className:"max-w-xl mx-auto px-4 py-6",children:g?e.jsx(Y,{message:g,onRetry:S}):m&&y?e.jsx(A,{stripe:y,options:{clientSecret:m.clientSecret,appearance:{theme:i?"night":"stripe"}},children:e.jsx(Z,{intent:m,customer:s.customer,address:s.address,estimate:s.estimate})}):e.jsx("div",{className:"flex justify-center py-12",children:e.jsx(D,{})})})]}):null}export{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.