efficient-storefront-blocks 0.110.0 → 0.111.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,3 +1,3 @@
1
- "use client";import{jsx as x}from"react/jsx-runtime";import{createContext as gr,useContext as kr,useEffect as f,useMemo as yn,useRef as d,useState as s}from"react";import{isOrderable as hn,useCart as Cr}from"../CartContext.js";import{useCurrency as br}from"../CurrencyContext.js";import{getClickIds as Nr}from"../../lib/click-ids.js";import{adConsentForOrder as Pr}from"../../lib/consent/choice.js";import{trackBeginCheckout as Sr,trackPurchase as Ar}from"../../lib/google-tag.js";import{trackMetaPurchase as vr}from"../../lib/meta-pixel.js";import{ApiError as Ge,api as be,products as k}from"../../lib/api/index.js";import{uuid as ze}from"../../lib/uuid.js";import{orderLinesForSets as Or}from"../../lib/commerce.js";import{canPersist as Er,safeSessionStorage as X}from"efficient-web-builder/format/lib/safe-storage";import{AFTERPAY_CONTEXT_KEY as Kr,AFTERPAY_RETURN as Mr,GOCARDLESS_CONTEXT_KEY as dt,KLARNA_CONTEXT_KEY as pt,ZIP_CONTEXT_KEY as Tr,ZIP_RETURN as xr,runWalletReturn as wn}from"../../lib/checkout/wallet-return.js";import{matchSubdivision as Lr}from"../../lib/checkout/match-subdivision.js";import{clearCheckoutMemory as Ir,holdsPress as Rr,parkCheckoutMemory as _r,parkForm as Fr,parkOrder as qr,parkRequest as gn,readCheckoutMemory as $r,sendableRequest as Br}from"../../lib/checkout/checkout-memory.js";import{checkoutGone as ft,checkoutWaiting as kn,BANK_WAITING as Yr,DROPPABLE_INTENT as Ur,NOT_CHECKED as mt,LOST_CHANGE as Cn,PAY_FIRST_FLOW as De,paysFirst as Hr,readIntentStatus as Gr,releaseHeldCheckout as bn,CHECKOUT_COMMITTED as zr,goodsShapeOf as Dr,refusedForGood as Nn,settlePayFirst as Wr}from"../../lib/checkout/pay-first.js";import{couponCodeForOrder as Pn,couponRefusedByOrder as Jr}from"../../lib/cart/coupon-preview.js";function Sn(o){const w=o.indexOf(`
2
- `);return w===-1?[o,""]:[o.slice(0,w),o.slice(w+1)]}function An(o,{canParkContext:w}={canParkContext:!0}){const m=o.paymentMethods,a=[];return m.includes("card")&&a.push({key:"card",title:"Card",body:null,price:x("span",{className:"font-mono text-[12px] uppercase tracking-[0.2em] text-accent",children:"VISA · MC · AMEX"})}),m.includes("paypal")&&o.paypalClientId&&a.push({key:"paypal",title:"PayPal",body:null,price:x("span",{className:"font-mono text-[12px] uppercase tracking-[0.2em] text-accent",children:"PAYPAL · CARDS"})}),m.includes("afterpay")&&a.push({key:"afterpay",title:"Afterpay",body:null,price:x("span",{className:"font-mono text-[12px] uppercase tracking-[0.2em] text-accent",children:"4 × INTEREST-FREE"})}),m.includes("square")&&o.squareApplicationId&&o.squareLocationId&&a.push({key:"square",title:"Card (Square)",body:null,price:x("span",{className:"font-mono text-[12px] uppercase tracking-[0.2em] text-accent",children:"VISA · MC · AMEX"})}),m.includes("gocardless")&&w&&a.push({key:"gocardless",title:"Bank Direct Debit",body:null,price:x("span",{className:"font-mono text-[12px] uppercase tracking-[0.2em] text-accent",children:"PAY BY BANK"})}),m.includes("zip")&&a.push({key:"zip",title:"Zip",body:null,price:x("span",{className:"font-mono text-[12px] uppercase tracking-[0.2em] text-accent",children:"PAY IN 4"})}),m.includes("klarna")&&w&&a.push({key:"klarna",title:"Klarna",body:null,price:x("span",{className:"font-mono text-[12px] uppercase tracking-[0.2em] text-accent",children:"PAY LATER"})}),m.includes("bank")&&a.push({key:"bank",title:"Bank transfer",body:null,price:x("span",{className:"font-mono text-[12px] uppercase tracking-[0.2em] text-fg-dim",children:"Invoiced"})}),a}const wo="This shop does not take payment online yet. Please contact the shop to order.";class We extends Error{}function vn(o,w){if(!o.orderNumber&&ft(w))return w.message;const m=w instanceof Ge?` (${w.message})`:"";return o.orderNumber?`Your order ${o.orderNumber} is saved, but the payment did not start${m}. Try the payment again — your order will not be placed twice.`:`Your items are held under ${o.checkoutNumber}, but the payment did not start${m}. Try the payment again — you will not be charged twice.`}const Xr=3e3,Zr=.005,On=new Set(["paypal","square","afterpay","gocardless","zip","klarna"]);function En(){const o=Pr();return{...o==="denied"?{}:Nr(),...o?{adConsent:o}:{}}}const O=o=>JSON.parse(o),go="Shipping cannot be calculated right now. Please try again.";function ko(o){return`Your order is saved, so its contact, address, delivery and discount can't change here. To change any of them, contact the shop and quote ${o}.`}function jr({site:o,logo:w,preview:m=!1}){const{items:a,totals:C,coupon:L,refuseCoupon:Mn,deliveryOptions:yt,shippingMethodId:ce,setShippingMethodId:ht,setQuoteDestination:Ne,courier:Tn,requote:Je,identify:wt,clearCapturedCart:Z,replaceItems:Xe,removeCoupon:gt,applyCoupon:xn}=Cr(),Ln=yt.find(e=>e.id===ce)?.pickupLocation??null,{country:kt,countries:se,activeCountry:Ct,formatMoney:In}=br(),[g,Pe]=s(()=>An(o)[0]?.key??null),[bt,Rn]=s(!0);f(()=>{Rn(Er(X))},[]);const[I,Ze]=s(!1),[Y,Se]=s(""),[R,Ae]=s(""),[j,ve]=s(""),[Oe,je]=s(""),[ae,ie]=s(""),[Ee,ue]=s(""),[U,le]=s(""),[_,de]=s(""),[Q,pe]=s(""),[p,fe]=s(()=>kt||se[0]?.code||""),[E,Ke]=s(""),[me,Nt]=s([]),[Qe,Ve]=s(null),[Me,V]=s(null),Pt=yn(()=>se.find(e=>e.code===p)??Ct,[se,p,Ct]),_n=Pt?.postalLabel||"Postal Code",Fn=me[0]?.divisionType||"State / Province";f(()=>{if(!p){Nt([]),Ve(p);return}Ve(null);let e=!1;return k.listCountrySubdivisions(p).then(t=>{e||(Nt(t),Ve(p),Ke(""))}),()=>{e=!0}},[p]);const St=ae.trim()!==""&&U.trim()!==""&&_.trim()!==""&&Qe===p&&(me.length===0||E!=="")?_.trim():"";f(()=>{Ne(p?{country:p,subdivision:E,postcode:St}:null)},[p,E,St,Ne]),f(()=>()=>Ne(null),[Ne]);const qn=Tn?.status==="unavailable",$n=Je,[ye,At]=s(null),[Bn,vt]=s([]),[et,Te]=s("new"),[Ot,Et]=s(!1),[tt,Yn]=s("Home"),[Un,Kt]=s(null),[Hn,Mt]=s(null),[H,xe]=s(()=>ze()),Tt=d(null),[nt,S]=s(null),[Gn,N]=s(null),[xt,Le]=s(null),[Lt,zn]=s(!1),[It,Dn]=s(!1),[F,ee]=s(null),[Wn,te]=s(!1),[y,P]=s(null),Rt=!!y?.orderNumber,Jn=Rt||I,[Xn,K]=s(null),[Zn,jn]=s(!1),[Qn,_t]=s(!1),[Vn,er]=s(!1),[tr,Ft]=s(!1),[qt,nr]=s(!1),[rr,rt]=s(!1),[he,$t]=s(null),q=d(null),G=d(null),ot=d(!1),z=d(a),M=d(null),$=d(null),Bt=!!(nt||he&&he.kind!=="processing"||qt||Lt||It||xt&&F?.orderNumber);f(()=>{Bt&&(Xe([]),gt())},[Bt,Xe,gt]);const Yt=d(!1);f(()=>{m||Yt.current||!a.some(hn)||(Yt.current=!0,Sr({lines:a,currency:C.currency,value:C.subtotal-C.discount,coupon:L?.valid?L.code:void 0}))},[a,C,L,m]),f(()=>{wt(Y,R.trim()||void 0)},[Y,R,wt]);const Ut=d(null),[Ie,or]=s(null);f(()=>{const e=Ut.current;if(!Ie||!e)return;const t=()=>e.style.setProperty("--sf-checkout-header-h",`${Ie.offsetHeight}px`);t();const n=new ResizeObserver(t);return n.observe(Ie),()=>n.disconnect()},[Ie]),f(()=>{const e=n=>({setConfirming:n,land:S,markPaid:()=>te(!0),note:K,fail:N,clearCart:Z}),t={search:window.location.search,storage:X,scrubQuery:()=>window.history.replaceState(null,"",window.location.pathname)};wn(Mr,{...t,capture:k.captureAfterpayPayment,page:e(jn)}),wn(xr,{...t,capture:k.captureZipPayment,page:e(er)})},[]),f(()=>{const t=new URLSearchParams(window.location.search).get("gocardless");if(t!=="confirm"&&t!=="cancel")return;const n=X.getItem(dt);if(X.removeItem(dt),window.history.replaceState(null,"",window.location.pathname),!n)return;let c;try{c=JSON.parse(n)}catch{return}if(Z(),t==="cancel"){K("The direct debit was not set up — our team will follow up on payment."),S(c.confirmation);return}_t(!0),k.completeGocardlessPayment({idempotencyKey:c.idempotencyKey}).then(r=>{r.status==="paid"?te(!0):r.status==="declined"?K("The direct debit was declined — our team will follow up on payment."):K("Your direct debit is set up — the payment is collecting and will clear in a few days.")}).catch(()=>{K("We could not confirm the direct debit — our team will follow up on payment.")}).finally(()=>{S(c.confirmation),_t(!1)})},[]),f(()=>{const e=new URLSearchParams(window.location.search),t=e.get("klarna");if(t!=="confirm"&&t!=="cancel")return;const n=X.getItem(pt);X.removeItem(pt);const c=e.get("authorization_token");if(window.history.replaceState(null,"",window.location.pathname),!n)return;let r;try{r=JSON.parse(n)}catch{return}if(Z(),t==="cancel"||!c){K("The Klarna payment was not completed — our team will follow up on payment."),S(r.confirmation);return}Ft(!0),k.captureKlarnaPayment({idempotencyKey:r.idempotencyKey,authorizationToken:c}).then(u=>{u.status==="paid"?te(!0):u.status==="declined"?K("Klarna declined the payment — our team will follow up on payment."):K("Your Klarna payment is being reviewed — we'll confirm the outcome shortly.")}).catch(()=>{K("We could not confirm the Klarna payment — our team will follow up on payment.")}).finally(()=>{S(r.confirmation),Ft(!1)})},[]);function Ht(e){const[t,n]=Sn(e.address);ie(t),ue(n),le(e.city),de(e.zip_code),e.country&&fe(e.country),e.phone&&pe(e.phone),V({country:e.country||null,state:e.state??""})}f(()=>{if(Me){if((Me.country||p)!==p){V(null);return}Qe===p&&(Ke(Lr(p,Me.state,me)),V(null))}},[Me,p,Qe,me]),f(()=>{let e=!1;return(async()=>{try{const[t,n,c]=await Promise.all([be.me(),be.myProfile().catch(()=>null),be.myAddresses().catch(()=>[])]);if(e)return;At(t);const r=c.filter(h=>h.is_active);vt(r),Se(t.email);const u=(n?.contact_name??"").split(/\s+/);Ae(t.first_name||u[0]||""),ve(t.last_name||u.slice(1).join(" "));const i=t.phone||n?.phone;i&&pe(i);const l=r.find(h=>h.id===t.default_delivery_location)??r[0];if(l)Te(l.id),Ht(l);else if(n){const[h,He]=Sn(n.address??"");ie(h),ue(He),le(n.city??""),de(n.zip_code??""),n.country&&fe(n.country),V({country:n.country||null,state:n.state??""})}Ye.current&&jt(Ye.current,!1)}catch{}})(),()=>{e=!0}},[]);function cr(){be.logout(),we.current=!0,Ye.current=null,Be.current=null,ge(),At(null),vt([]),Te("new"),Et(!1),Se(""),Ae(""),ve(""),je(""),ie(""),ue(""),le(""),de(""),pe(""),fe(kt||se[0]?.code||""),Ke(""),V(null)}const ne=yn(()=>An(o,{canParkContext:bt}),[o,bt]);f(()=>{ne.some(e=>e.key===g)||Pe(ne[0]?.key??null)},[ne,g]);const sr=ne.length===0,Re=Ee.trim()?`${ae}
3
- ${Ee.trim()}`:ae,ar=Dr({email:Y,firstName:R,lastName:j,company:Oe.trim(),phone:Q,address:Re,city:U,subdivision:E,postcode:_,country:p,lines:a.map(e=>[e.id,e.qty]),shippingMethodId:ce,couponCode:Pn(L),currency:C.currency,shopperId:ye?.id??null}),b=JSON.stringify([ar,g]),A=d(null),ct=d(null),_e=d(!1),B=d(!1),re=d(null),Fe=d(!1),v=d(b);v.current=b;const Gt=d(I);Gt.current=I;const qe=d(null);f(()=>{const e=()=>{const t=qe.current;t&&(qe.current=null,P(t),Ze(!1))};return window.addEventListener("pageshow",e),()=>window.removeEventListener("pageshow",e)},[]);function $e(e,t,n,c){const r={idempotencyKey:t,confirmation:n};X.setItem(e,JSON.stringify(r)),window.location.assign(c),qe.current=n}async function zt(e){Ze(!0);try{await e()}finally{qe.current||Ze(!1)}}const Dt=d(!1),Wt=!!(nt||he&&he.kind!=="processing");f(()=>{Wt&&(Dt.current=!0,ge())},[Wt]);const Be=d(null),we=d(!1),st=d(null);function ge(){st.current=null,Ir()}const Ye=d(null),[oe,ir]=s(!1);function at(e){if(Dt.current||m||we.current)return;const t=M.current,n={key:e,authed:ot.current,parkedAt:st.current??=Date.now(),lastPress:t&&{key:t.key,request:gn(t.request),lines:t.lines,goods:O(t.shape)[0],plainPressed:!!t.plainMethod,plainLines:t.plainLines,plainGoods:O(t.plainShape)[0]},keptCardKey:$.current,placedGoods:A.current===null?null:O(A.current)[0],unpaidOrder:Ue.current&&qr(Ue.current),placedRequest:G.current&&gn(G.current),lines:a.length>0?a:z.current,form:Fr({email:Y,firstName:R,lastName:j,company:Oe,address1:ae,address2:Ee,city:U,postcode:_,phone:Q,country:p,subdivision:E,selectedAddressId:et,shippingMethodId:ce,couponCode:L?.valid?L.code:null})};Rr(n)?_r(n):ge()}const Ue=d(y);Ue.current=y;const Jt=d(g);Jt.current=g;function it(e){return{...Br(e),...En(),...e.payFirst?{checkoutFlow:De}:{}}}function ur(e,t){let n=e.request.payFirst?"":null,c=e.plainPressed?null:"";const r=()=>Jt.current??"";return{key:e.key,send:()=>t(it(e.request)),request:it(e.request),lines:e.lines,shape:JSON.stringify([e.goods,null]),get method(){return n??r()},set method(u){n=u},get plainMethod(){return c??r()},set plainMethod(u){c=u},plainLines:e.plainLines,plainShape:JSON.stringify([e.plainGoods,null])}}const[lr,dr]=s(!1),Xt=lr?!C.quoted||C.serverSubtotal===null?"waiting":Math.abs(C.serverSubtotal-C.subtotal)<Zr?"same":"changed":null,ut=!y&&Xt==="waiting",pr=ut?{...C,repricing:!0}:C,Zt=ut&&C.quoteFailed;f(()=>{if(!Zt)return;const e=setInterval(Je,Xr);return()=>clearInterval(e)},[Zt,Je]);function jt(e,t=!0){Se(e.email),Ae(e.firstName),ve(e.lastName),je(e.company),ie(e.address1),ue(e.address2),le(e.city),de(e.postcode),pe(e.phone),e.country&&fe(e.country),V({country:e.country||null,state:e.subdivision}),Te(e.selectedAddressId),e.shippingMethodId&&ht(e.shippingMethodId),t&&(Be.current=e.couponCode)}f(()=>{let e=m?null:$r();if(e&&a.length>0&&(ge(),e=null),e){const t=e.authed?k.createOrderAuthed:k.createOrder;xe(e.key),st.current=e.parkedAt,M.current=e.lastPress&&ur(e.lastPress,t),$.current=e.keptCardKey,A.current=e.placedGoods===null?null:JSON.stringify([e.placedGoods,null]),ot.current=e.authed;const n=e.placedRequest&&it(e.placedRequest);G.current=n,q.current=n?()=>t(n):null,e.unpaidOrder&&P(e.unpaidOrder),e.lines.length>0&&(Xe(e.lines),z.current=e.lines,dr(!0)),e.form&&(Ye.current=e.form,jt(e.form))}ir(!0)},[]),f(()=>{!oe||a.length>0||Ue.current||I||(we.current=!0,ge())},[oe,a.length]),f(()=>{const e=Be.current;!oe||!e||a.length===0||(Be.current=null,xn(e,Y||void 0))},[oe,a.length]),f(()=>{!oe||I||at(H)},[oe,I,H,y]);const D=d(null);f(()=>{Gt.current||(b!==D.current&&(D.current=null),!(!B.current||!y||y.orderNumber)&&(b===A.current||b===D.current||zt(()=>Qt(y))))},[b,y]);async function Qt(e){if(Fe.current)return null;Fe.current=!0;try{const t=re.current?await Gr(re.current):"none";if(t==="succeeded"||t==="processing")return B.current=!1,P(null),T("card"),t==="succeeded"?await W(void 0,e):an(e),null;if(t===void 0||!Ur.has(t))return D.current=v.current,P(e),N(t==="requires_action"?Yr:mt),null;const n=await bn(H);if(n==="committed")return B.current=!1,P(null),T("card"),await W(void 0,e),null;if(n!=="released")return D.current=v.current,P(e),N(mt),null;B.current=!1,re.current=null,D.current=null,N(null),P(null);const c=ze();return xe(c),c}finally{Fe.current=!1}}async function fr(){m||I||Fe.current||await zt(mr)}async function mr(){if(y){if((B.current?b!==A.current:ke())&&!y.orderNumber){const c=await Qt(y);c&&v.current===b&&await Vt(c);return}N(null),_e.current=!1,await lt();const t=O(v.current)[1],n=y.orderNumber?t:"card";if(n&&On.has(n)&&ke()&&O(v.current)[0]!==ct.current){en(y);return}T(n),n!==g&&Pe(n),await un(y,n,!y.orderNumber);return}await Vt(H)}async function Vt(e){if(a.length===0||C.repricing||ut||!g||!ne.some(i=>i.key===g))return;const t=a.filter(hn).flatMap(i=>Or(i.components,i.qty));if(t.length===0){N("Pick a size on each wheel's product page before checking out.");return}N(null);let n,c=e,r=g,u=!1;try{const i=ye?k.createOrderAuthed:k.createOrder,l={customer:{email:Y,name:`${R} ${j}`.trim(),phone:Q.trim()||void 0,companyName:Oe.trim()||void 0,address:Re,city:U,state:E||void 0,zipCode:_,country:p},items:t,currency:C.currency,idempotencyKey:e,shippingMethodId:ce??void 0,couponCode:Pn(L),...En(),...Hr(g)?{checkoutFlow:De}:{}};q.current=()=>i(l),G.current=l,ot.current=!!ye,we.current=!1,Mt(null),ct.current=null,_e.current=!1,re.current=null,B.current=!1,D.current=null,A.current=b,z.current=a;const h=M.current,He=h?.key===l.idempotencyKey&&(h.shape!==b&&(!!l.checkoutFlow||!!h.method||!!h.plainMethod)||!!l.checkoutFlow&&!!h.plainMethod);He&&($.current=l.idempotencyKey);const pn=on(l,i),fn=He||!l.checkoutFlow&&$.current===l.idempotencyKey,mn=!pn&&!fn&&!l.checkoutFlow&&!!h&&!h.method;mn&&(h.plainMethod=g,h.plainLines=a,h.plainShape=b,at(l.idempotencyKey));const J=await(fn?nn(l,i):i(l).then(Ce=>({answer:Ce,request:l})).catch(Ce=>(pn?tn(Ce,l.idempotencyKey):mn&&Nn(Ce)&&(h.plainMethod=""),yr(Ce,l,i))));if(!J)return;n=J.answer,c=J.request.idempotencyKey,r=J.method??r,T(r),u=ke()||r!==O(v.current)[1],J.method&&J.method!==g&&Pe(J.method),n.orderNumber&&(cn(n),Z()),await lt()}catch(i){const l=Jr(i);l?(Mn(l),N(`${l} Your order has not been placed. Place it again to continue without the code.`)):i instanceof We?N(mt):N(i instanceof Ge?i.message:"Could not place the order. Please try again.");return}if(r&&On.has(r)&&(u||ke())){en(n);return}await un(n,r,!1,c)}function en(e){ct.current=O(v.current)[0],N(`${vn(e,null)} ${Cn}`),P(e)}function tn(e,t){Nn(e)&&!kn(e)&&M.current?.key===t&&(M.current=null)}async function yr(e,t,n){if(ft(e))return rn(t,n);if(!kn(e))throw e;return $.current=t.idempotencyKey,nn(t,n,!0)}async function nn(e,t,n=!1){const c=await bn(e.idempotencyKey);if(c==="released")return rn(e,t);if(c!=="committed")throw new We;const r=M.current?.key===e.idempotencyKey?M.current:null;if(z.current=r?.lines??a,r?.method&&!n){$.current=null,q.current=r.send,G.current=r.request;const l=await r.send().catch(()=>{throw new We});return A.current=r.shape,{answer:l,request:e,method:r.method}}const u=r&&!r.method?r.send:()=>t({...e,checkoutFlow:De});q.current=u,G.current=r&&!r.method?r.request:{...e,checkoutFlow:De};const i=await u().catch(()=>null);if(!i&&r?.plainMethod)throw new We;return i?.orderNumber&&i.status!==zr?($.current=null,r?.plainMethod&&(z.current=r.plainLines),r&&(A.current=r.plainMethod?r.plainShape:r.shape),{answer:i,request:e,method:r?.plainMethod||void 0}):(r&&(A.current=r.shape),T("card"),await sn("",i?async()=>i:()=>Promise.reject(new Error("The order request did not answer."))),await lt(),null)}function ke(){const e=A.current;return e!==null&&O(e)[0]!==O(v.current)[0]}function T(e){e!==O(v.current)[1]&&(_e.current=!0),Mt(_e.current||ke()?Cn:null)}async function rn(e,t){const n={...e,idempotencyKey:ze()};$.current=null,xe(n.idempotencyKey),q.current=()=>t(n),G.current=n,on(n,t);try{return{answer:await t(n),request:n}}catch(c){throw tn(c,n.idempotencyKey),c}}function on(e,t){return M.current?.key===e.idempotencyKey?!1:(M.current={key:e.idempotencyKey,send:()=>t(e),request:e,lines:a,shape:b,method:e.checkoutFlow?"":g??"",plainMethod:"",plainLines:a,plainShape:b},we.current=!1,at(e.idempotencyKey),!0)}function cn(e){Ar({confirmation:e,lines:z.current,adsSendTo:o.googleAdsId&&o.googleAdsConversionLabel?`${o.googleAdsId}/${o.googleAdsConversionLabel}`:null}),vr({confirmation:e,lines:z.current})}async function W(e,t=F){if(!t)return;const n=e?async()=>e:q.current;if(t.orderNumber||!n){te(!0),S(t);return}await sn(t.checkoutNumber,n)}async function sn(e,t){Z(),await Wr({checkoutNumber:e,resend:t,page:{setConfirming:nr,land:S,markPaid:()=>te(!0),track:cn,unplaced:$t}})}function an(e=F){if(e){if(e.orderNumber){S(e);return}Z(),$t({kind:"processing",checkoutNumber:e.checkoutNumber})}}async function lt(){const e=JSON.stringify([tt.trim(),R,j,Q.trim(),Re,U,E,_,p]);if(!(!ye||!Ot||et!=="new"||Tt.current===e))try{await be.createAddress({label:tt.trim()||"Home",contact_name:`${R} ${j}`.trim(),phone:Q.trim(),address:Re,city:U,zip_code:_,state:E,country:p}),Tt.current=e,Kt("Address saved to your account.")}catch{Kt("We couldn't save the address to your account — you can add it under Account → Addresses.")}}async function un(e,t=g,n=!1,c=H){P(null);try{if(t==="card"&&o.paymentMethods.includes("card")){const r=await k.createPaymentIntent({idempotencyKey:c});re.current=r;let u=e;if(n){const i=await q.current?.().catch(()=>null);if(i?.orderNumber){T("card"),await W(i,e);return}u=ln(e,i)??{...e,expiresAt:null}}T("card"),ee(u),rt(!1),Le(r)}else if(t==="paypal"&&o.paymentMethods.includes("paypal"))ee(e),zn(!0);else if(t==="afterpay"&&o.paymentMethods.includes("afterpay")){const r=window.location.origin,u=await k.createAfterpayCheckout({idempotencyKey:c,confirmUrl:`${r}/checkout?afterpay=confirm`,cancelUrl:`${r}/checkout?afterpay=cancel`});$e(Kr,c,e,u.redirectCheckoutUrl);return}else if(t==="square"&&o.paymentMethods.includes("square"))ee(e),Dn(!0);else if(t==="gocardless"&&o.paymentMethods.includes("gocardless")){const r=window.location.origin,u=await k.createGocardlessBillingRequest({idempotencyKey:c,confirmUrl:`${r}/checkout?gocardless=confirm`,cancelUrl:`${r}/checkout?gocardless=cancel`});$e(dt,c,e,u.authorisationUrl);return}else if(t==="zip"&&o.paymentMethods.includes("zip")){const r=window.location.origin,u=await k.createZipCheckout({idempotencyKey:c,redirectUrl:`${r}/checkout?zip=return`});$e(Tr,c,e,u.redirectUrl);return}else if(t==="klarna"&&o.paymentMethods.includes("klarna")){const r=window.location.origin,u=await k.createKlarnaCheckout({idempotencyKey:c,confirmUrl:`${r}/checkout?klarna=confirm`,cancelUrl:`${r}/checkout?klarna=cancel`});$e(pt,c,e,u.redirectUrl);return}else T(t),S(e)}catch(r){if((n||t==="card")&&r instanceof Ge&&r.status===409){T(t),await W(void 0,e);return}dn(e,r)}}function ln(e,t){return t&&!t.orderNumber&&t.status==="open"&&t.checkoutNumber===e.checkoutNumber?t:null}function dn(e,t){N(vn(e,t)),!e.orderNumber&&ft(t)?(B.current=!1,xe(ze())):P(e)}async function hr(e){if(!F)return;const t=F;try{const n=await k.createPaymentIntent({idempotencyKey:H}),c=await q.current?.().catch(()=>null);if(c?.orderNumber){await W(c);return}const r=ln(t,c);ee(r??{...t,expiresAt:null}),rt(e&&r!==null),re.current=n,Le(n)}catch(n){if(n instanceof Ge&&n.status===409){await W();return}Le(null),ee(null),dn(t,n)}}function wr(){F&&(B.current=!0,P(F),Le(null),ee(null),rt(!1))}return{site:o,logo:w,items:a,totals:pr,coupon:L,deliveryOptions:yt,courierUnavailable:qn,retryCourier:$n,shippingMethodId:ce,setShippingMethodId:ht,pickupLocation:Ln,servedCountries:se,formatMoney:In,payChoice:g,setPayChoice:Pe,placing:I,email:Y,setEmail:Se,firstName:R,setFirstName:Ae,lastName:j,setLastName:ve,company:Oe,setCompany:je,address1:ae,setAddress1:ie,address2:Ee,setAddress2:ue,city:U,setCity:le,postcode:_,setPostcode:de,phone:Q,setPhone:pe,country:p,setCountry:fe,subdivision:E,setSubdivision:Ke,subdivisions:me,destination:Pt,postcodeLabel:_n,subdivisionLabel:Fn,me:ye,savedAddresses:Bn,selectedAddressId:et,setSelectedAddressId:Te,saveAddress:Ot,setSaveAddress:Et,saveLabel:tt,setSaveLabel:Yn,addressSaveNote:Un,lostChangeNote:Hn,idemKey:H,confirmation:nt,setConfirmation:S,orderError:Gn,payment:xt,paypalStep:Lt,squareStep:It,pendingConf:F,paid:Wn,setPaid:te,unpaidOrder:y,orderLocked:Rt,formLocked:Jn,restoredPrices:Xt,payNote:Xn,afterpayConfirming:Zn,gocardlessConfirming:Qn,zipConfirming:Vn,klarnaConfirming:tr,cardConfirming:qt,checkoutResult:he,confirmCardPayment:W,cardStillProcessing:an,renewCardPayment:hr,holdRenewed:rr,leaveCardPayment:wr,checkoutRootRef:Ut,setCheckoutHeaderEl:or,fillFromAddress:Ht,checkoutSignOut:cr,payOptions:ne,noPaymentMethod:sr,placeOrder:fr}}const Kn=gr(null);function Co({children:o,...w}){const m=jr(w);return x(Kn.Provider,{value:m,children:o})}function bo(){const o=kr(Kn);if(!o)throw new Error("useCheckout must be used inside CheckoutStateProvider");return o}export{Co as CheckoutStateProvider,wo as NO_PAYMENT_METHOD_NOTE,go as SHIPPING_RETRY_NOTE,An as buildPayOptions,vn as paymentNotStartedMessage,ko as placedOrderLockNote,bo as useCheckout};
1
+ "use client";import{jsx as x}from"react/jsx-runtime";import{createContext as Cr,useContext as br,useEffect as f,useMemo as gn,useRef as d,useState as s}from"react";import{isOrderable as wn,useCart as Nr}from"../CartContext.js";import{useCurrency as Pr}from"../CurrencyContext.js";import{getClickIds as Sr}from"../../lib/click-ids.js";import{adConsentForOrder as Ar}from"../../lib/consent/choice.js";import{trackBeginCheckout as vr,trackPurchase as Or}from"../../lib/google-tag.js";import{trackMetaPurchase as Er}from"../../lib/meta-pixel.js";import{ApiError as De,api as Ne,products as k}from"../../lib/api/index.js";import{uuid as We}from"../../lib/uuid.js";import{orderLinesForSets as Kr}from"../../lib/commerce.js";import{canPersist as Mr,safeSessionStorage as X}from"efficient-web-builder/format/lib/safe-storage";import{AFTERPAY_CONTEXT_KEY as Tr,AFTERPAY_RETURN as xr,GOCARDLESS_CONTEXT_KEY as ft,KLARNA_CONTEXT_KEY as mt,ZIP_CONTEXT_KEY as Lr,ZIP_RETURN as Ir,parkedLostChange as kn,runWalletReturn as Cn}from"../../lib/checkout/wallet-return.js";import{matchSubdivision as Rr}from"../../lib/checkout/match-subdivision.js";import{clearCheckoutMemory as _r,holdsPress as Fr,parkCheckoutMemory as qr,parkForm as $r,parkOrder as Br,parkRequest as bn,readCheckoutMemory as Yr,sendableRequest as Ur}from"../../lib/checkout/checkout-memory.js";import{checkoutGone as yt,checkoutWaiting as Nn,BANK_WAITING as Hr,DROPPABLE_INTENT as Gr,NOT_CHECKED as ht,LOST_CHANGE as Pe,PAY_FIRST_FLOW as Je,paysFirst as zr,readIntentStatus as Dr,releaseHeldCheckout as Pn,CHECKOUT_COMMITTED as Wr,goodsShapeOf as Jr,refusedForGood as Sn,settlePayFirst as Xr}from"../../lib/checkout/pay-first.js";import{couponCodeForOrder as An,couponRefusedByOrder as Zr}from"../../lib/cart/coupon-preview.js";function vn(c){const g=c.indexOf(`
2
+ `);return g===-1?[c,""]:[c.slice(0,g),c.slice(g+1)]}function On(c,{canParkContext:g}={canParkContext:!0}){const m=c.paymentMethods,a=[];return m.includes("card")&&a.push({key:"card",title:"Card",body:null,price:x("span",{className:"font-mono text-[12px] uppercase tracking-[0.2em] text-accent",children:"VISA · MC · AMEX"})}),m.includes("paypal")&&c.paypalClientId&&a.push({key:"paypal",title:"PayPal",body:null,price:x("span",{className:"font-mono text-[12px] uppercase tracking-[0.2em] text-accent",children:"PAYPAL · CARDS"})}),m.includes("afterpay")&&a.push({key:"afterpay",title:"Afterpay",body:null,price:x("span",{className:"font-mono text-[12px] uppercase tracking-[0.2em] text-accent",children:"4 × INTEREST-FREE"})}),m.includes("square")&&c.squareApplicationId&&c.squareLocationId&&a.push({key:"square",title:"Card (Square)",body:null,price:x("span",{className:"font-mono text-[12px] uppercase tracking-[0.2em] text-accent",children:"VISA · MC · AMEX"})}),m.includes("gocardless")&&g&&a.push({key:"gocardless",title:"Bank Direct Debit",body:null,price:x("span",{className:"font-mono text-[12px] uppercase tracking-[0.2em] text-accent",children:"PAY BY BANK"})}),m.includes("zip")&&a.push({key:"zip",title:"Zip",body:null,price:x("span",{className:"font-mono text-[12px] uppercase tracking-[0.2em] text-accent",children:"PAY IN 4"})}),m.includes("klarna")&&g&&a.push({key:"klarna",title:"Klarna",body:null,price:x("span",{className:"font-mono text-[12px] uppercase tracking-[0.2em] text-accent",children:"PAY LATER"})}),m.includes("bank")&&a.push({key:"bank",title:"Bank transfer",body:null,price:x("span",{className:"font-mono text-[12px] uppercase tracking-[0.2em] text-fg-dim",children:"Invoiced"})}),a}const ko="This shop does not take payment online yet. Please contact the shop to order.";class Xe extends Error{}function En(c,g){if(!c.orderNumber&&yt(g))return g.message;const m=g instanceof De?` (${g.message})`:"";return c.orderNumber?`Your order ${c.orderNumber} is saved, but the payment did not start${m}. Try the payment again — your order will not be placed twice.`:`Your items are held under ${c.checkoutNumber}, but the payment did not start${m}. Try the payment again — you will not be charged twice.`}const jr=3e3,Qr=.005,Kn=new Set(["paypal","square","afterpay","gocardless","zip","klarna"]);function Mn(){const c=Ar();return{...c==="denied"?{}:Sr(),...c?{adConsent:c}:{}}}const O=c=>JSON.parse(c),Co="Shipping cannot be calculated right now. Please try again.";function bo(c){return`Your order is saved, so its contact, address, delivery and discount can't change here. To change any of them, contact the shop and quote ${c}.`}function Vr({site:c,logo:g,preview:m=!1}){const{items:a,totals:C,coupon:L,refuseCoupon:xn,deliveryOptions:gt,shippingMethodId:ce,setShippingMethodId:wt,setQuoteDestination:Se,courier:Ln,requote:Ze,identify:kt,clearCapturedCart:Z,replaceItems:je,removeCoupon:Ct,applyCoupon:In}=Nr(),Rn=gt.find(e=>e.id===ce)?.pickupLocation??null,{country:bt,countries:se,activeCountry:Nt,formatMoney:_n}=Pr(),[w,Ae]=s(()=>On(c)[0]?.key??null),[Pt,Fn]=s(!0);f(()=>{Fn(Mr(X))},[]);const[I,Qe]=s(!1),[Y,ve]=s(""),[R,Oe]=s(""),[j,Ee]=s(""),[Ke,Ve]=s(""),[ae,ie]=s(""),[Me,ue]=s(""),[U,le]=s(""),[_,de]=s(""),[Q,pe]=s(""),[p,fe]=s(()=>bt||se[0]?.code||""),[E,Te]=s(""),[me,St]=s([]),[et,tt]=s(null),[xe,V]=s(null),At=gn(()=>se.find(e=>e.code===p)??Nt,[se,p,Nt]),qn=At?.postalLabel||"Postal Code",$n=me[0]?.divisionType||"State / Province";f(()=>{if(!p){St([]),tt(p);return}tt(null);let e=!1;return k.listCountrySubdivisions(p).then(t=>{e||(St(t),tt(p),Te(""))}),()=>{e=!0}},[p]);const vt=ae.trim()!==""&&U.trim()!==""&&_.trim()!==""&&et===p&&(me.length===0||E!=="")?_.trim():"";f(()=>{Se(p?{country:p,subdivision:E,postcode:vt}:null)},[p,E,vt,Se]),f(()=>()=>Se(null),[Se]);const Bn=Ln?.status==="unavailable",Yn=Ze,[ye,Ot]=s(null),[Un,Et]=s([]),[nt,Le]=s("new"),[Kt,Mt]=s(!1),[rt,Hn]=s("Home"),[Gn,Tt]=s(null),[zn,he]=s(null),[H,Ie]=s(()=>We()),xt=d(null),[ot,S]=s(null),[Dn,N]=s(null),[Lt,Re]=s(null),[It,Wn]=s(!1),[Rt,Jn]=s(!1),[F,ee]=s(null),[Xn,te]=s(!1),[y,P]=s(null),_t=!!y?.orderNumber,Zn=_t||I,[jn,K]=s(null),[Qn,Vn]=s(!1),[er,Ft]=s(!1),[tr,nr]=s(!1),[rr,qt]=s(!1),[$t,or]=s(!1),[cr,ct]=s(!1),[ge,Bt]=s(null),q=d(null),G=d(null),st=d(!1),z=d(a),M=d(null),$=d(null),Yt=!!(ot||ge&&ge.kind!=="processing"||$t||It||Rt||Lt&&F?.orderNumber);f(()=>{Yt&&(je([]),Ct())},[Yt,je,Ct]);const Ut=d(!1);f(()=>{m||Ut.current||!a.some(wn)||(Ut.current=!0,vr({lines:a,currency:C.currency,value:C.subtotal-C.discount,coupon:L?.valid?L.code:void 0}))},[a,C,L,m]),f(()=>{kt(Y,R.trim()||void 0)},[Y,R,kt]);const Ht=d(null),[_e,sr]=s(null);f(()=>{const e=Ht.current;if(!_e||!e)return;const t=()=>e.style.setProperty("--sf-checkout-header-h",`${_e.offsetHeight}px`);t();const n=new ResizeObserver(t);return n.observe(_e),()=>n.disconnect()},[_e]),f(()=>{const e=n=>({setConfirming:n,land:S,markPaid:()=>te(!0),note:K,fail:N,clearCart:Z,lostChange:()=>he(Pe)}),t={search:window.location.search,storage:X,scrubQuery:()=>window.history.replaceState(null,"",window.location.pathname)};Cn(xr,{...t,capture:k.captureAfterpayPayment,page:e(Vn)}),Cn(Ir,{...t,capture:k.captureZipPayment,page:e(nr)})},[]),f(()=>{const t=new URLSearchParams(window.location.search).get("gocardless");if(t!=="confirm"&&t!=="cancel")return;const n=X.getItem(ft);if(X.removeItem(ft),window.history.replaceState(null,"",window.location.pathname),!n)return;let o;try{o=JSON.parse(n)}catch{return}if(Z(),kn(o)&&he(Pe),t==="cancel"){K("The direct debit was not set up — our team will follow up on payment."),S(o.confirmation);return}Ft(!0),k.completeGocardlessPayment({idempotencyKey:o.idempotencyKey}).then(r=>{r.status==="paid"?te(!0):r.status==="declined"?K("The direct debit was declined — our team will follow up on payment."):K("Your direct debit is set up — the payment is collecting and will clear in a few days.")}).catch(()=>{K("We could not confirm the direct debit — our team will follow up on payment.")}).finally(()=>{S(o.confirmation),Ft(!1)})},[]),f(()=>{const e=new URLSearchParams(window.location.search),t=e.get("klarna");if(t!=="confirm"&&t!=="cancel")return;const n=X.getItem(mt);X.removeItem(mt);const o=e.get("authorization_token");if(window.history.replaceState(null,"",window.location.pathname),!n)return;let r;try{r=JSON.parse(n)}catch{return}if(Z(),kn(r)&&he(Pe),t==="cancel"||!o){K("The Klarna payment was not completed — our team will follow up on payment."),S(r.confirmation);return}qt(!0),k.captureKlarnaPayment({idempotencyKey:r.idempotencyKey,authorizationToken:o}).then(u=>{u.status==="paid"?te(!0):u.status==="declined"?K("Klarna declined the payment — our team will follow up on payment."):K("Your Klarna payment is being reviewed — we'll confirm the outcome shortly.")}).catch(()=>{K("We could not confirm the Klarna payment — our team will follow up on payment.")}).finally(()=>{S(r.confirmation),qt(!1)})},[]);function Gt(e){const[t,n]=vn(e.address);ie(t),ue(n),le(e.city),de(e.zip_code),e.country&&fe(e.country),e.phone&&pe(e.phone),V({country:e.country||null,state:e.state??""})}f(()=>{if(xe){if((xe.country||p)!==p){V(null);return}et===p&&(Te(Rr(p,xe.state,me)),V(null))}},[xe,p,et,me]),f(()=>{let e=!1;return(async()=>{try{const[t,n,o]=await Promise.all([Ne.me(),Ne.myProfile().catch(()=>null),Ne.myAddresses().catch(()=>[])]);if(e)return;Ot(t);const r=o.filter(h=>h.is_active);Et(r),ve(t.email);const u=(n?.contact_name??"").split(/\s+/);Oe(t.first_name||u[0]||""),Ee(t.last_name||u.slice(1).join(" "));const i=t.phone||n?.phone;i&&pe(i);const l=r.find(h=>h.id===t.default_delivery_location)??r[0];if(l)Le(l.id),Gt(l);else if(n){const[h,ze]=vn(n.address??"");ie(h),ue(ze),le(n.city??""),de(n.zip_code??""),n.country&&fe(n.country),V({country:n.country||null,state:n.state??""})}He.current&&Qt(He.current,!1)}catch{}})(),()=>{e=!0}},[]);function ar(){Ne.logout(),we.current=!0,He.current=null,Ue.current=null,ke(),Ot(null),Et([]),Le("new"),Mt(!1),ve(""),Oe(""),Ee(""),Ve(""),ie(""),ue(""),le(""),de(""),pe(""),fe(bt||se[0]?.code||""),Te(""),V(null)}const ne=gn(()=>On(c,{canParkContext:Pt}),[c,Pt]);f(()=>{ne.some(e=>e.key===w)||Ae(ne[0]?.key??null)},[ne,w]);const ir=ne.length===0,Fe=Me.trim()?`${ae}
3
+ ${Me.trim()}`:ae,ur=Jr({email:Y,firstName:R,lastName:j,company:Ke.trim(),phone:Q,address:Fe,city:U,subdivision:E,postcode:_,country:p,lines:a.map(e=>[e.id,e.qty]),shippingMethodId:ce,couponCode:An(L),currency:C.currency,shopperId:ye?.id??null}),b=JSON.stringify([ur,w]),A=d(null),at=d(null),qe=d(!1),B=d(!1),re=d(null),$e=d(!1),v=d(b);v.current=b;const zt=d(I);zt.current=I;const Be=d(null);f(()=>{const e=()=>{const t=Be.current;t&&(Be.current=null,P(t),Qe(!1))};return window.addEventListener("pageshow",e),()=>window.removeEventListener("pageshow",e)},[]);function Ye(e,t,n,o){const r={idempotencyKey:t,confirmation:n};on()&&(r.lostChange=!0),X.setItem(e,JSON.stringify(r)),window.location.assign(o),Be.current=n}async function Dt(e){Qe(!0);try{await e()}finally{Be.current||Qe(!1)}}const Wt=d(!1),Jt=!!(ot||ge&&ge.kind!=="processing");f(()=>{Jt&&(Wt.current=!0,ke())},[Jt]);const Ue=d(null),we=d(!1),it=d(null);function ke(){it.current=null,_r()}const He=d(null),[oe,lr]=s(!1);function ut(e){if(Wt.current||m||we.current)return;const t=M.current,n={key:e,authed:st.current,parkedAt:it.current??=Date.now(),lastPress:t&&{key:t.key,request:bn(t.request),lines:t.lines,goods:O(t.shape)[0],plainPressed:!!t.plainMethod,plainLines:t.plainLines,plainGoods:O(t.plainShape)[0]},keptCardKey:$.current,placedGoods:A.current===null?null:O(A.current)[0],unpaidOrder:Ge.current&&Br(Ge.current),placedRequest:G.current&&bn(G.current),lines:a.length>0?a:z.current,form:$r({email:Y,firstName:R,lastName:j,company:Ke,address1:ae,address2:Me,city:U,postcode:_,phone:Q,country:p,subdivision:E,selectedAddressId:nt,shippingMethodId:ce,couponCode:L?.valid?L.code:null})};Fr(n)?qr(n):ke()}const Ge=d(y);Ge.current=y;const Xt=d(w);Xt.current=w;function lt(e){return{...Ur(e),...Mn(),...e.payFirst?{checkoutFlow:Je}:{}}}function dr(e,t){let n=e.request.payFirst?"":null,o=e.plainPressed?null:"";const r=()=>Xt.current??"";return{key:e.key,send:()=>t(lt(e.request)),request:lt(e.request),lines:e.lines,shape:JSON.stringify([e.goods,null]),get method(){return n??r()},set method(u){n=u},get plainMethod(){return o??r()},set plainMethod(u){o=u},plainLines:e.plainLines,plainShape:JSON.stringify([e.plainGoods,null])}}const[pr,fr]=s(!1),Zt=pr?!C.quoted||C.serverSubtotal===null?"waiting":Math.abs(C.serverSubtotal-C.subtotal)<Qr?"same":"changed":null,dt=!y&&Zt==="waiting",mr=dt?{...C,repricing:!0}:C,jt=dt&&C.quoteFailed;f(()=>{if(!jt)return;const e=setInterval(Ze,jr);return()=>clearInterval(e)},[jt,Ze]);function Qt(e,t=!0){ve(e.email),Oe(e.firstName),Ee(e.lastName),Ve(e.company),ie(e.address1),ue(e.address2),le(e.city),de(e.postcode),pe(e.phone),e.country&&fe(e.country),V({country:e.country||null,state:e.subdivision}),Le(e.selectedAddressId),e.shippingMethodId&&wt(e.shippingMethodId),t&&(Ue.current=e.couponCode)}f(()=>{let e=m?null:Yr();if(e&&a.length>0&&(ke(),e=null),e){const t=e.authed?k.createOrderAuthed:k.createOrder;Ie(e.key),it.current=e.parkedAt,M.current=e.lastPress&&dr(e.lastPress,t),$.current=e.keptCardKey,A.current=e.placedGoods===null?null:JSON.stringify([e.placedGoods,null]),st.current=e.authed;const n=e.placedRequest&&lt(e.placedRequest);G.current=n,q.current=n?()=>t(n):null,e.unpaidOrder&&P(e.unpaidOrder),e.lines.length>0&&(je(e.lines),z.current=e.lines,fr(!0)),e.form&&(He.current=e.form,Qt(e.form))}lr(!0)},[]),f(()=>{!oe||a.length>0||Ge.current||I||(we.current=!0,ke())},[oe,a.length]),f(()=>{const e=Ue.current;!oe||!e||a.length===0||(Ue.current=null,In(e,Y||void 0))},[oe,a.length]),f(()=>{!oe||I||ut(H)},[oe,I,H,y]);const D=d(null);f(()=>{zt.current||(b!==D.current&&(D.current=null),!(!B.current||!y||y.orderNumber)&&(b===A.current||b===D.current||Dt(()=>Vt(y))))},[b,y]);async function Vt(e){if($e.current)return null;$e.current=!0;try{const t=re.current?await Dr(re.current):"none";if(t==="succeeded"||t==="processing")return B.current=!1,P(null),T("card"),t==="succeeded"?await W(void 0,e):ln(e),null;if(t===void 0||!Gr.has(t))return D.current=v.current,P(e),N(t==="requires_action"?Hr:ht),null;const n=await Pn(H);if(n==="committed")return B.current=!1,P(null),T("card"),await W(void 0,e),null;if(n!=="released")return D.current=v.current,P(e),N(ht),null;B.current=!1,re.current=null,D.current=null,N(null),P(null);const o=We();return Ie(o),o}finally{$e.current=!1}}async function yr(){m||I||$e.current||await Dt(hr)}async function hr(){if(y){if((B.current?b!==A.current:Ce())&&!y.orderNumber){const o=await Vt(y);o&&v.current===b&&await en(o);return}N(null),qe.current=!1,await pt();const t=O(v.current)[1],n=y.orderNumber?t:"card";if(n&&Kn.has(n)&&Ce()&&O(v.current)[0]!==at.current){tn(y);return}T(n),n!==w&&Ae(n),await dn(y,n,!y.orderNumber);return}await en(H)}async function en(e){if(a.length===0||C.repricing||dt||!w||!ne.some(i=>i.key===w))return;const t=a.filter(wn).flatMap(i=>Kr(i.components,i.qty));if(t.length===0){N("Pick a size on each wheel's product page before checking out.");return}N(null);let n,o=e,r=w,u=!1;try{const i=ye?k.createOrderAuthed:k.createOrder,l={customer:{email:Y,name:`${R} ${j}`.trim(),phone:Q.trim()||void 0,companyName:Ke.trim()||void 0,address:Fe,city:U,state:E||void 0,zipCode:_,country:p},items:t,currency:C.currency,idempotencyKey:e,shippingMethodId:ce??void 0,couponCode:An(L),...Mn(),...zr(w)?{checkoutFlow:Je}:{}};q.current=()=>i(l),G.current=l,st.current=!!ye,we.current=!1,he(null),at.current=null,qe.current=!1,re.current=null,B.current=!1,D.current=null,A.current=b,z.current=a;const h=M.current,ze=h?.key===l.idempotencyKey&&(h.shape!==b&&(!!l.checkoutFlow||!!h.method||!!h.plainMethod)||!!l.checkoutFlow&&!!h.plainMethod);ze&&($.current=l.idempotencyKey);const mn=sn(l,i),yn=ze||!l.checkoutFlow&&$.current===l.idempotencyKey,hn=!mn&&!yn&&!l.checkoutFlow&&!!h&&!h.method;hn&&(h.plainMethod=w,h.plainLines=a,h.plainShape=b,ut(l.idempotencyKey));const J=await(yn?rn(l,i):i(l).then(be=>({answer:be,request:l})).catch(be=>(mn?nn(be,l.idempotencyKey):hn&&Sn(be)&&(h.plainMethod=""),gr(be,l,i))));if(!J)return;n=J.answer,o=J.request.idempotencyKey,r=J.method??r,T(r),u=Ce()||r!==O(v.current)[1],J.method&&J.method!==w&&Ae(J.method),n.orderNumber&&(an(n),Z()),await pt()}catch(i){const l=Zr(i);l?(xn(l),N(`${l} Your order has not been placed. Place it again to continue without the code.`)):i instanceof Xe?N(ht):N(i instanceof De?i.message:"Could not place the order. Please try again.");return}if(r&&Kn.has(r)&&(u||Ce())){tn(n);return}await dn(n,r,!1,o)}function tn(e){at.current=O(v.current)[0],N(`${En(e,null)} ${Pe}`),P(e)}function nn(e,t){Sn(e)&&!Nn(e)&&M.current?.key===t&&(M.current=null)}async function gr(e,t,n){if(yt(e))return cn(t,n);if(!Nn(e))throw e;return $.current=t.idempotencyKey,rn(t,n,!0)}async function rn(e,t,n=!1){const o=await Pn(e.idempotencyKey);if(o==="released")return cn(e,t);if(o!=="committed")throw new Xe;const r=M.current?.key===e.idempotencyKey?M.current:null;if(z.current=r?.lines??a,r?.method&&!n){$.current=null,q.current=r.send,G.current=r.request;const l=await r.send().catch(()=>{throw new Xe});return A.current=r.shape,{answer:l,request:e,method:r.method}}const u=r&&!r.method?r.send:()=>t({...e,checkoutFlow:Je});q.current=u,G.current=r&&!r.method?r.request:{...e,checkoutFlow:Je};const i=await u().catch(()=>null);if(!i&&r?.plainMethod)throw new Xe;return i?.orderNumber&&i.status!==Wr?($.current=null,r?.plainMethod&&(z.current=r.plainLines),r&&(A.current=r.plainMethod?r.plainShape:r.shape),{answer:i,request:e,method:r?.plainMethod||void 0}):(r&&(A.current=r.shape),T("card"),await un("",i?async()=>i:()=>Promise.reject(new Error("The order request did not answer."))),await pt(),null)}function Ce(){const e=A.current;return e!==null&&O(e)[0]!==O(v.current)[0]}function T(e){e!==O(v.current)[1]&&(qe.current=!0),he(on()?Pe:null)}function on(){return qe.current||Ce()}async function cn(e,t){const n={...e,idempotencyKey:We()};$.current=null,Ie(n.idempotencyKey),q.current=()=>t(n),G.current=n,sn(n,t);try{return{answer:await t(n),request:n}}catch(o){throw nn(o,n.idempotencyKey),o}}function sn(e,t){return M.current?.key===e.idempotencyKey?!1:(M.current={key:e.idempotencyKey,send:()=>t(e),request:e,lines:a,shape:b,method:e.checkoutFlow?"":w??"",plainMethod:"",plainLines:a,plainShape:b},we.current=!1,ut(e.idempotencyKey),!0)}function an(e){Or({confirmation:e,lines:z.current,adsSendTo:c.googleAdsId&&c.googleAdsConversionLabel?`${c.googleAdsId}/${c.googleAdsConversionLabel}`:null}),Er({confirmation:e,lines:z.current})}async function W(e,t=F){if(!t)return;const n=e?async()=>e:q.current;if(t.orderNumber||!n){te(!0),S(t);return}await un(t.checkoutNumber,n)}async function un(e,t){Z(),await Xr({checkoutNumber:e,resend:t,page:{setConfirming:or,land:S,markPaid:()=>te(!0),track:an,unplaced:Bt}})}function ln(e=F){if(e){if(e.orderNumber){S(e);return}Z(),Bt({kind:"processing",checkoutNumber:e.checkoutNumber})}}async function pt(){const e=JSON.stringify([rt.trim(),R,j,Q.trim(),Fe,U,E,_,p]);if(!(!ye||!Kt||nt!=="new"||xt.current===e))try{await Ne.createAddress({label:rt.trim()||"Home",contact_name:`${R} ${j}`.trim(),phone:Q.trim(),address:Fe,city:U,zip_code:_,state:E,country:p}),xt.current=e,Tt("Address saved to your account.")}catch{Tt("We couldn't save the address to your account — you can add it under Account → Addresses.")}}async function dn(e,t=w,n=!1,o=H){P(null);try{if(t==="card"&&c.paymentMethods.includes("card")){const r=await k.createPaymentIntent({idempotencyKey:o});re.current=r;let u=e;if(n){const i=await q.current?.().catch(()=>null);if(i?.orderNumber){T("card"),await W(i,e);return}u=pn(e,i)??{...e,expiresAt:null}}T("card"),ee(u),ct(!1),Re(r)}else if(t==="paypal"&&c.paymentMethods.includes("paypal"))ee(e),Wn(!0);else if(t==="afterpay"&&c.paymentMethods.includes("afterpay")){const r=window.location.origin,u=await k.createAfterpayCheckout({idempotencyKey:o,confirmUrl:`${r}/checkout?afterpay=confirm`,cancelUrl:`${r}/checkout?afterpay=cancel`});Ye(Tr,o,e,u.redirectCheckoutUrl);return}else if(t==="square"&&c.paymentMethods.includes("square"))ee(e),Jn(!0);else if(t==="gocardless"&&c.paymentMethods.includes("gocardless")){const r=window.location.origin,u=await k.createGocardlessBillingRequest({idempotencyKey:o,confirmUrl:`${r}/checkout?gocardless=confirm`,cancelUrl:`${r}/checkout?gocardless=cancel`});Ye(ft,o,e,u.authorisationUrl);return}else if(t==="zip"&&c.paymentMethods.includes("zip")){const r=window.location.origin,u=await k.createZipCheckout({idempotencyKey:o,redirectUrl:`${r}/checkout?zip=return`});Ye(Lr,o,e,u.redirectUrl);return}else if(t==="klarna"&&c.paymentMethods.includes("klarna")){const r=window.location.origin,u=await k.createKlarnaCheckout({idempotencyKey:o,confirmUrl:`${r}/checkout?klarna=confirm`,cancelUrl:`${r}/checkout?klarna=cancel`});Ye(mt,o,e,u.redirectUrl);return}else T(t),S(e)}catch(r){if((n||t==="card")&&r instanceof De&&r.status===409){T(t),await W(void 0,e);return}fn(e,r)}}function pn(e,t){return t&&!t.orderNumber&&t.status==="open"&&t.checkoutNumber===e.checkoutNumber?t:null}function fn(e,t){N(En(e,t)),!e.orderNumber&&yt(t)?(B.current=!1,Ie(We())):P(e)}async function wr(e){if(!F)return;const t=F;try{const n=await k.createPaymentIntent({idempotencyKey:H}),o=await q.current?.().catch(()=>null);if(o?.orderNumber){await W(o);return}const r=pn(t,o);ee(r??{...t,expiresAt:null}),ct(e&&r!==null),re.current=n,Re(n)}catch(n){if(n instanceof De&&n.status===409){await W();return}Re(null),ee(null),fn(t,n)}}function kr(){F&&(B.current=!0,P(F),Re(null),ee(null),ct(!1))}return{site:c,logo:g,items:a,totals:mr,coupon:L,deliveryOptions:gt,courierUnavailable:Bn,retryCourier:Yn,shippingMethodId:ce,setShippingMethodId:wt,pickupLocation:Rn,servedCountries:se,formatMoney:_n,payChoice:w,setPayChoice:Ae,placing:I,email:Y,setEmail:ve,firstName:R,setFirstName:Oe,lastName:j,setLastName:Ee,company:Ke,setCompany:Ve,address1:ae,setAddress1:ie,address2:Me,setAddress2:ue,city:U,setCity:le,postcode:_,setPostcode:de,phone:Q,setPhone:pe,country:p,setCountry:fe,subdivision:E,setSubdivision:Te,subdivisions:me,destination:At,postcodeLabel:qn,subdivisionLabel:$n,me:ye,savedAddresses:Un,selectedAddressId:nt,setSelectedAddressId:Le,saveAddress:Kt,setSaveAddress:Mt,saveLabel:rt,setSaveLabel:Hn,addressSaveNote:Gn,lostChangeNote:zn,idemKey:H,confirmation:ot,setConfirmation:S,orderError:Dn,payment:Lt,paypalStep:It,squareStep:Rt,pendingConf:F,paid:Xn,setPaid:te,unpaidOrder:y,orderLocked:_t,formLocked:Zn,restoredPrices:Zt,payNote:jn,afterpayConfirming:Qn,gocardlessConfirming:er,zipConfirming:tr,klarnaConfirming:rr,cardConfirming:$t,checkoutResult:ge,confirmCardPayment:W,cardStillProcessing:ln,renewCardPayment:wr,holdRenewed:cr,leaveCardPayment:kr,checkoutRootRef:Ht,setCheckoutHeaderEl:sr,fillFromAddress:Gt,checkoutSignOut:ar,payOptions:ne,noPaymentMethod:ir,placeOrder:yr}}const Tn=Cr(null);function No({children:c,...g}){const m=Vr(g);return x(Tn.Provider,{value:m,children:c})}function Po(){const c=br(Tn);if(!c)throw new Error("useCheckout must be used inside CheckoutStateProvider");return c}export{No as CheckoutStateProvider,ko as NO_PAYMENT_METHOD_NOTE,Co as SHIPPING_RETRY_NOTE,On as buildPayOptions,En as paymentNotStartedMessage,bo as placedOrderLockNote,Po as useCheckout};
@@ -7,7 +7,9 @@ export declare const KLARNA_CONTEXT_KEY = "checkout-klarna-context";
7
7
  export interface WalletContext {
8
8
  idempotencyKey: string;
9
9
  confirmation: OrderConfirmation;
10
+ lostChange?: true;
10
11
  }
12
+ export declare function parkedLostChange(context: WalletContext | null): boolean;
11
13
  export type LandingOrder = Pick<OrderConfirmation, "orderNumber"> & Partial<Pick<OrderConfirmation, "currency" | "grandTotal" | "freightCharge" | "discountAmount" | "shippingMethod" | "couponCode">>;
12
14
  export type WalletReturn<C> = {
13
15
  action: "ignore";
@@ -41,6 +43,7 @@ export interface WalletReturnPage {
41
43
  note(message: string): void;
42
44
  fail(message: string): void;
43
45
  clearCart(): void;
46
+ lostChange(): void;
44
47
  }
45
48
  export interface WalletReturnDeps<Request> {
46
49
  search: string;
@@ -1 +1 @@
1
- const i="checkout-afterpay-context",g="checkout-gocardless-context",l="checkout-zip-context",p="checkout-klarna-context";function m({evidence:t,parked:e}){return t?{action:"capture",evidence:t,parked:e}:e?{action:"settle",parked:e}:{action:"ignore"}}function s(t,e){const r=t.getItem(e);if(t.removeItem(e),!r)return null;try{return JSON.parse(r)}catch{return null}}const f={name:"Afterpay",legParam:"afterpay",legValues:["confirm","cancel"],storageKey:i,evidenceFrom(t,e){return e==="cancel"||(t.get("status")??"").toUpperCase()==="CANCELLED"?null:t.get("orderToken")},requestFrom:t=>({token:t})},y={name:"Zip",legParam:"zip",legValues:["return"],storageKey:l,evidenceFrom(t){const e=(t.get("result")??"").toLowerCase();return e==="cancelled"||e==="declined"?null:t.get("checkoutId")},requestFrom:t=>({checkoutId:t})};async function E(t,e){const r=new URLSearchParams(e.search),o=r.get(t.legParam);if(!o||!t.legValues.includes(o))return;const c=s(e.storage,t.storageKey),u=t.evidenceFrom(r,o);e.scrubQuery();const n=m({evidence:u,parked:c});if(n.action!=="ignore"){if(e.page.clearCart(),n.action==="settle"){e.page.note(`The ${t.name} payment was not completed — our team will follow up on payment.`),e.page.land(n.parked.confirmation);return}e.page.setConfirming(!0);try{const a=await e.capture(t.requestFrom(n.evidence));a.status==="paid"?e.page.markPaid():e.page.note(`${t.name} declined the payment — our team will follow up on payment.`),e.page.land(n.parked?.confirmation??a)}catch{n.parked?(e.page.note(`We could not confirm the ${t.name} payment — our team will follow up on payment.`),e.page.land(n.parked.confirmation)):e.page.fail(`We could not confirm your ${t.name} payment. Please contact us before trying again — your payment may already have been taken.`)}finally{e.page.setConfirming(!1)}}}export{i as AFTERPAY_CONTEXT_KEY,f as AFTERPAY_RETURN,g as GOCARDLESS_CONTEXT_KEY,p as KLARNA_CONTEXT_KEY,l as ZIP_CONTEXT_KEY,y as ZIP_RETURN,s as readParked,m as resolveWalletReturn,E as runWalletReturn};
1
+ const i="checkout-afterpay-context",p="checkout-gocardless-context",l="checkout-zip-context",f="checkout-klarna-context";function m(t){return t?.lostChange===!0}function g({evidence:t,parked:e}){return t?{action:"capture",evidence:t,parked:e}:e?{action:"settle",parked:e}:{action:"ignore"}}function s(t,e){const r=t.getItem(e);if(t.removeItem(e),!r)return null;try{return JSON.parse(r)}catch{return null}}const y={name:"Afterpay",legParam:"afterpay",legValues:["confirm","cancel"],storageKey:i,evidenceFrom(t,e){return e==="cancel"||(t.get("status")??"").toUpperCase()==="CANCELLED"?null:t.get("orderToken")},requestFrom:t=>({token:t})},h={name:"Zip",legParam:"zip",legValues:["return"],storageKey:l,evidenceFrom(t){const e=(t.get("result")??"").toLowerCase();return e==="cancelled"||e==="declined"?null:t.get("checkoutId")},requestFrom:t=>({checkoutId:t})};async function d(t,e){const r=new URLSearchParams(e.search),o=r.get(t.legParam);if(!o||!t.legValues.includes(o))return;const c=s(e.storage,t.storageKey),u=t.evidenceFrom(r,o);e.scrubQuery();const n=g({evidence:u,parked:c});if(n.action!=="ignore"){if(e.page.clearCart(),m(n.parked)&&e.page.lostChange(),n.action==="settle"){e.page.note(`The ${t.name} payment was not completed — our team will follow up on payment.`),e.page.land(n.parked.confirmation);return}e.page.setConfirming(!0);try{const a=await e.capture(t.requestFrom(n.evidence));a.status==="paid"?e.page.markPaid():e.page.note(`${t.name} declined the payment — our team will follow up on payment.`),e.page.land(n.parked?.confirmation??a)}catch{n.parked?(e.page.note(`We could not confirm the ${t.name} payment — our team will follow up on payment.`),e.page.land(n.parked.confirmation)):e.page.fail(`We could not confirm your ${t.name} payment. Please contact us before trying again — your payment may already have been taken.`)}finally{e.page.setConfirming(!1)}}}export{i as AFTERPAY_CONTEXT_KEY,y as AFTERPAY_RETURN,p as GOCARDLESS_CONTEXT_KEY,f as KLARNA_CONTEXT_KEY,l as ZIP_CONTEXT_KEY,h as ZIP_RETURN,m as parkedLostChange,s as readParked,g as resolveWalletReturn,d as runWalletReturn};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "efficient-storefront-blocks",
3
- "version": "0.110.0",
3
+ "version": "0.111.0",
4
4
  "description": "The EFFICIENT storefront's website editor — the website builder assembled with the storefront's own sections — for an app that edits a storefront website inside its own page. Built from the efficient-storefront-blocks repository.",
5
5
  "license": "UNLICENSED",
6
6
  "author": "Efficient Pty Ltd",
@@ -1,4 +0,0 @@
1
- "use client";import{A as jr,P as Ur,Q as Wr,R as $r,S as Yr,T as Br,U as ye,W as bt,X as zr,Y as Hr,Z as Wt,_ as Gr,aa as bn,b as _r,ba as te,c as hn,d as Kr,e as jt,ea as Jr,fa as Vr,ka as Xr,la as Ne,ma as Zr,na as Qr,sa as eo,ta as vt,wa as vn,y as Ut,ya as ae,z as Dr}from"./chunk-CPAF23MT.js";import{P as ue,V as nt,aa as $}from"./chunk-MVJVIU2F.js";import{ni as Fr,pi as He,ti as qr}from"./chunk-FRCI3FAV.js";import{n as Mr,o as ht,p as ce}from"./chunk-GB6OHYUY.js";import{a as yn,b as ui}from"./chunk-Y6SLVHK3.js";var ro=yn((Rs,no)=>{"use strict";var pi="SECRET_DO_NOT_PASS_THIS_OR_YOU_WILL_BE_FIRED";no.exports=pi});var so=yn((Os,io)=>{"use strict";var mi=ro();function oo(){}function ao(){}ao.resetWarningCache=oo;io.exports=function(){function e(r,a,c,d,g,f){if(f!==mi){var p=new Error("Calling PropTypes validators directly is not supported by the `prop-types` package. Use PropTypes.checkPropTypes() to call them. Read more at http://fb.me/use-check-prop-types");throw p.name="Invariant Violation",p}}e.isRequired=e;function t(){return e}var n={array:e,bigint:e,bool:e,func:e,number:e,object:e,string:e,symbol:e,any:e,arrayOf:t,element:e,elementType:e,instanceOf:t,node:e,objectOf:t,oneOf:t,oneOfType:t,shape:t,exact:t,checkPropTypes:ao,resetWarningCache:oo};return n.PropTypes=n,n}});var lo=yn((Is,co)=>{"use strict";co.exports=so()();var As,Ls});import{useEffect as Ea,useMemo as Pa,useRef as it,useState as Je}from"react";import{rootIsDark as di}from"efficient-shell/format";function to(){if(typeof document>"u")return;let e=getComputedStyle(document.documentElement),t=(r,a)=>e.getPropertyValue(r).trim()||a,n=di({whenUnset:!0});return{theme:n?"night":"stripe",variables:{colorPrimary:t("--accent",n?"#c9a461":"#8a6a2a"),colorBackground:t("--site-surface",n?"#131313":"#ffffff"),colorText:t("--fg",n?"#f5f1e8":"#0a0a0a"),borderRadius:"0px"}}}var M=ui(lo(),1);import I from"react";function uo(e,t){(t==null||t>e.length)&&(t=e.length);for(var n=0,r=Array(t);n<t;n++)r[n]=e[n];return r}function fi(e){if(Array.isArray(e))return e}function yo(e,t,n){return(t=xi(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function gi(e,t){var n=e==null?null:typeof Symbol<"u"&&e[Symbol.iterator]||e["@@iterator"];if(n!=null){var r,a,c,d,g=[],f=!0,p=!1;try{if(c=(n=n.call(e)).next,t!==0)for(;!(f=(r=c.call(n)).done)&&(g.push(r.value),g.length!==t);f=!0);}catch(h){p=!0,a=h}finally{try{if(!f&&n.return!=null&&(d=n.return(),Object(d)!==d))return}finally{if(p)throw a}}return g}}function yi(){throw new TypeError(`Invalid attempt to destructure non-iterable instance.
2
- In order to be iterable, non-array objects must have a [Symbol.iterator]() method.`)}function po(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter(function(a){return Object.getOwnPropertyDescriptor(e,a).enumerable})),n.push.apply(n,r)}return n}function mo(e){for(var t=1;t<arguments.length;t++){var n=arguments[t]!=null?arguments[t]:{};t%2?po(Object(n),!0).forEach(function(r){yo(e,r,n[r])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):po(Object(n)).forEach(function(r){Object.defineProperty(e,r,Object.getOwnPropertyDescriptor(n,r))})}return e}function hi(e,t){if(e==null)return{};var n,r,a=bi(e,t);if(Object.getOwnPropertySymbols){var c=Object.getOwnPropertySymbols(e);for(r=0;r<c.length;r++)n=c[r],t.indexOf(n)===-1&&{}.propertyIsEnumerable.call(e,n)&&(a[n]=e[n])}return a}function bi(e,t){if(e==null)return{};var n={};for(var r in e)if({}.hasOwnProperty.call(e,r)){if(t.indexOf(r)!==-1)continue;n[r]=e[r]}return n}function ho(e,t){return fi(e)||gi(e,t)||ki(e,t)||yi()}function vi(e,t){if(typeof e!="object"||!e)return e;var n=e[Symbol.toPrimitive];if(n!==void 0){var r=n.call(e,t);if(typeof r!="object")return r;throw new TypeError("@@toPrimitive must return a primitive value.")}return(t==="string"?String:Number)(e)}function xi(e){var t=vi(e,"string");return typeof t=="symbol"?t:t+""}function xn(e){"@babel/helpers - typeof";return xn=typeof Symbol=="function"&&typeof Symbol.iterator=="symbol"?function(t){return typeof t}:function(t){return t&&typeof Symbol=="function"&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},xn(e)}function ki(e,t){if(e){if(typeof e=="string")return uo(e,t);var n={}.toString.call(e).slice(8,-1);return n==="Object"&&e.constructor&&(n=e.constructor.name),n==="Map"||n==="Set"?Array.from(e):n==="Arguments"||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?uo(e,t):void 0}}var V=function(t,n,r){var a=!!r,c=I.useRef(r);I.useEffect(function(){c.current=r},[r]),I.useEffect(function(){if(!a||!t)return function(){};var d=function(){if(c.current)return c.current.apply(c,arguments)};return t.on(n,d),function(){t.off(n,d)}},[a,n,t,c])},kn=function(t){var n=I.useRef(t);return I.useEffect(function(){n.current=t},[t]),n.current},rt=function(t){return t!==null&&xn(t)==="object"},Ci=function(t){return rt(t)&&typeof t.then=="function"},Pi=function(t){return rt(t)&&typeof t.elements=="function"&&typeof t.createToken=="function"&&typeof t.createPaymentMethod=="function"&&typeof t.confirmCardPayment=="function"},fo="[object Object]",wi=function e(t,n){if(t===n)return!0;if(!rt(t)||!rt(n))return t===n;var r=Array.isArray(t),a=Array.isArray(n);if(r!==a)return!1;var c=Object.prototype.toString.call(t)===fo,d=Object.prototype.toString.call(n)===fo;if(c!==d)return!1;if(!c&&!r)return t===n;var g=Object.keys(t),f=Object.keys(n);if(g.length!==f.length)return!1;for(var p={},h=0;h<g.length;h+=1)p[g[h]]=!0;for(var k=0;k<f.length;k+=1)p[f[k]]=!0;var v=Object.keys(p);if(v.length!==g.length)return!1;var y=t,E=n,C=function(D){return e(y[D],E[D])};return v.every(C)},bo=function(t,n,r){return rt(t)?Object.keys(t).reduce(function(a,c){var d=!rt(n)||!wi(t[c],n[c]);return r.includes(c)?(d&&console.warn("Unsupported prop change: options.".concat(c," is not a mutable property.")),a):d?mo(mo({},a||{}),{},yo({},c,t[c])):a},null):null},vo="Invalid prop `stripe` supplied to `Elements`. We recommend using the `loadStripe` utility from `@stripe/stripe-js`. See https://stripe.com/docs/stripe-js/react#elements-props-stripe for details.",go=function(t){var n=arguments.length>1&&arguments[1]!==void 0?arguments[1]:vo;if(t===null||Pi(t))return t;throw new Error(n)},Ni=function(t){var n=arguments.length>1&&arguments[1]!==void 0?arguments[1]:vo;if(Ci(t))return{tag:"async",stripePromise:Promise.resolve(t).then(function(a){return go(a,n)})};var r=go(t,n);return r===null?{tag:"empty"}:{tag:"sync",stripe:r}},Si=function(t){!t||!t._registerWrapper||!t.registerAppInfo||(t._registerWrapper({name:"react-stripe-js",version:"6.12.0"}),t.registerAppInfo({name:"react-stripe-js",version:"6.12.0",url:"https://stripe.com/docs/stripe-js/react"}))},$t=I.createContext(null);$t.displayName="ElementsContext";var xo=function(t,n){if(!t)throw new Error("Could not find Elements context; You need to wrap the part of your app that ".concat(n," in an <Elements> provider."));return t},Pn=function(t){var n=t.stripe,r=t.options,a=t.children,c=I.useMemo(function(){return Ni(n)},[n]),d=I.useState(function(){return{stripe:c.tag==="sync"?c.stripe:null,elements:c.tag==="sync"?c.stripe.elements(r):null}}),g=ho(d,2),f=g[0],p=g[1];I.useEffect(function(){var v=!0,y=function(C){p(function(R){return R.stripe?R:{stripe:C,elements:C.elements(r)}})};return c.tag==="async"&&!f.stripe?c.stripePromise.then(function(E){E&&v&&y(E)}):c.tag==="sync"&&!f.stripe&&y(c.stripe),function(){v=!1}},[c,f,r]);var h=kn(n);I.useEffect(function(){h!==null&&h!==n&&console.warn("Unsupported prop change on Elements: You cannot change the `stripe` prop after setting it.")},[h,n]);var k=kn(r);return I.useEffect(function(){if(f.elements){var v=bo(r,k,["clientSecret","fonts"]);v&&f.elements.update(v)}},[r,k,f.elements]),I.useEffect(function(){Si(f.stripe)},[f.stripe]),I.createElement($t.Provider,{value:f},a)};Pn.propTypes={stripe:M.default.any,options:M.default.object};var ko=function(t){var n=I.useContext($t);return xo(n,t)},Co=function(){var t=ko("calls useElements()"),n=t.elements;return n},Ei=function(t){var n=t.children,r=ko("mounts <ElementsConsumer>");return n(r)};Ei.propTypes={children:M.default.func.isRequired};var Ri=I.createContext(null);Ri.displayName="CheckoutContext";var Po=I.createContext(null);Po.displayName="CheckoutSdkContext";var Cn=function(t){var n=I.useContext(Po),r=I.useContext($t);if(n){if(r)throw new Error("You cannot wrap the part of your app that ".concat(t," in both a checkout provider and <Elements> provider."));return n}else return xo(r,t)},Oi=["mode"],Ai=function(t){return t.charAt(0).toUpperCase()+t.slice(1)},_=function(t,n,r){var a="".concat(Ai(t),"Element"),c=function(p){var h=p.id,k=p.className,v=p.options,y=v===void 0?{}:v,E=p.onBlur,C=p.onFocus,R=p.onReady,D=p.onChange,O=p.onEscape,S=p.onClick,B=p.onLoadError,X=p.onLoaderStart,de=p.onNetworksChange,j=p.onConfirm,ie=p.onCancel,Re=p.onShippingAddressChange,De=p.onShippingRateChange,Q=p.onSavedPaymentMethodRemove,be=p.onSavedPaymentMethodUpdate,ne=p.onAvailablePaymentMethodsChange,ee=Cn("mounts <".concat(a,">")),z="elements"in ee?ee.elements:null,b="checkoutSdk"in ee?ee.checkoutSdk:null,Oe=I.useState(null),je=ho(Oe,2),U=je[0],st=je[1],Z=I.useRef(null),ve=I.useRef(null);V(U,"blur",E),V(U,"focus",C),V(U,"escape",O),V(U,"click",S),V(U,"loaderror",B),V(U,"loaderstart",X),V(U,"networkschange",de),V(U,"confirm",j),V(U,"cancel",ie),V(U,"shippingaddresschange",Re),V(U,"shippingratechange",De),V(U,"savedpaymentmethodremove",Q),V(U,"savedpaymentmethodupdate",be),V(U,"availablepaymentmethodschange",ne),V(U,"change",D);var Ae;R&&(t==="expressCheckout"?Ae=R:Ae=function(){R(U)}),V(U,"ready",Ae),I.useLayoutEffect(function(){if(Z.current===null&&ve.current!==null&&(z||b)){var L=null;if(b){var re=b,pe=b;switch(t){case"paymentForm":L=pe.createForm(y);break;case"payment":L=re.createPaymentElement(y);break;case"address":if("mode"in y){var Ie=y.mode,xe=hi(y,Oi);if(Ie==="shipping")L=re.createShippingAddressElement(xe);else if(Ie==="billing")L=re.createBillingAddressElement(xe);else throw new Error("Invalid options.mode. mode must be 'billing' or 'shipping'.")}else throw new Error("You must supply options.mode. mode must be 'billing' or 'shipping'.");break;case"expressCheckout":L=re.createExpressCheckoutElement(y);break;case"currencySelector":L=b.createCurrencySelectorElement();break;case"taxId":L=re.createTaxIdElement(y);break;case"contactDetails":L=re.createContactDetailsElement();break;case"linkSignup":if("createLinkSignupElement"in b)L=b.createLinkSignupElement(y);else throw new Error("<LinkSignupElement> requires <CheckoutElementsProvider> and is not supported inside <CheckoutFormProvider>.");break;case"terms":L=re.createTermsElement(y);break;default:throw new Error("<".concat(a,"> is not supported inside a checkout provider. Use an <Elements> provider instead."))}}else z&&(L=z.create(t,y));Z.current=L,st(L),L&&L.mount(ve.current)}},[z,b,y]);var Le=kn(y);return I.useEffect(function(){if(Z.current){var L=bo(y,Le,["paymentRequest"]);L&&"update"in Z.current&&Z.current.update(L)}},[y,Le]),I.useLayoutEffect(function(){return function(){if(Z.current&&typeof Z.current.destroy=="function")try{Z.current.destroy(),Z.current=null}catch{}}},[]),I.createElement("div",{id:h,className:k,ref:ve})},d=function(p){Cn("mounts <".concat(a,">"));var h=p.id,k=p.className;return I.createElement("div",{id:h,className:k})},g=n?d:c;return g.propTypes={id:M.default.string,className:M.default.string,onChange:M.default.func,onBlur:M.default.func,onFocus:M.default.func,onReady:M.default.func,onEscape:M.default.func,onClick:M.default.func,onLoadError:M.default.func,onLoaderStart:M.default.func,onNetworksChange:M.default.func,onConfirm:M.default.func,onCancel:M.default.func,onShippingAddressChange:M.default.func,onShippingRateChange:M.default.func,onSavedPaymentMethodRemove:M.default.func,onSavedPaymentMethodUpdate:M.default.func,onAvailablePaymentMethodsChange:M.default.func,options:M.default.object},g.displayName=a,g.__elementType=t,g},K=typeof window>"u",Li=I.createContext(null);Li.displayName="EmbeddedCheckoutProviderContext";var wo=function(){var t=Cn("calls useStripe()"),n=t.stripe;return n},Fs=_("auBankAccount",K),qs=_("card",K),Ms=_("cardNumber",K),_s=_("cardExpiry",K),Ks=_("cardCvc",K),Ds=_("currencySelector",K),js=_("iban",K),No=_("payment",K),Us=_("expressCheckout",K),Ws=_("paymentRequestButton",K),$s=_("linkAuthentication",K),Ys=_("linkSignup",K),Bs=_("contactDetails",K),zs=_("address",K),Hs=_("shippingAddress",K),Gs=_("paymentMethodMessaging",K),Js=_("taxId",K),Vs=_("issuingCardNumberDisplay",K),Xs=_("issuingCardCvcDisplay",K),Zs=_("issuingCardExpiryDisplay",K),Qs=_("issuingCardPinDisplay",K),ec=_("issuingCardCopyButton",K),tc=_("terms",K);function zt(e){"@babel/helpers - typeof";return typeof Symbol=="function"&&typeof Symbol.iterator=="symbol"?zt=function(t){return typeof t}:zt=function(t){return t&&typeof Symbol=="function"&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},zt(e)}var Ro="dahlia",Ii=function(t){return t===3?"v3":t},Oo="https://js.stripe.com",Ti="".concat(Oo,"/").concat(Ro,"/stripe.js"),Fi=/^https:\/\/js\.stripe\.com\/v3\/?(\?.*)?$/,qi=/^https:\/\/js\.stripe\.com\/(v3|[a-z]+)\/stripe\.js(\?.*)?$/,So="loadStripe.setLoadParameters was called but an existing Stripe.js script already exists in the document; existing script parameters will be used",Mi=function(t){return Fi.test(t)||qi.test(t)},_i=function(){for(var t=document.querySelectorAll('script[src^="'.concat(Oo,'"]')),n=0;n<t.length;n++){var r=t[n];if(Mi(r.src))return r}return null},Eo=function(t){var n=t&&!t.advancedFraudSignals?"?advancedFraudSignals=false":"",r=document.createElement("script");r.src="".concat(Ti).concat(n);var a=document.head||document.body;if(!a)throw new Error("Expected document.body not to be null. Stripe.js requires a <body> element.");return a.appendChild(r),r},Ki=function(t,n){!t||!t._registerWrapper||t._registerWrapper({name:"stripe-js",version:"9.17.0",startTime:n})},xt=null,Yt=null,Bt=null,Di=function(t){return function(n){t(new Error("Failed to load Stripe.js",{cause:n}))}},ji=function(t,n){return function(){window.Stripe?t(window.Stripe):n(new Error("Stripe.js not available"))}},Ui=function(t){return xt!==null?xt:(xt=new Promise(function(n,r){if(typeof window>"u"||typeof document>"u"){n(null);return}if(window.Stripe&&t&&console.warn(So),window.Stripe){n(window.Stripe);return}try{var a=_i();if(a&&t)console.warn(So);else if(!a)a=Eo(t);else if(a&&Bt!==null&&Yt!==null){var c;a.removeEventListener("load",Bt),a.removeEventListener("error",Yt),(c=a.parentNode)===null||c===void 0||c.removeChild(a),a=Eo(t)}Bt=ji(n,r),Yt=Di(r),a.addEventListener("load",Bt),a.addEventListener("error",Yt)}catch(d){r(d);return}}),xt.catch(function(n){return xt=null,Promise.reject(n)}))},Wi=function(t,n,r){if(t===null)return null;var a=n[0];if(typeof a!="string")throw new Error("Expected publishable key to be of type string, got type ".concat(zt(a)," instead."));var c=a.match(/^pk_test/),d=Ii(t.version),g=Ro;c&&d!==g&&console.warn("Stripe.js@".concat(d," was loaded on the page, but @stripe/stripe-js@").concat("9.17.0"," expected Stripe.js@").concat(g,". This may result in unexpected behavior. For more information, see https://docs.stripe.com/sdks/stripejs-versioning"));var f=t.apply(void 0,n);return Ki(f,r),f},kt,Ao=!1,Lo=function(){return kt||(kt=Ui(null).catch(function(t){return kt=null,Promise.reject(t)}),kt)};Promise.resolve().then(function(){return Lo()}).catch(function(e){Ao||console.warn(e)});var Ht=function(){for(var t=arguments.length,n=new Array(t),r=0;r<t;r++)n[r]=arguments[r];Ao=!0;var a=Date.now();return Lo().then(function(c){return Wi(c,n,a)})};var Ct=2;function Io(e){return e==="card"}var $i="checkout_unavailable",Yi="checkout_waiting",To="committed",_e="We could not check your payment. Please try again.",wn="Your last change was not saved. This is your order as placed.",Fo="Your bank is still waiting for you to approve this payment, so your order stays as it was. Finish the approval, or try again in a few minutes.",qo=1e4;async function Mo(e,t=qo){let n,r=new Promise(c=>{n=setTimeout(()=>c(void 0),t)}),a=(async()=>{try{return(await(await Ht(e.publishableKey))?.retrievePaymentIntent(e.clientSecret))?.paymentIntent?.status}catch{return}})();try{return await Promise.race([a,r])}finally{clearTimeout(n)}}var _o=new Set(["none","requires_payment_method","canceled"]);async function Nn(e,t=qo){let n,r=new Promise(a=>{n=setTimeout(()=>a(void 0),t)});try{return await Promise.race([$.releaseCheckout({idempotencyKey:e}).then(a=>a.status,()=>{}),r])}finally{clearTimeout(n)}}function Ko(e,t){return e instanceof ue&&typeof e.data=="object"&&e.data!==null&&e.data.code===t}function Gt(e){return Ko(e,$i)}function Sn(e){return Ko(e,Yi)}function En(e){return e instanceof ue&&e.status>=400&&e.status<500&&e.status!==408}function Do(e){return JSON.stringify([e.email,e.firstName,e.lastName,e.phone,e.address,e.city,e.subdivision,e.postcode,e.country,e.lines,e.shippingMethodId,e.couponCode,e.currency,e.shopperId,e.company])}function Jt(e){return e.orderNumber||e.checkoutNumber}function Bi(e){return e.orderNumber?{kind:"placed",order:e}:{kind:e.status==="released"?"refunded":e.status==="expired"?"expired":"pending",checkoutNumber:e.checkoutNumber}}async function jo({checkoutNumber:e,resend:t,page:n}){n.setConfirming(!0);let r;try{r=Bi(await t())}catch{r={kind:"pending",checkoutNumber:e}}r.kind==="placed"?(n.markPaid(),n.track(r.order),n.land(r.order)):n.unplaced({...r,checkoutNumber:r.checkoutNumber||e}),n.setConfirming(!1)}import{createContext as os,useContext as as,useEffect as Y,useMemo as aa,useRef as q,useState as w}from"react";var zi="sf:gclid",Hi="sf:fbclid",Gi=2160*60*60*1e3;function $o(){return typeof window<"u"}function Uo(e){let t=ht.getItem(e);if(!t)return"";try{let{v:n,t:r}=JSON.parse(t);return!n||typeof r!="number"||Date.now()-r>Gi?"":n}catch{return""}}function Wo(e){if(!$o())return"";let t=e.replace(/([.$?*|{}()[\]\\/+^])/g,"\\$1"),n=document.cookie.match(new RegExp(`(?:^|; )${t}=([^;]*)`));return n?decodeURIComponent(n[1]):""}function Yo(){if(!$o())return{};let e=Uo(zi),t=Uo(Hi),n=Wo("_fbp"),r=Wo("_fbc");!r&&t&&(r=`fb.1.${Date.now()}.${t}`);let a={};return e&&(a.gclid=e),t&&(a.fbclid=t),n&&(a.fbp=n),r&&(a.fbc=r),a}var Bo="sf:meta-purchases",Ji=20;function Ho(){return typeof window>"u"||window.parent!==window}function Vi(...e){try{if(Ho()||typeof window.fbq!="function")return;window.fbq(...e)}catch{}}var zo=new Set;function Xi(e){if(zo.has(e))return!1;zo.add(e);try{let t=JSON.parse(ht.getItem(Bo)??"[]");if(t.includes(e))return!1;ht.setItem(Bo,JSON.stringify([...t,e].slice(-Ji)))}catch{}return!0}function Zi(e){return[...new Set(e.filter(bt).flatMap(t=>t.components.map(n=>n.partNumber)))]}function Go(e){let t=e.confirmation;Ho()||!Xi(t.orderNumber)||Vi("track","Purchase",{value:Number(t.grandTotal),currency:t.currency,content_type:"product",content_ids:Zi(e.lines)},{eventID:t.orderNumber})}var Rn="checkout-afterpay-context",Vt="checkout-gocardless-context",On="checkout-zip-context",Xt="checkout-klarna-context";function Qi({evidence:e,parked:t}){return e?{action:"capture",evidence:e,parked:t}:t?{action:"settle",parked:t}:{action:"ignore"}}function es(e,t){let n=e.getItem(t);if(e.removeItem(t),!n)return null;try{return JSON.parse(n)}catch{return null}}var Jo={name:"Afterpay",legParam:"afterpay",legValues:["confirm","cancel"],storageKey:Rn,evidenceFrom(e,t){return t==="cancel"||(e.get("status")??"").toUpperCase()==="CANCELLED"?null:e.get("orderToken")},requestFrom:e=>({token:e})},Vo={name:"Zip",legParam:"zip",legValues:["return"],storageKey:On,evidenceFrom(e){let t=(e.get("result")??"").toLowerCase();return t==="cancelled"||t==="declined"?null:e.get("checkoutId")},requestFrom:e=>({checkoutId:e})};async function An(e,t){let n=new URLSearchParams(t.search),r=n.get(e.legParam);if(!r||!e.legValues.includes(r))return;let a=es(t.storage,e.storageKey),c=e.evidenceFrom(n,r);t.scrubQuery();let d=Qi({evidence:c,parked:a});if(d.action!=="ignore"){if(t.page.clearCart(),d.action==="settle"){t.page.note(`The ${e.name} payment was not completed \u2014 our team will follow up on payment.`),t.page.land(d.parked.confirmation);return}t.page.setConfirming(!0);try{let g=await t.capture(e.requestFrom(d.evidence));g.status==="paid"?t.page.markPaid():t.page.note(`${e.name} declined the payment \u2014 our team will follow up on payment.`),t.page.land(d.parked?.confirmation??g)}catch{d.parked?(t.page.note(`We could not confirm the ${e.name} payment \u2014 our team will follow up on payment.`),t.page.land(d.parked.confirmation)):t.page.fail(`We could not confirm your ${e.name} payment. Please contact us before trying again \u2014 your payment may already have been taken.`)}finally{t.page.setConfirming(!1)}}}function Xo(e,t,n){let r=(t??"").trim();if(!r)return"";if(n.length===0)return r;let a=r.toUpperCase(),c=`${e.toUpperCase()}-${a}`,d=n.find(g=>g.code&&g.code.toUpperCase()===a)??n.find(g=>g.code&&g.code.toUpperCase()===c)??n.find(g=>g.name.toUpperCase()===a);return d?d.code||d.name:""}var In="checkout-memory-context",Qo="Prices have changed since this checkout started. The total shows today's prices.",ea=2,ts=3600*1e3;function ns(e){return{id:e.id,slug:e.slug,name:{lead:e.name?.lead,accent:e.name?.accent},process:e.process,positionNo:e.positionNo,config:(e.config??[]).map(t=>({label:t.label,gold:t.gold})),finishName:e.finishName,size:e.size,qty:e.qty,href:e.href,kind:e.kind,sku:e.sku,components:e.components.map(t=>({partNumber:t.partNumber,wheels:t.wheels,prices:{...t.prices},hand:t.hand}))}}var ot=e=>e.map(ns);function ta(e){let t=e.customer;return{customer:{email:t.email,name:t.name,phone:t.phone,companyName:t.companyName,address:t.address,city:t.city,state:t.state,zipCode:t.zipCode,country:t.country},items:e.items.flatMap(n=>jt([{partNumber:n.partNumber,wheels:n.quantity,prices:{}}],1)),currency:e.currency,idempotencyKey:e.idempotencyKey,shippingMethodId:e.shippingMethodId,couponCode:e.couponCode}}function Tn(e){return{...ta(e),payFirst:!!e.checkoutFlow}}function na(e){return ta(e)}function Fn(e){let t=n=>typeof n=="string"?n:"";return{email:t(e.email),firstName:t(e.firstName),lastName:t(e.lastName),company:t(e.company),address1:t(e.address1),address2:t(e.address2),city:t(e.city),postcode:t(e.postcode),phone:t(e.phone),country:t(e.country),subdivision:t(e.subdivision),selectedAddressId:t(e.selectedAddressId),shippingMethodId:typeof e.shippingMethodId=="string"?e.shippingMethodId:null,couponCode:typeof e.couponCode=="string"?e.couponCode:null}}function qn(e){return{orderNumber:e.orderNumber,checkoutNumber:e.checkoutNumber,expiresAt:e.expiresAt,status:e.status,total:e.total,currency:e.currency,freightCharge:e.freightCharge,discountAmount:e.discountAmount,grandTotal:e.grandTotal,shippingMethod:e.shippingMethod,couponCode:e.couponCode}}function Mn(e){return e.lastPress!==null||e.unpaidOrder!==null||e.keptCardKey!==null}function rs(e){let t=e.parkedAt+ts,n=e.unpaidOrder&&!e.unpaidOrder.orderNumber?e.unpaidOrder.expiresAt:null,r=n?Date.parse(n):NaN;return Number.isNaN(r)?t:Math.min(t,r)}function ra(e){try{let t=e.lastPress,n={...e,lines:ot(e.lines),lastPress:t&&{...t,lines:ot(t.lines),plainLines:ot(t.plainLines)}};ce.setItem(In,JSON.stringify({v:ea,...n}))}catch{}}var Pt=e=>!!e&&typeof e=="object"&&!Array.isArray(e),Zo=e=>Pt(e)&&typeof e.idempotencyKey=="string"&&Array.isArray(e.items)&&e.items.every(t=>Pt(t)&&typeof t.partNumber=="string"&&typeof t.quantity=="number")&&Pt(e.customer)&&typeof e.payFirst=="boolean",Ln=e=>Pt(e)&&typeof e.id=="string"&&typeof e.qty=="number"&&Array.isArray(e.components);function oa(){let e;try{e=ce.getItem(In)}catch{return null}if(!e)return null;try{let t=JSON.parse(e);if(t.v!==ea||typeof t.key!="string"||!t.key||!Array.isArray(t.lines)||!t.lines.every(Ln)||typeof t.parkedAt!="number")return null;let n=t.lastPress,r={key:t.key,authed:t.authed===!0,parkedAt:t.parkedAt,lastPress:Pt(n)&&typeof n.key=="string"&&Zo(n.request)&&Array.isArray(n.lines)&&n.lines.every(Ln)&&Array.isArray(n.plainLines)&&n.plainLines.every(Ln)?{...n,lines:ot(n.lines),plainLines:ot(n.plainLines)}:null,keptCardKey:typeof t.keptCardKey=="string"?t.keptCardKey:null,placedGoods:typeof t.placedGoods=="string"?t.placedGoods:null,unpaidOrder:t.unpaidOrder&&typeof t.unpaidOrder=="object"?qn(t.unpaidOrder):null,placedRequest:Zo(t.placedRequest)?t.placedRequest:null,lines:ot(t.lines),form:t.form&&typeof t.form=="object"?Fn(t.form):null};return Date.now()>=rs(r)?(_n(),null):Mn(r)?r:null}catch{return null}}function _n(){try{ce.removeItem(In)}catch{}}import{jsx as Se}from"react/jsx-runtime";function ia(e){let t=e.indexOf(`
3
- `);return t===-1?[e,""]:[e.slice(0,t),e.slice(t+1)]}function sa(e,{canParkContext:t}={canParkContext:!0}){let n=e.paymentMethods,r=[];return n.includes("card")&&r.push({key:"card",title:"Card",body:null,price:Se("span",{className:"font-mono text-[12px] uppercase tracking-[0.2em] text-accent",children:"VISA \xB7 MC \xB7 AMEX"})}),n.includes("paypal")&&e.paypalClientId&&r.push({key:"paypal",title:"PayPal",body:null,price:Se("span",{className:"font-mono text-[12px] uppercase tracking-[0.2em] text-accent",children:"PAYPAL \xB7 CARDS"})}),n.includes("afterpay")&&r.push({key:"afterpay",title:"Afterpay",body:null,price:Se("span",{className:"font-mono text-[12px] uppercase tracking-[0.2em] text-accent",children:"4 \xD7 INTEREST-FREE"})}),n.includes("square")&&e.squareApplicationId&&e.squareLocationId&&r.push({key:"square",title:"Card (Square)",body:null,price:Se("span",{className:"font-mono text-[12px] uppercase tracking-[0.2em] text-accent",children:"VISA \xB7 MC \xB7 AMEX"})}),n.includes("gocardless")&&t&&r.push({key:"gocardless",title:"Bank Direct Debit",body:null,price:Se("span",{className:"font-mono text-[12px] uppercase tracking-[0.2em] text-accent",children:"PAY BY BANK"})}),n.includes("zip")&&r.push({key:"zip",title:"Zip",body:null,price:Se("span",{className:"font-mono text-[12px] uppercase tracking-[0.2em] text-accent",children:"PAY IN 4"})}),n.includes("klarna")&&t&&r.push({key:"klarna",title:"Klarna",body:null,price:Se("span",{className:"font-mono text-[12px] uppercase tracking-[0.2em] text-accent",children:"PAY LATER"})}),n.includes("bank")&&r.push({key:"bank",title:"Bank transfer",body:null,price:Se("span",{className:"font-mono text-[12px] uppercase tracking-[0.2em] text-fg-dim",children:"Invoiced"})}),r}var da="This shop does not take payment online yet. Please contact the shop to order.",at=class extends Error{};function ca(e,t){if(!e.orderNumber&&Gt(t))return t.message;let n=t instanceof ue?` (${t.message})`:"";return e.orderNumber?`Your order ${e.orderNumber} is saved, but the payment did not start${n}. Try the payment again \u2014 your order will not be placed twice.`:`Your items are held under ${e.checkoutNumber}, but the payment did not start${n}. Try the payment again \u2014 you will not be charged twice.`}var is=3e3,ss=.005,la=new Set(["paypal","square","afterpay","gocardless","zip","klarna"]);function ua(){let e=eo();return{...e==="denied"?{}:Yo(),...e?{adConsent:e}:{}}}var he=e=>JSON.parse(e),pa="Shipping cannot be calculated right now. Please try again.";function ma(e){return`Your order is saved, so its contact, address, delivery and discount can't change here. To change any of them, contact the shop and quote ${e}.`}function cs({site:e,logo:t,preview:n=!1}){let{items:r,totals:a,coupon:c,refuseCoupon:d,deliveryOptions:g,shippingMethodId:f,setShippingMethodId:p,setQuoteDestination:h,courier:k,requote:v,identify:y,clearCapturedCart:E,replaceItems:C,removeCoupon:R,applyCoupon:D}=Wt(),O=g.find(o=>o.id===f)?.pickupLocation??null,{country:S,countries:B,activeCountry:X,formatMoney:de}=ye(),[j,ie]=w(()=>sa(e)[0]?.key??null),[Re,De]=w(!0);Y(()=>{De(Mr(ce))},[]);let[Q,be]=w(!1),[ne,ee]=w(""),[z,b]=w(""),[Oe,je]=w(""),[U,st]=w(""),[Z,ve]=w(""),[Ae,Le]=w(""),[L,re]=w(""),[pe,Ie]=w(""),[xe,ct]=w(""),[W,lt]=w(()=>S||B[0]?.code||""),[ke,Nt]=w(""),[ut,Wn]=w([]),[nn,rn]=w(null),[St,Ve]=w(null),$n=aa(()=>B.find(o=>o.code===W)??X,[B,W,X]),Ra=$n?.postalLabel||"Postal Code",Oa=ut[0]?.divisionType||"State / Province";Y(()=>{if(!W){Wn([]),rn(W);return}rn(null);let o=!1;return $.listCountrySubdivisions(W).then(s=>{o||(Wn(s),rn(W),Nt(""))}),()=>{o=!0}},[W]);let Yn=Z.trim()!==""&&L.trim()!==""&&pe.trim()!==""&&nn===W&&(ut.length===0||ke!=="")?pe.trim():"";Y(()=>{h(W?{country:W,subdivision:ke,postcode:Yn}:null)},[W,ke,Yn,h]),Y(()=>()=>h(null),[h]);let Aa=k?.status==="unavailable",La=v,[dt,Bn]=w(null),[Ia,zn]=w([]),[on,Et]=w("new"),[Hn,Gn]=w(!1),[an,Ta]=w("Home"),[Fa,Jn]=w(null),[qa,Vn]=w(null),[Ue,Rt]=w(()=>vt()),Xn=q(null),[sn,me]=w(null),[Ma,se]=w(null),[Zn,Ot]=w(null),[Qn,_a]=w(!1),[er,Ka]=w(!1),[Te,Xe]=w(null),[Da,Ze]=w(!1),[G,le]=w(null),tr=!!G?.orderNumber,ja=tr||Q,[Ua,Ce]=w(null),[Wa,$a]=w(!1),[Ya,nr]=w(!1),[Ba,za]=w(!1),[Ha,rr]=w(!1),[or,Ga]=w(!1),[Ja,cn]=w(!1),[pt,ar]=w(null),Fe=q(null),We=q(null),ln=q(!1),$e=q(r),Pe=q(null),qe=q(null),ir=!!(sn||pt&&pt.kind!=="processing"||or||Qn||er||Zn&&Te?.orderNumber);Y(()=>{ir&&(C([]),R())},[ir,C,R]);let sr=q(!1);Y(()=>{n||sr.current||!r.some(bt)||(sr.current=!0,Ur({lines:r,currency:a.currency,value:a.subtotal-a.discount,coupon:c?.valid?c.code:void 0}))},[r,a,c,n]),Y(()=>{y(ne,z.trim()||void 0)},[ne,z,y]);let cr=q(null),[At,Va]=w(null);Y(()=>{let o=cr.current;if(!At||!o)return;let s=()=>o.style.setProperty("--sf-checkout-header-h",`${At.offsetHeight}px`);s();let u=new ResizeObserver(s);return u.observe(At),()=>u.disconnect()},[At]),Y(()=>{let o=u=>({setConfirming:u,land:me,markPaid:()=>Ze(!0),note:Ce,fail:se,clearCart:E}),s={search:window.location.search,storage:ce,scrubQuery:()=>window.history.replaceState(null,"",window.location.pathname)};An(Jo,{...s,capture:$.captureAfterpayPayment,page:o($a)}),An(Vo,{...s,capture:$.captureZipPayment,page:o(za)})},[]),Y(()=>{let s=new URLSearchParams(window.location.search).get("gocardless");if(s!=="confirm"&&s!=="cancel")return;let u=ce.getItem(Vt);if(ce.removeItem(Vt),window.history.replaceState(null,"",window.location.pathname),!u)return;let P;try{P=JSON.parse(u)}catch{return}if(E(),s==="cancel"){Ce("The direct debit was not set up \u2014 our team will follow up on payment."),me(P.confirmation);return}nr(!0),$.completeGocardlessPayment({idempotencyKey:P.idempotencyKey}).then(m=>{m.status==="paid"?Ze(!0):m.status==="declined"?Ce("The direct debit was declined \u2014 our team will follow up on payment."):Ce("Your direct debit is set up \u2014 the payment is collecting and will clear in a few days.")}).catch(()=>{Ce("We could not confirm the direct debit \u2014 our team will follow up on payment.")}).finally(()=>{me(P.confirmation),nr(!1)})},[]),Y(()=>{let o=new URLSearchParams(window.location.search),s=o.get("klarna");if(s!=="confirm"&&s!=="cancel")return;let u=ce.getItem(Xt);ce.removeItem(Xt);let P=o.get("authorization_token");if(window.history.replaceState(null,"",window.location.pathname),!u)return;let m;try{m=JSON.parse(u)}catch{return}if(E(),s==="cancel"||!P){Ce("The Klarna payment was not completed \u2014 our team will follow up on payment."),me(m.confirmation);return}rr(!0),$.captureKlarnaPayment({idempotencyKey:m.idempotencyKey,authorizationToken:P}).then(T=>{T.status==="paid"?Ze(!0):T.status==="declined"?Ce("Klarna declined the payment \u2014 our team will follow up on payment."):Ce("Your Klarna payment is being reviewed \u2014 we'll confirm the outcome shortly.")}).catch(()=>{Ce("We could not confirm the Klarna payment \u2014 our team will follow up on payment.")}).finally(()=>{me(m.confirmation),rr(!1)})},[]);function lr(o){let[s,u]=ia(o.address);ve(s),Le(u),re(o.city),Ie(o.zip_code),o.country&&lt(o.country),o.phone&&ct(o.phone),Ve({country:o.country||null,state:o.state??""})}Y(()=>{if(St){if((St.country||W)!==W){Ve(null);return}nn===W&&(Nt(Xo(W,St.state,ut)),Ve(null))}},[St,W,nn,ut]),Y(()=>{let o=!1;return(async()=>{try{let[s,u,P]=await Promise.all([nt.me(),nt.myProfile().catch(()=>null),nt.myAddresses().catch(()=>[])]);if(o)return;Bn(s);let m=P.filter(J=>J.is_active);zn(m),ee(s.email);let T=(u?.contact_name??"").split(/\s+/);b(s.first_name||T[0]||""),je(s.last_name||T.slice(1).join(" "));let A=s.phone||u?.phone;A&&ct(A);let F=m.find(J=>J.id===s.default_delivery_location)??m[0];if(F)Et(F.id),lr(F);else if(u){let[J,Dt]=ia(u.address??"");ve(J),Le(Dt),re(u.city??""),Ie(u.zip_code??""),u.country&&lt(u.country),Ve({country:u.country||null,state:u.state??""})}_t.current&&hr(_t.current,!1)}catch{}})(),()=>{o=!0}},[]);function Xa(){nt.logout(),mt.current=!0,_t.current=null,Mt.current=null,ft(),Bn(null),zn([]),Et("new"),Gn(!1),ee(""),b(""),je(""),st(""),ve(""),Le(""),re(""),Ie(""),ct(""),lt(S||B[0]?.code||""),Nt(""),Ve(null)}let Qe=aa(()=>sa(e,{canParkContext:Re}),[e,Re]);Y(()=>{Qe.some(o=>o.key===j)||ie(Qe[0]?.key??null)},[Qe,j]);let Za=Qe.length===0,Lt=Ae.trim()?`${Z}
4
- ${Ae.trim()}`:Z,Qa=Do({email:ne,firstName:z,lastName:Oe,company:U.trim(),phone:xe,address:Lt,city:L,subdivision:ke,postcode:pe,country:W,lines:r.map(o=>[o.id,o.qty]),shippingMethodId:f,couponCode:hn(c),currency:a.currency,shopperId:dt?.id??null}),oe=JSON.stringify([Qa,j]),fe=q(null),un=q(null),It=q(!1),Me=q(!1),et=q(null),Tt=q(!1),ge=q(oe);ge.current=oe;let ur=q(Q);ur.current=Q;let Ft=q(null);Y(()=>{let o=()=>{let s=Ft.current;s&&(Ft.current=null,le(s),be(!1))};return window.addEventListener("pageshow",o),()=>window.removeEventListener("pageshow",o)},[]);function qt(o,s,u,P){let m={idempotencyKey:s,confirmation:u};ce.setItem(o,JSON.stringify(m)),window.location.assign(P),Ft.current=u}async function dr(o){be(!0);try{await o()}finally{Ft.current||be(!1)}}let pr=q(!1),mr=!!(sn||pt&&pt.kind!=="processing");Y(()=>{mr&&(pr.current=!0,ft())},[mr]);let Mt=q(null),mt=q(!1),dn=q(null);function ft(){dn.current=null,_n()}let _t=q(null),[tt,ei]=w(!1);function pn(o){if(pr.current||n||mt.current)return;let s=Pe.current,u={key:o,authed:ln.current,parkedAt:dn.current??=Date.now(),lastPress:s&&{key:s.key,request:Tn(s.request),lines:s.lines,goods:he(s.shape)[0],plainPressed:!!s.plainMethod,plainLines:s.plainLines,plainGoods:he(s.plainShape)[0]},keptCardKey:qe.current,placedGoods:fe.current===null?null:he(fe.current)[0],unpaidOrder:Kt.current&&qn(Kt.current),placedRequest:We.current&&Tn(We.current),lines:r.length>0?r:$e.current,form:Fn({email:ne,firstName:z,lastName:Oe,company:U,address1:Z,address2:Ae,city:L,postcode:pe,phone:xe,country:W,subdivision:ke,selectedAddressId:on,shippingMethodId:f,couponCode:c?.valid?c.code:null})};Mn(u)?ra(u):ft()}let Kt=q(G);Kt.current=G;let fr=q(j);fr.current=j;function mn(o){return{...na(o),...ua(),...o.payFirst?{checkoutFlow:Ct}:{}}}function ti(o,s){let u=o.request.payFirst?"":null,P=o.plainPressed?null:"",m=()=>fr.current??"";return{key:o.key,send:()=>s(mn(o.request)),request:mn(o.request),lines:o.lines,shape:JSON.stringify([o.goods,null]),get method(){return u??m()},set method(T){u=T},get plainMethod(){return P??m()},set plainMethod(T){P=T},plainLines:o.plainLines,plainShape:JSON.stringify([o.plainGoods,null])}}let[ni,ri]=w(!1),gr=ni?!a.quoted||a.serverSubtotal===null?"waiting":Math.abs(a.serverSubtotal-a.subtotal)<ss?"same":"changed":null,fn=!G&&gr==="waiting",oi=fn?{...a,repricing:!0}:a,yr=fn&&a.quoteFailed;Y(()=>{if(!yr)return;let o=setInterval(v,is);return()=>clearInterval(o)},[yr,v]);function hr(o,s=!0){ee(o.email),b(o.firstName),je(o.lastName),st(o.company),ve(o.address1),Le(o.address2),re(o.city),Ie(o.postcode),ct(o.phone),o.country&&lt(o.country),Ve({country:o.country||null,state:o.subdivision}),Et(o.selectedAddressId),o.shippingMethodId&&p(o.shippingMethodId),s&&(Mt.current=o.couponCode)}Y(()=>{let o=n?null:oa();if(o&&r.length>0&&(ft(),o=null),o){let s=o.authed?$.createOrderAuthed:$.createOrder;Rt(o.key),dn.current=o.parkedAt,Pe.current=o.lastPress&&ti(o.lastPress,s),qe.current=o.keptCardKey,fe.current=o.placedGoods===null?null:JSON.stringify([o.placedGoods,null]),ln.current=o.authed;let u=o.placedRequest&&mn(o.placedRequest);We.current=u,Fe.current=u?()=>s(u):null,o.unpaidOrder&&le(o.unpaidOrder),o.lines.length>0&&(C(o.lines),$e.current=o.lines,ri(!0)),o.form&&(_t.current=o.form,hr(o.form))}ei(!0)},[]),Y(()=>{!tt||r.length>0||Kt.current||Q||(mt.current=!0,ft())},[tt,r.length]),Y(()=>{let o=Mt.current;!tt||!o||r.length===0||(Mt.current=null,D(o,ne||void 0))},[tt,r.length]),Y(()=>{!tt||Q||pn(Ue)},[tt,Q,Ue,G]);let Ye=q(null);Y(()=>{ur.current||(oe!==Ye.current&&(Ye.current=null),!(!Me.current||!G||G.orderNumber)&&(oe===fe.current||oe===Ye.current||dr(()=>br(G))))},[oe,G]);async function br(o){if(Tt.current)return null;Tt.current=!0;try{let s=et.current?await Mo(et.current):"none";if(s==="succeeded"||s==="processing")return Me.current=!1,le(null),we("card"),s==="succeeded"?await Be(void 0,o):Er(o),null;if(s===void 0||!_o.has(s))return Ye.current=ge.current,le(o),se(s==="requires_action"?Fo:_e),null;let u=await Nn(Ue);if(u==="committed")return Me.current=!1,le(null),we("card"),await Be(void 0,o),null;if(u!=="released")return Ye.current=ge.current,le(o),se(_e),null;Me.current=!1,et.current=null,Ye.current=null,se(null),le(null);let P=vt();return Rt(P),P}finally{Tt.current=!1}}async function ai(){n||Q||Tt.current||await dr(ii)}async function ii(){if(G){if((Me.current?oe!==fe.current:gt())&&!G.orderNumber){let P=await br(G);P&&ge.current===oe&&await vr(P);return}se(null),It.current=!1,await gn();let s=he(ge.current)[1],u=G.orderNumber?s:"card";if(u&&la.has(u)&&gt()&&he(ge.current)[0]!==un.current){xr(G);return}we(u),u!==j&&ie(u),await Rr(G,u,!G.orderNumber);return}await vr(Ue)}async function vr(o){if(r.length===0||a.repricing||fn||!j||!Qe.some(A=>A.key===j))return;let s=r.filter(bt).flatMap(A=>jt(A.components,A.qty));if(s.length===0){se("Pick a size on each wheel's product page before checking out.");return}se(null);let u,P=o,m=j,T=!1;try{let A=dt?$.createOrderAuthed:$.createOrder,F={customer:{email:ne,name:`${z} ${Oe}`.trim(),phone:xe.trim()||void 0,companyName:U.trim()||void 0,address:Lt,city:L,state:ke||void 0,zipCode:pe,country:W},items:s,currency:a.currency,idempotencyKey:o,shippingMethodId:f??void 0,couponCode:hn(c),...ua(),...Io(j)?{checkoutFlow:Ct}:{}};Fe.current=()=>A(F),We.current=F,ln.current=!!dt,mt.current=!1,Vn(null),un.current=null,It.current=!1,et.current=null,Me.current=!1,Ye.current=null,fe.current=oe,$e.current=r;let J=Pe.current,Dt=J?.key===F.idempotencyKey&&(J.shape!==oe&&(!!F.checkoutFlow||!!J.method||!!J.plainMethod)||!!F.checkoutFlow&&!!J.plainMethod);Dt&&(qe.current=F.idempotencyKey);let Lr=wr(F,A),Ir=Dt||!F.checkoutFlow&&qe.current===F.idempotencyKey,Tr=!Lr&&!Ir&&!F.checkoutFlow&&!!J&&!J.method;Tr&&(J.plainMethod=j,J.plainLines=r,J.plainShape=oe,pn(F.idempotencyKey));let ze=await(Ir?Cr(F,A):A(F).then(yt=>({answer:yt,request:F})).catch(yt=>(Lr?kr(yt,F.idempotencyKey):Tr&&En(yt)&&(J.plainMethod=""),si(yt,F,A))));if(!ze)return;u=ze.answer,P=ze.request.idempotencyKey,m=ze.method??m,we(m),T=gt()||m!==he(ge.current)[1],ze.method&&ze.method!==j&&ie(ze.method),u.orderNumber&&(Nr(u),E()),await gn()}catch(A){let F=Kr(A);F?(d(F),se(`${F} Your order has not been placed. Place it again to continue without the code.`)):A instanceof at?se(_e):se(A instanceof ue?A.message:"Could not place the order. Please try again.");return}if(m&&la.has(m)&&(T||gt())){xr(u);return}await Rr(u,m,!1,P)}function xr(o){un.current=he(ge.current)[0],se(`${ca(o,null)} ${wn}`),le(o)}function kr(o,s){En(o)&&!Sn(o)&&Pe.current?.key===s&&(Pe.current=null)}async function si(o,s,u){if(Gt(o))return Pr(s,u);if(!Sn(o))throw o;return qe.current=s.idempotencyKey,Cr(s,u,!0)}async function Cr(o,s,u=!1){let P=await Nn(o.idempotencyKey);if(P==="released")return Pr(o,s);if(P!=="committed")throw new at;let m=Pe.current?.key===o.idempotencyKey?Pe.current:null;if($e.current=m?.lines??r,m?.method&&!u){qe.current=null,Fe.current=m.send,We.current=m.request;let F=await m.send().catch(()=>{throw new at});return fe.current=m.shape,{answer:F,request:o,method:m.method}}let T=m&&!m.method?m.send:()=>s({...o,checkoutFlow:Ct});Fe.current=T,We.current=m&&!m.method?m.request:{...o,checkoutFlow:Ct};let A=await T().catch(()=>null);if(!A&&m?.plainMethod)throw new at;return A?.orderNumber&&A.status!==To?(qe.current=null,m?.plainMethod&&($e.current=m.plainLines),m&&(fe.current=m.plainMethod?m.plainShape:m.shape),{answer:A,request:o,method:m?.plainMethod||void 0}):(m&&(fe.current=m.shape),we("card"),await Sr("",A?async()=>A:()=>Promise.reject(new Error("The order request did not answer."))),await gn(),null)}function gt(){let o=fe.current;return o!==null&&he(o)[0]!==he(ge.current)[0]}function we(o){o!==he(ge.current)[1]&&(It.current=!0),Vn(It.current||gt()?wn:null)}async function Pr(o,s){let u={...o,idempotencyKey:vt()};qe.current=null,Rt(u.idempotencyKey),Fe.current=()=>s(u),We.current=u,wr(u,s);try{return{answer:await s(u),request:u}}catch(P){throw kr(P,u.idempotencyKey),P}}function wr(o,s){return Pe.current?.key===o.idempotencyKey?!1:(Pe.current={key:o.idempotencyKey,send:()=>s(o),request:o,lines:r,shape:oe,method:o.checkoutFlow?"":j??"",plainMethod:"",plainLines:r,plainShape:oe},mt.current=!1,pn(o.idempotencyKey),!0)}function Nr(o){Wr({confirmation:o,lines:$e.current,adsSendTo:e.googleAdsId&&e.googleAdsConversionLabel?`${e.googleAdsId}/${e.googleAdsConversionLabel}`:null}),Go({confirmation:o,lines:$e.current})}async function Be(o,s=Te){if(!s)return;let u=o?async()=>o:Fe.current;if(s.orderNumber||!u){Ze(!0),me(s);return}await Sr(s.checkoutNumber,u)}async function Sr(o,s){E(),await jo({checkoutNumber:o,resend:s,page:{setConfirming:Ga,land:me,markPaid:()=>Ze(!0),track:Nr,unplaced:ar}})}function Er(o=Te){if(o){if(o.orderNumber){me(o);return}E(),ar({kind:"processing",checkoutNumber:o.checkoutNumber})}}async function gn(){let o=JSON.stringify([an.trim(),z,Oe,xe.trim(),Lt,L,ke,pe,W]);if(!(!dt||!Hn||on!=="new"||Xn.current===o))try{await nt.createAddress({label:an.trim()||"Home",contact_name:`${z} ${Oe}`.trim(),phone:xe.trim(),address:Lt,city:L,zip_code:pe,state:ke,country:W}),Xn.current=o,Jn("Address saved to your account.")}catch{Jn("We couldn't save the address to your account \u2014 you can add it under Account \u2192 Addresses.")}}async function Rr(o,s=j,u=!1,P=Ue){le(null);try{if(s==="card"&&e.paymentMethods.includes("card")){let m=await $.createPaymentIntent({idempotencyKey:P});et.current=m;let T=o;if(u){let A=await Fe.current?.().catch(()=>null);if(A?.orderNumber){we("card"),await Be(A,o);return}T=Or(o,A)??{...o,expiresAt:null}}we("card"),Xe(T),cn(!1),Ot(m)}else if(s==="paypal"&&e.paymentMethods.includes("paypal"))Xe(o),_a(!0);else if(s==="afterpay"&&e.paymentMethods.includes("afterpay")){let m=window.location.origin,T=await $.createAfterpayCheckout({idempotencyKey:P,confirmUrl:`${m}/checkout?afterpay=confirm`,cancelUrl:`${m}/checkout?afterpay=cancel`});qt(Rn,P,o,T.redirectCheckoutUrl);return}else if(s==="square"&&e.paymentMethods.includes("square"))Xe(o),Ka(!0);else if(s==="gocardless"&&e.paymentMethods.includes("gocardless")){let m=window.location.origin,T=await $.createGocardlessBillingRequest({idempotencyKey:P,confirmUrl:`${m}/checkout?gocardless=confirm`,cancelUrl:`${m}/checkout?gocardless=cancel`});qt(Vt,P,o,T.authorisationUrl);return}else if(s==="zip"&&e.paymentMethods.includes("zip")){let m=window.location.origin,T=await $.createZipCheckout({idempotencyKey:P,redirectUrl:`${m}/checkout?zip=return`});qt(On,P,o,T.redirectUrl);return}else if(s==="klarna"&&e.paymentMethods.includes("klarna")){let m=window.location.origin,T=await $.createKlarnaCheckout({idempotencyKey:P,confirmUrl:`${m}/checkout?klarna=confirm`,cancelUrl:`${m}/checkout?klarna=cancel`});qt(Xt,P,o,T.redirectUrl);return}else we(s),me(o)}catch(m){if((u||s==="card")&&m instanceof ue&&m.status===409){we(s),await Be(void 0,o);return}Ar(o,m)}}function Or(o,s){return s&&!s.orderNumber&&s.status==="open"&&s.checkoutNumber===o.checkoutNumber?s:null}function Ar(o,s){se(ca(o,s)),!o.orderNumber&&Gt(s)?(Me.current=!1,Rt(vt())):le(o)}async function ci(o){if(!Te)return;let s=Te;try{let u=await $.createPaymentIntent({idempotencyKey:Ue}),P=await Fe.current?.().catch(()=>null);if(P?.orderNumber){await Be(P);return}let m=Or(s,P);Xe(m??{...s,expiresAt:null}),cn(o&&m!==null),et.current=u,Ot(u)}catch(u){if(u instanceof ue&&u.status===409){await Be();return}Ot(null),Xe(null),Ar(s,u)}}function li(){Te&&(Me.current=!0,le(Te),Ot(null),Xe(null),cn(!1))}return{site:e,logo:t,items:r,totals:oi,coupon:c,deliveryOptions:g,courierUnavailable:Aa,retryCourier:La,shippingMethodId:f,setShippingMethodId:p,pickupLocation:O,servedCountries:B,formatMoney:de,payChoice:j,setPayChoice:ie,placing:Q,email:ne,setEmail:ee,firstName:z,setFirstName:b,lastName:Oe,setLastName:je,company:U,setCompany:st,address1:Z,setAddress1:ve,address2:Ae,setAddress2:Le,city:L,setCity:re,postcode:pe,setPostcode:Ie,phone:xe,setPhone:ct,country:W,setCountry:lt,subdivision:ke,setSubdivision:Nt,subdivisions:ut,destination:$n,postcodeLabel:Ra,subdivisionLabel:Oa,me:dt,savedAddresses:Ia,selectedAddressId:on,setSelectedAddressId:Et,saveAddress:Hn,setSaveAddress:Gn,saveLabel:an,setSaveLabel:Ta,addressSaveNote:Fa,lostChangeNote:qa,idemKey:Ue,confirmation:sn,setConfirmation:me,orderError:Ma,payment:Zn,paypalStep:Qn,squareStep:er,pendingConf:Te,paid:Da,setPaid:Ze,unpaidOrder:G,orderLocked:tr,formLocked:ja,restoredPrices:gr,payNote:Ua,afterpayConfirming:Wa,gocardlessConfirming:Ya,zipConfirming:Ba,klarnaConfirming:Ha,cardConfirming:or,checkoutResult:pt,confirmCardPayment:Be,cardStillProcessing:Er,renewCardPayment:ci,holdRenewed:Ja,leaveCardPayment:li,checkoutRootRef:cr,setCheckoutHeaderEl:Va,fillFromAddress:lr,checkoutSignOut:Xa,payOptions:Qe,noPaymentMethod:Za,placeOrder:ai}}var fa=os(null);function ga({children:e,...t}){let n=cs(t);return Se(fa.Provider,{value:n,children:e})}function Ee(){let e=as(fa);if(!e)throw new Error("useCheckout must be used inside CheckoutStateProvider");return e}import{useId as Kn}from"react";import{Fragment as Ke,jsx as i,jsxs as N}from"react/jsx-runtime";function ha(){let{email:e,setEmail:t,firstName:n,setFirstName:r,lastName:a,setLastName:c,company:d,setCompany:g,me:f,checkoutSignOut:p,orderLocked:h,unpaidOrder:k}=Ee(),v=Kn();return N(en,{num:"N\xB0 01",title:"Contact",children:[h&&k&&i(us,{orderNumber:k.orderNumber}),i(ae,{label:"Email",htmlFor:v,hint:f?N(Ke,{children:["Signed in \xB7"," ",i("button",{type:"button",onClick:p,className:"underline transition-colors enabled:hover:text-accent",children:"Not you? Sign out"})]}):void 0,children:i("input",{id:v,type:"email",value:e,onChange:y=>t(y.target.value),placeholder:"you@example.com",readOnly:f!==null,className:te})}),N(Ca,{children:[i(ae,{label:"First name",children:i("input",{type:"text",value:n,onChange:y=>r(y.target.value),className:te})}),i(ae,{label:"Last name",children:i("input",{type:"text",value:a,onChange:y=>c(y.target.value),className:te})})]}),i(ae,{label:"Company (optional)",children:i("input",{type:"text",value:d,onChange:y=>g(y.target.value),autoComplete:"organization",className:te})})]})}function ba(){let{pickupLocation:e,servedCountries:t,address1:n,setAddress1:r,address2:a,setAddress2:c,city:d,setCity:g,postcode:f,setPostcode:p,phone:h,setPhone:k,country:v,setCountry:y,subdivision:E,setSubdivision:C,subdivisions:R,destination:D,postcodeLabel:O,subdivisionLabel:S,me:B,savedAddresses:X,selectedAddressId:de,setSelectedAddressId:j,saveAddress:ie,setSaveAddress:Re,saveLabel:De,setSaveLabel:Q,fillFromAddress:be,orderLocked:ne}=Ee(),ee=Kn(),z=Kn();return N(en,{num:"N\xB0 02",title:e?"Collection":"Shipping address",children:[e?N("div",{className:"grid gap-2 text-[14px] leading-[1.6]",children:[i("span",{className:"font-medium",children:e.name}),[e.address,e.city,e.state,e.zipCode,e.country].filter(Boolean).length>0&&i("span",{className:"opacity-80",children:[e.address,e.city,e.state,e.zipCode,e.country].filter(Boolean).join(", ")}),e.openingHours&&i("span",{className:"opacity-80",children:e.openingHours}),e.instructions&&i("span",{className:"opacity-80",children:e.instructions}),i("span",{className:"mt-1 font-mono text-[11px] uppercase tracking-[0.2em] text-fg-dim",children:"No delivery address needed"})]}):N(Ke,{children:[B!==null&&X.length>0&&N("div",{className:"grid gap-3",children:[X.map(b=>i(Zt,{active:de===b.id,onClick:()=>{j(b.id),be(b)},title:b.label,body:b.formatted_address,price:null},b.id)),i(Zt,{active:de==="new",onClick:()=>j("new"),title:"New address",body:null,price:null})]}),i(ae,{label:"Address line 1",children:i("input",{type:"text",value:n,onChange:b=>r(b.target.value),className:te})}),i(ae,{label:"Address line 2",children:i("input",{type:"text",value:a,onChange:b=>c(b.target.value),placeholder:"Apartment, unit, garage bay\u2026",className:te})}),N(Ca,{cols:"three",children:[i(ae,{label:"City",children:i("input",{type:"text",value:d,onChange:b=>g(b.target.value),className:te})}),i(ae,{label:O,children:i("input",{type:"text",value:f,onChange:b=>p(b.target.value),className:te})}),i(ae,{label:"Country",separate:!0,htmlFor:ee,children:i(vn,{id:ee,value:v,onChange:b=>y(b.target.value),className:te+" pr-10",style:ya,children:t.map(b=>i("option",{value:b.code,children:b.name},b.code))})})]}),i(ae,{label:S,separate:!0,htmlFor:z,children:R.length>0?N(vn,{id:z,value:E,onChange:b=>C(b.target.value),className:te+" pr-10",style:ya,children:[i("option",{value:"",children:"Select\u2026"}),R.map(b=>i("option",{value:b.code||b.name,children:b.name},b.code||b.name))]}):i("input",{id:z,type:"text",value:E,onChange:b=>C(b.target.value),className:te})})]}),i(ae,{label:"Phone",children:i("input",{type:"tel",value:h,onChange:b=>k(b.target.value),className:te})}),!e&&B!==null&&de==="new"&&!ne&&N(Ke,{children:[i(ds,{checked:ie,onChange:Re,label:"Save this address to my account"}),ie&&i(ae,{label:"Address label",children:i("input",{type:"text",value:De,onChange:b=>Q(b.target.value),placeholder:"Home",className:te})})]})]})}function va(){let{totals:e,coupon:t,deliveryOptions:n,shippingMethodId:r,setShippingMethodId:a,pickupLocation:c,formatMoney:d,city:g,destination:f,courierUnavailable:p,retryCourier:h}=Ee();return i(en,{num:"N\xB0 03",title:"Shipping",children:N("div",{className:"grid gap-3",children:[n.map(k=>{let v=k.pickupLocation,y=v?[v.address,v.city,v.state,v.zipCode].filter(Boolean).join(", "):null;return i(Zt,{active:r===k.id,onClick:()=>a(k.id),title:v?`${k.name} \u2014 ${v.name}`:k.name,body:v?[y,v.openingHours,v.instructions,k.description].filter(Boolean).join(" \xB7 "):k.description||null,price:e.freeShipping||k.amount===0?Ut:d(k.amount,e.currency),tag:k.tag||void 0},k.id)}),p?N("p",{className:"font-mono text-[11px] uppercase tracking-[0.2em] text-fg-dim",children:[pa," ",i("button",{type:"button",onClick:h,className:"underline transition-colors enabled:hover:text-accent",children:"Try again"})]}):n.length===0&&i("p",{className:"font-mono text-[11px] uppercase tracking-[0.2em] text-fg-dim",children:"Shipping is arranged after your order is reviewed."})]})})}function xa(){let{payChoice:e,setPayChoice:t,payment:n,payOptions:r,noPaymentMethod:a}=Ee();return N(en,{num:"N\xB0 04",title:"Payment",children:[a&&i("p",{className:"font-mono text-[11px] uppercase tracking-[0.2em] text-fg-dim",children:da}),i("div",{className:"grid gap-3",children:r.map(c=>i(Zt,{active:e===c.key,onClick:()=>t(c.key),title:c.title,body:c.body,price:c.price,tag:c.tag},c.key))}),e==="card"?i("p",{className:"font-mono text-[11px] uppercase tracking-[0.2em] text-fg-dim",children:"You\u2019ll enter card details on the secure payment step after placing the order."}):e==="paypal"?i("p",{className:"font-mono text-[11px] uppercase tracking-[0.2em] text-fg-dim",children:"You\u2019ll approve the payment with PayPal on the payment step after placing the order."}):e==="afterpay"?i("p",{className:"font-mono text-[11px] uppercase tracking-[0.2em] text-fg-dim",children:"You\u2019ll be taken to Afterpay to approve four interest-free payments, then brought straight back."}):e==="square"?i("p",{className:"font-mono text-[11px] uppercase tracking-[0.2em] text-fg-dim",children:"You\u2019ll enter card details on the secure payment step after placing the order."}):e==="gocardless"?i("p",{className:"font-mono text-[11px] uppercase tracking-[0.2em] text-fg-dim",children:"You\u2019ll set up a bank direct debit with GoCardless, then be brought straight back. Direct debits clear in a few days."}):e==="zip"?i("p",{className:"font-mono text-[11px] uppercase tracking-[0.2em] text-fg-dim",children:"You\u2019ll be taken to Zip to approve four instalments, then brought straight back."}):e==="klarna"?i("p",{className:"font-mono text-[11px] uppercase tracking-[0.2em] text-fg-dim",children:"You\u2019ll be taken to Klarna to choose how to pay, then brought straight back."}):e==="bank"?i("p",{className:"font-mono text-[11px] uppercase tracking-[0.2em] text-fg-dim",children:"Our team emails you the invoice and bank details after review."}):null]})}function ka(){let{site:e,items:t,totals:n,coupon:r,formatMoney:a,payChoice:c,placing:d,email:g,orderError:f,payment:p,noPaymentMethod:h,unpaidOrder:k,formLocked:v,restoredPrices:y,placeOrder:E}=Ee(),C=y==="waiting",R=y==="changed";return N("aside",{className:"sticky top-[var(--sf-checkout-header-h,88px)] border border-line max-view-desktop:static",style:{background:"linear-gradient(180deg, color-mix(in oklab, var(--site-surface) 70%, var(--bg)) 0%, var(--bg) 100%)"},children:[N("header",{className:"flex items-center justify-between border-b border-accent bg-accent px-6 py-4 font-mono text-[13px] font-bold uppercase tracking-[0.28em] text-bg",children:[i("span",{children:"Your order"}),i(wt,{href:"/wheels",className:"text-bg/80 transition-colors hover:text-bg",children:"Edit \u2197"})]}),i("div",{className:"flex flex-col px-6 py-2",children:t.length===0?N("div",{className:"py-8 text-center font-serif text-[16px] italic leading-[1.5] text-fg-dim",children:["Your cart is empty. ",i(wt,{href:"/wheels",className:"text-accent underline-offset-4 hover:underline",children:"Browse the catalog \u2192"})]}):t.map(D=>i(ps,{slug:D.slug,name:D.name,qty:D.qty,config:D.config,configSummary:ms(D.config),price:R||C?null:zr(D,n.currency)??0,currency:n.currency},D.id))}),i(Qt,{locked:v,className:"border-t border-line px-6 pt-5",children:i(Xr,{customerEmail:g,disabled:v})}),N("div",{className:"flex flex-col gap-2 border-t border-line mt-5 px-6 pt-5",children:[i(Ge,{label:"Subtotal",value:C?jr:a(R?n.serverSubtotal??0:n.subtotal,n.currency)}),n.discount>0&&r?.valid&&i(Ge,{label:`Coupon \xB7 ${r.code}`,value:N("span",{className:"font-semibold text-green",children:["\u2212 ",a(n.discount,n.currency)]})}),r?.deferred&&i(Ge,{label:`Coupon \xB7 ${r.code}`,value:_r}),r?.valid&&r.effects?.gift&&i(Ge,{label:`Free gift \xB7 ${r.effects.gift.partNumber}${r.effects.gift.quantity>1?` \xD7${r.effects.gift.quantity}`:""}`,value:i("span",{className:"font-semibold text-green",children:Ut})}),i(Ge,{label:"Shipping",value:n.shippingStatus==="free"?i("span",{className:"font-semibold text-green",children:Ut}):Yr(n.shippingStatus)??a(n.shipping,n.currency)}),n.tax&&(n.tax.charged?i(Ge,{label:n.tax.inclusive?`${n.tax.name} included \xB7 ${n.tax.rate}%`:n.tax.name,value:a(n.tax.amount,n.currency)}):n.tax.name?i(Ge,{label:n.tax.name,value:$r}):null)]}),N("div",{className:"mt-4 flex items-end justify-between border-y-2 border-accent px-6 py-4",style:{background:"color-mix(in oklab, var(--accent) 10%, var(--bg))"},children:[i("span",{className:"font-display text-[20px] font-bold uppercase tracking-[0.04em] text-fg",children:"Total"}),i("span",{className:"text-right font-display text-[34px] font-bold leading-none tracking-[-0.025em] text-fg",children:n.repricing?Dr:a(n.grand,n.currency)})]}),N("div",{className:"flex flex-col gap-3 px-6 pt-5 pb-6",children:[R&&i(Ne,{tone:"quiet",children:Qo}),f&&i(Ne,{role:"alert",children:f}),n.hasUnpricedLine&&N(Ne,{role:"status",children:["One or more items have no price in ",n.currency,". Remove them, or switch region, to continue."]}),i("button",{type:"button",onClick:E,disabled:d||!k&&(h||t.length===0||n.hasUnpricedLine||n.repricing),className:["group flex items-center justify-between border px-5 py-5 font-mono text-[14px] font-medium uppercase tracking-[0.3em] transition-all",d||!k&&(t.length===0||h||n.hasUnpricedLine||n.repricing)?"cursor-not-allowed border-line bg-surface text-fg-dim":"border-btn bg-btn text-btn-ink hover:border-fg hover:bg-fg"].join(" "),children:d?N(Ke,{children:["Building order\u2026 ",i("span",{children:"\xB7"})]}):h?N(Ke,{children:["No online payment ",i("span",{children:"\xB7"})]}):k?N(Ke,{children:["Try payment again \xB7 ",Jt(k),i("span",{className:"transition-transform group-hover:translate-x-1",children:"\u2192"})]}):n.repricing?N(Ke,{children:["Updating total\u2026 ",i("span",{children:"\xB7"})]}):N(Ke,{children:[c==="bank"?"Place order":"Continue to payment"," \xB7"," ",a(n.grand,n.currency),i("span",{className:"transition-transform group-hover:translate-x-1",children:"\u2192"})]})})]})]})}var ls=" [&:disabled_:disabled]:cursor-not-allowed! [&:disabled_:disabled]:opacity-70! [&_input[readonly]]:cursor-not-allowed [&_input[readonly]]:opacity-70";function Qt({locked:e,className:t="",children:n}){return i("fieldset",{disabled:e,className:"m-0 min-w-0 border-0 p-0 "+t+ls,children:n})}function wt({href:e,className:t="",children:n,...r}){let{placing:a}=Ee();return a?i("span",{"aria-disabled":"true","aria-label":r["aria-label"],className:t+" pointer-events-none",children:n}):i(He,{href:e,"aria-label":r["aria-label"],className:t,children:n})}function us({orderNumber:e}){return i(Ne,{tone:"quiet",role:"status",children:N("span",{className:"flex items-start gap-2",children:[N("svg",{"aria-hidden":!0,viewBox:"0 0 16 16",width:"16",height:"16",fill:"none",stroke:"currentColor",strokeWidth:"1.5",className:"mt-[3px] shrink-0",children:[i("rect",{x:"3",y:"7",width:"10",height:"7",rx:"1"}),i("path",{d:"M5 7V5a3 3 0 0 1 6 0v2"})]}),i("span",{children:ma(e)})]})})}var ya={backgroundImage:"linear-gradient(45deg, transparent 50%, var(--accent) 50%), linear-gradient(135deg, var(--accent) 50%, transparent 50%)",backgroundPosition:"calc(100% - 18px) 50%, calc(100% - 12px) 50%",backgroundSize:"6px 6px",backgroundRepeat:"no-repeat"};function en({num:e,title:t,children:n}){return N("section",{className:"mb-6 border border-line bg-bg",children:[N("header",{className:"flex items-center gap-4 border-b border-line bg-surface px-6 py-4",children:[i("span",{className:"inline-flex items-center justify-center bg-accent px-3 py-1 font-mono text-[11px] font-bold uppercase tracking-[0.24em] text-bg",children:e}),i("h2",{className:"font-display text-[26px] font-medium uppercase leading-none tracking-[-0.02em] text-fg",children:t})]}),i("div",{className:"flex flex-col gap-4 px-6 py-6",children:n})]})}function Ca({cols:e="two",children:t}){return i("div",{className:["grid gap-3 max-[640px]:grid-cols-1",e==="two"?"grid-cols-2":"grid-cols-[1.2fr_1fr_1fr]"].join(" "),children:t})}function Zt({active:e,onClick:t,title:n,body:r,price:a,tag:c}){return N("button",{type:"button",onClick:t,"aria-pressed":e,className:["relative grid grid-cols-[auto_1fr_auto] items-center gap-5 border bg-bg px-6 py-5 text-left transition-colors",e?"border-accent outline outline-1 outline-accent -outline-offset-1":"border-line enabled:hover:border-[color-mix(in_oklab,var(--accent)_50%,var(--site-line))]"].join(" "),style:e?{background:"color-mix(in oklab, var(--accent) 14%, var(--bg))"}:void 0,children:[e&&i("span",{"aria-hidden":!0,className:"absolute inset-y-0 left-0 w-[3px] bg-accent"}),i("span",{className:["flex h-[18px] w-[18px] items-center justify-center rounded-full border-2",e?"border-accent":"border-fg-dim"].join(" "),children:e&&i("span",{className:"block h-2.5 w-2.5 rounded-full bg-accent"})}),N("span",{className:"flex min-w-0 flex-col gap-1",children:[N("span",{className:"flex flex-wrap items-baseline gap-3 font-display text-[18px] font-medium tracking-[-0.01em] text-fg",children:[n,c&&i("span",{className:"border px-2 py-0.5 font-mono text-[11px] font-normal uppercase tracking-[0.24em] text-accent",style:{background:"color-mix(in oklab, var(--accent) 14%, transparent)",borderColor:"color-mix(in oklab, var(--accent) 45%, var(--site-line))"},children:c})]}),r&&i("span",{className:"font-mono text-[12px] uppercase tracking-[0.22em] text-fg-dim",children:r})]}),i("span",{className:"whitespace-nowrap font-display text-[18px] font-medium tracking-[-0.01em] text-fg",children:a})]})}function ds({checked:e,onChange:t,label:n,sub:r}){return N("div",{className:"flex items-start gap-3 border-t border-line py-4 first:border-t-0 first:pt-0",children:[i("button",{type:"button",onClick:()=>t(!e),"aria-pressed":e,"aria-label":n,className:["mt-px flex h-5 w-5 flex-shrink-0 items-center justify-center border transition-colors",e?"border-accent":"border-line"].join(" "),style:e?{background:"color-mix(in oklab, var(--accent) 18%, transparent)"}:void 0,children:e&&i("span",{className:"text-[13px] text-accent",children:"\u2713"})}),N("span",{className:"flex-1 font-display text-[16px] leading-[1.5] text-fg",children:[n,r&&i("small",{className:"mt-1 block font-mono text-[12px] uppercase tracking-[0.18em] text-fg-dim",children:r})]})]})}function ps({slug:e,name:t,qty:n,config:r,configSummary:a,price:c,currency:d}){let{catalog:g}=Wt(),{formatMoney:f}=ye(),p=g.find(C=>C.slug===e),h=p?.spokes??5,k=p?.mesh??!1,v=r.find(C=>C.gold)?.label,y=p?.finishes.find(C=>C.name===v&&C.src)??p?.finishes.find(C=>C.src),E=p?.finishes[0]?.color??Vr;return N("div",{className:"grid grid-cols-[60px_1fr_auto] items-center gap-4 border-b border-line py-4 last:border-b-0",children:[N("div",{className:"relative aspect-square",children:[i("div",{className:"flex h-full w-full items-center justify-center overflow-hidden border border-line bg-surface",children:y?.src?i(Fr,{src:y.src,alt:`${t.lead}${t.accent} \u2014 ${y.name}`,width:120,height:120,sizes:"60px",className:"block h-full w-full object-contain p-2"}):i("div",{className:"block w-[78%]",style:{color:E},children:i(Jr,{spokes:h,mesh:k,className:"block w-full"})})}),i("span",{className:"absolute -right-1.5 -top-1.5 z-[2] flex h-[18px] w-[18px] items-center justify-center rounded-full bg-accent font-mono text-[11px] font-bold text-bg",children:n})]}),N("div",{className:"flex min-w-0 flex-col gap-0.5",children:[N("span",{className:"font-display text-[17px] font-bold uppercase leading-none tracking-[-0.005em] text-fg",children:[t.lead,i("em",{className:"font-serif font-normal italic text-accent tracking-[-0.005em] normal-case",children:t.accent})]}),i("span",{className:"font-mono text-[12px] uppercase leading-[1.5] tracking-[0.18em] text-fg-dim",children:a})]}),i("span",{className:"text-right font-display text-[17px] font-bold tracking-[-0.005em] text-fg",children:c===null?null:f(c,d)})]})}function Ge({label:e,value:t}){return N("div",{className:"flex items-center justify-between font-mono text-[13px] font-medium uppercase tracking-[0.18em] text-fg",children:[i("span",{children:e}),i("strong",{className:"font-display text-[16px] font-medium tracking-[-0.005em] normal-case text-fg",children:t})]})}function ms(e){return e.map(t=>t.label).join(" \xB7 ")}import{Fragment as H,jsx as l,jsxs as x}from"react/jsx-runtime";function Un(e){return l(ga,{...e,children:l(ys,{})})}function fs({order:e,paid:t}){let{formatMoney:n}=ye();if(!e.grandTotal||!e.currency)return null;let r=d=>n(Number(d),e.currency),a=Number(e.freightCharge??0),c=Number(e.discountAmount??0);return x("dl",{className:"grid w-full max-w-sm grid-cols-[1fr_auto] gap-x-6 gap-y-1 border-y border-line py-3 text-left text-sm",children:[(e.shippingMethod||a>0)&&x(H,{children:[x("dt",{className:"text-fg-dim",children:["Delivery",e.shippingMethod?` \xB7 ${e.shippingMethod}`:""]}),l("dd",{className:"text-right font-mono",children:r(e.freightCharge??"0")})]}),c>0&&x(H,{children:[x("dt",{className:"text-fg-dim",children:["Discount",e.couponCode?` \xB7 ${e.couponCode}`:""]}),x("dd",{className:"text-right font-mono",children:["\u2212",r(e.discountAmount??"0")]})]}),l("dt",{className:"text-fg",children:t?"Total paid":"Order total"}),l("dd",{className:"text-right font-mono text-fg",children:r(e.grandTotal)})]})}function gs({result:e,lostChangeNote:t=null}){let n=l("span",{className:"font-mono text-fg",children:e.checkoutNumber});return x("div",{className:"flex min-h-screen flex-col items-center justify-center gap-4 bg-bg px-6 text-center text-fg",children:[l("h1",{className:"font-display text-3xl",children:e.kind==="refunded"||e.kind==="expired"?"Order not placed":e.kind==="processing"?"Payment processing":"Payment received"}),l("p",{className:"text-fg-dim",children:e.kind==="refunded"?x(H,{children:["An item sold out or an offer ended while you paid for checkout ",n,". Your payment goes back to your card."]}):e.kind==="expired"?x(H,{children:["The hold on checkout ",n," ran out before your payment arrived. Your payment goes back to your card."]}):e.kind==="processing"?x(H,{children:["Your payment for checkout ",n," is being processed. When it goes through, we will email your order confirmation."]}):x(H,{children:["Thank you \u2014 your payment",e.checkoutNumber?x(H,{children:[" for checkout ",n]}):null," has gone through. We will email you the order number shortly."]})}),t&&e.kind!=="refunded"&&e.kind!=="expired"&&l("p",{className:"text-sm text-fg-dim",children:t}),l(He,{href:"/wheels",className:"mt-2 border-2 border-line px-6 py-3 font-mono text-[12px] uppercase tracking-[0.24em] hover:border-accent",children:"Continue browsing"})]})}function ys(){let{site:e,logo:t,items:n,placing:r,formLocked:a,email:c,me:d,addressSaveNote:g,lostChangeNote:f,idemKey:p,confirmation:h,setConfirmation:k,payment:v,paypalStep:y,squareStep:E,pendingConf:C,paid:R,setPaid:D,payNote:O,afterpayConfirming:S,gocardlessConfirming:B,zipConfirming:X,klarnaConfirming:de,cardConfirming:j,checkoutResult:ie,confirmCardPayment:Re,cardStillProcessing:De,renewCardPayment:Q,holdRenewed:be,leaveCardPayment:ne,checkoutRootRef:ee,setCheckoutHeaderEl:z}=Ee();return h?x("div",{className:"flex min-h-screen flex-col items-center justify-center gap-4 bg-bg px-6 text-center text-fg",children:[l("h1",{className:"font-display text-3xl",children:R?"Payment received":"Order received"}),x("p",{className:"text-fg-dim",children:[R?x(H,{children:["Thank you \u2014 your payment for order"," ",l("span",{className:"font-mono text-fg",children:h.orderNumber})," has gone through."," "]}):x(H,{children:["Thank you \u2014 your order ",l("span",{className:"font-mono text-fg",children:h.orderNumber})," is being reviewed by our team."," "]}),d?x(H,{children:["Track it under"," ",l(He,{href:"/account/orders",className:"text-accent underline",children:"your orders"}),"."]}):l(H,{children:"We\u2019ve emailed you a link to set a password and track it."})]}),l(fs,{order:h,paid:R}),f&&l("p",{className:"text-sm text-fg-dim",children:f}),O&&l("p",{className:"text-sm text-fg-dim",children:O}),g&&l("p",{className:"text-sm text-fg-dim",children:g}),!d&&x("p",{className:"text-sm text-fg-dim",children:["You can also"," ",l(He,{href:`/track?order=${encodeURIComponent(h.orderNumber)}`,className:"text-accent underline",children:"track this order"})," ","anytime with just your order number and email \u2014 no password needed."]}),l(He,{href:"/wheels",className:"mt-2 border-2 border-line px-6 py-3 font-mono text-[12px] uppercase tracking-[0.24em] hover:border-accent",children:"Continue browsing"})]}):ie?l(gs,{result:ie,lostChangeNote:f}):j?x("div",{className:"flex min-h-screen flex-col items-center justify-center gap-4 bg-bg px-6 text-center text-fg",children:[l("h1",{className:"font-display text-3xl",children:"Confirming your payment\u2026"}),l("p",{className:"font-mono text-[12px] uppercase tracking-[0.2em] text-fg-dim",children:"Placing your order \u2014 one moment."})]}):S?x("div",{className:"flex min-h-screen flex-col items-center justify-center gap-4 bg-bg px-6 text-center text-fg",children:[l("h1",{className:"font-display text-3xl",children:"Confirming your payment\u2026"}),l("p",{className:"font-mono text-[12px] uppercase tracking-[0.2em] text-fg-dim",children:"Checking with Afterpay \u2014 one moment."})]}):B?x("div",{className:"flex min-h-screen flex-col items-center justify-center gap-4 bg-bg px-6 text-center text-fg",children:[l("h1",{className:"font-display text-3xl",children:"Setting up your direct debit\u2026"}),l("p",{className:"font-mono text-[12px] uppercase tracking-[0.2em] text-fg-dim",children:"Confirming with GoCardless \u2014 one moment."})]}):X?x("div",{className:"flex min-h-screen flex-col items-center justify-center gap-4 bg-bg px-6 text-center text-fg",children:[l("h1",{className:"font-display text-3xl",children:"Confirming your payment\u2026"}),l("p",{className:"font-mono text-[12px] uppercase tracking-[0.2em] text-fg-dim",children:"Checking with Zip \u2014 one moment."})]}):de?x("div",{className:"flex min-h-screen flex-col items-center justify-center gap-4 bg-bg px-6 text-center text-fg",children:[l("h1",{className:"font-display text-3xl",children:"Confirming your payment\u2026"}),l("p",{className:"font-mono text-[12px] uppercase tracking-[0.2em] text-fg-dim",children:"Checking with Klarna \u2014 one moment."})]}):v&&C?l(hs,{payment:v,checkout:C,holdRenewed:be,onPaid:Re,onProcessing:De,onRenew:Q,onBack:ne}):y&&C?l(ks,{confirmation:C,clientId:e.paypalClientId??"",idemKey:p,onPaid:()=>{D(!0),k(C)},onSkip:()=>k(C)}):E&&C?l(Ps,{confirmation:C,applicationId:e.squareApplicationId??"",locationId:e.squareLocationId??"",environment:e.squareEnvironment??"production",idemKey:p,onPaid:()=>{D(!0),k(C)},onSkip:()=>k(C)}):x("div",{ref:ee,className:"bg-bg text-fg",children:[x("header",{ref:z,className:"sticky top-0 z-30 grid grid-cols-[1fr_auto_1fr] items-center gap-8 max-[640px]:grid-cols-[auto_minmax(0,1fr)_auto] max-[640px]:gap-3 border-b border-line px-[var(--sf-site-gutter,40px)] py-6 backdrop-blur-md max-[640px]:px-[min(20px,var(--sf-site-gutter,40px))] max-[640px]:py-4",style:{background:"color-mix(in oklab, var(--bg) 92%, transparent)"},children:[x(wt,{href:"/",className:"inline-flex items-center gap-3 font-mono text-[14px] uppercase tracking-[0.26em] text-fg-dim transition-colors hover:text-accent",children:["\u2190",l("span",{className:"max-[640px]:hidden",children:"Back to shop"})]}),l("div",{className:"flex min-w-0 justify-center max-[640px]:[container-type:inline-size]",children:l(wt,{href:"/","aria-label":`${e.name} home`,className:"inline-flex max-w-full items-center justify-center overflow-x-clip",children:l(Qr,{variant:"header",scrolled:!0,src:t?.url??null,reverse:t?.reverse??!1,reversedSrc:t?.reversed??null,inkIsDark:t?.inkIsDark??null,size:t?.size??"medium",sizePx:t?.sizePx??null,sizeUnit:t?.sizeUnit??null,siteName:e.name,fitWordmarkToContainer:!0,fitFloorPx:Zr})})}),e.cardPayments?x("span",{className:"flex items-center justify-end gap-3 font-mono text-[12px] uppercase tracking-[0.26em] text-fg-dim",children:[l("span",{className:"text-green",children:"\u25CF"}),l("span",{className:"max-[640px]:hidden",children:"Encrypted \xB7"})," Stripe"]}):l("span",{})]}),x("section",{className:"mx-auto flex max-w-[var(--sf-site-width,1600px)] flex-wrap items-center justify-between gap-x-8 gap-y-3 border-b border-line bg-surface px-[var(--sf-site-gutter,40px)] py-4 font-mono text-[13px] font-medium uppercase tracking-[0.24em] text-fg max-view-desktop:px-[min(24px,var(--sf-site-gutter,40px))]",children:[l("span",{className:"inline-flex items-center bg-accent px-3 py-1 font-bold text-bg",children:"Checkout"}),l("nav",{"aria-label":"Checkout steps",className:"flex flex-wrap items-center gap-5",children:[{n:"01",label:"Cart",state:"done"},{n:"02",label:"Ship & pay",state:"active"},{n:"03",label:"Confirmed",state:"pending"}].map(b=>x("span",{className:["relative flex items-center gap-2 transition-colors",b.state==="pending"?"text-fg-dim":"text-fg",b.state==="active"?"font-bold after:absolute after:inset-x-0 after:-bottom-1 after:h-[2px] after:bg-accent":""].join(" "),children:[l("span",{className:b.state==="done"?"text-accent font-bold":"",children:b.n}),l("span",{children:b.label})]},b.n))})]}),x("main",{className:"mx-auto grid max-w-[var(--sf-site-width,1600px)] grid-cols-[1fr_420px] items-start gap-16 px-[var(--sf-site-gutter,40px)] pt-10 pb-[100px] max-view-desktop:grid-cols-1 max-view-desktop:gap-10 max-view-desktop:px-[min(24px,var(--sf-site-gutter,40px))] max-view-desktop:pt-8 max-view-desktop:pb-20",children:[x("div",{children:[x(Qt,{locked:a,children:[l(ha,{}),l(ba,{}),l(va,{})]}),l(Qt,{locked:r,children:l(xa,{})})]}),l(ka,{})]}),l("footer",{className:"flex flex-wrap items-center justify-between gap-4 border-t border-line px-[var(--sf-site-gutter,40px)] py-6 font-mono text-[12px] uppercase tracking-[0.22em] text-fg-dim max-[640px]:px-[min(20px,var(--sf-site-gutter,40px))]",children:l("span",{children:Gr({legalName:e.legalName,foundedYear:e.foundedYear,siteName:e.name})})})]})}function hs({payment:e,checkout:t,holdRenewed:n,onPaid:r,onProcessing:a,onRenew:c,onBack:d}){let{formatMoney:g}=ye(),f=l("span",{className:"text-fg",children:g(Number(e.amount),e.currency)}),p=Pa(()=>Ht(e.publishableKey),[e.publishableKey]),h=Pa(()=>to(),[]);return l("div",{className:"flex min-h-screen flex-col items-center justify-center gap-6 bg-bg px-6 py-16 text-fg",children:x("div",{className:"w-full max-w-xl border border-line bg-bg",children:[x("header",{className:"flex items-center justify-between gap-4 border-b border-line bg-surface px-6 py-4",children:[l("span",{className:"inline-flex items-center justify-center bg-accent px-3 py-1 font-mono text-[11px] font-bold uppercase tracking-[0.24em] text-bg",children:Jt(t)}),l("h1",{className:"font-display text-[26px] font-medium uppercase leading-none tracking-[-0.02em] text-fg",children:"Payment"})]}),x("div",{className:"flex flex-col gap-4 px-6 py-6",children:[l("p",{className:"font-mono text-[12px] uppercase tracking-[0.2em] text-fg-dim",children:t.orderNumber?x(H,{children:["Your order is placed. Pay ",f," by card to confirm it now."]}):n?x(H,{children:["Your hold ran out, so your items are held again",t.expiresAt?` until ${wa(t.expiresAt)}`:"",". Enter your card again, then pay ",f,"."]}):x(H,{children:["Your items are held",t.expiresAt?` until ${wa(t.expiresAt)}`:"",". Pay ",f," by card to place your order."]})}),l(Pn,{stripe:p,options:{clientSecret:e.clientSecret,appearance:h},children:l(vs,{payment:e,checkout:t,onPaid:r,onProcessing:a,onRenew:c,onBack:d})},e.clientSecret)]})]})})}function wa(e){return new Date(e).toLocaleTimeString([],{hour:"numeric",minute:"2-digit"})}var bs=5;function vs({payment:e,checkout:t,onPaid:n,onProcessing:r,onRenew:a,onBack:c}){let{formatMoney:d}=ye(),g=wo(),f=Co(),[p,h]=Je(!1),[k,v]=Je(null),y=it(!1);async function E(){try{return(await g.retrievePaymentIntent(e.clientSecret)).paymentIntent?.status}catch{return}}async function C(O){let S=O;for(let B=0;S==="processing"&&B<bs;B+=1)await new Promise(X=>setTimeout(X,1e3)),S=await E()??S;if(S==="succeeded"){n();return}if(S==="processing"){r();return}v("Payment did not complete. Please try again."),h(!1)}async function R(){if(!g||!f||p)return;h(!0),v(null),y.current=!0;let O=await g.confirmPayment({elements:f,redirect:"if_required"}).catch(()=>null);if(!O){let S=await E();if(S==="succeeded"||S==="processing"){await C(S);return}v(S===void 0?_e:"Payment failed. Please try again."),h(!1);return}if(O.error){if(!t.orderNumber&&O.error.code==="payment_intent_unexpected_state"){let S=await E();if(S==="succeeded"||S==="processing"){await C(S);return}if(S===void 0){v(_e),h(!1);return}await a(S==="canceled"),h(!1);return}v(O.error.message??"Payment failed. Please try again."),h(!1);return}await C(O.paymentIntent?.status)}async function D(){if(p)return;if(!y.current){c();return}h(!0),v(null);let O=await E();if(O==="succeeded"||O==="processing"){await C(O);return}if(h(!1),O===void 0){v(_e);return}c()}return x("div",{className:"flex flex-col gap-4",children:[l(No,{}),k&&l(Ne,{role:"alert",children:k}),l("button",{type:"button",onClick:R,disabled:!g||!f||p,className:["group flex items-center justify-between border px-5 py-5 font-mono text-[14px] font-medium uppercase tracking-[0.3em] transition-all",!g||!f||p?"cursor-not-allowed border-line bg-surface text-fg-dim":"border-btn bg-btn text-btn-ink hover:border-fg hover:bg-fg"].join(" "),children:p?x(H,{children:["Processing\u2026 ",l("span",{children:"\xB7"})]}):x(H,{children:["Pay ",d(Number(e.amount),e.currency),l("span",{className:"transition-transform group-hover:translate-x-1",children:"\u2192"})]})}),!t.orderNumber&&!p&&x("button",{type:"button",onClick:D,className:"inline-flex items-center gap-3 self-start font-mono text-[12px] uppercase tracking-[0.26em] text-fg-dim transition-colors hover:text-accent",children:["\u2190",l("span",{children:"Back to checkout"})]})]})}var Na="paypal-sdk-js",Dn=null;function xs(e,t){let n=`${e}|${t}`;if(Dn?.key===n)return Dn.promise;let r=new Promise((a,c)=>{document.getElementById(Na)?.remove();let d=document.createElement("script");d.id=Na;let g=new URLSearchParams({"client-id":e,currency:t,intent:"capture"});d.src=`https://www.paypal.com/sdk/js?${g}`,d.onload=()=>{let f=window.paypal;f?a(f):c(new Error("PayPal SDK loaded without its namespace"))},d.onerror=()=>c(new Error("PayPal SDK failed to load")),document.head.appendChild(d)});return Dn={key:n,promise:r},r}function ks({confirmation:e,clientId:t,idemKey:n,onPaid:r,onSkip:a}){let{formatMoney:c}=ye(),d=it(null),[g,f]=Je(!1),[p,h]=Je(null),k=it(r);return k.current=r,Ea(()=>{let v=!1,y=null;return xs(t,e.currency).then(E=>{if(!(v||!d.current))return y=E.Buttons({style:{layout:"vertical",color:"gold",shape:"rect",label:"paypal"},createOrder:async()=>(await $.createPaypalOrder({idempotencyKey:n})).paypalOrderId,onApprove:async C=>{try{if((await $.capturePaypalOrder({idempotencyKey:n,paypalOrderId:C.orderID})).status==="paid"){k.current();return}h("PayPal did not complete the payment. Please try again.")}catch(R){h(R instanceof ue?R.message:"PayPal payment failed. Please try again.")}},onError:()=>{h("PayPal could not process the payment. Please try again.")}}),y.render(d.current).then(()=>{v||f(!0)})}).catch(()=>{v||h("PayPal could not be loaded. You can pay later \u2014 your order stands either way.")}),()=>{v=!0,y?.close?.()}},[t,e.currency,n]),l("div",{className:"flex min-h-screen flex-col items-center justify-center gap-6 bg-bg px-6 py-16 text-fg",children:x("div",{className:"w-full max-w-xl border border-line bg-bg",children:[x("header",{className:"flex items-center justify-between gap-4 border-b border-line bg-surface px-6 py-4",children:[l("span",{className:"inline-flex items-center justify-center bg-accent px-3 py-1 font-mono text-[11px] font-bold uppercase tracking-[0.24em] text-bg",children:e.orderNumber}),l("h1",{className:"font-display text-[26px] font-medium uppercase leading-none tracking-[-0.02em] text-fg",children:"PayPal"})]}),x("div",{className:"flex flex-col gap-4 px-6 py-6",children:[x("p",{className:"font-mono text-[12px] uppercase tracking-[0.2em] text-fg-dim",children:["Your order is placed. Pay"," ",l("span",{className:"text-fg",children:c(Number(e.grandTotal),e.currency)})," ","with PayPal to confirm it now."]}),!g&&!p&&l("p",{className:"font-mono text-[11px] uppercase tracking-[0.2em] text-fg-dim",children:"Loading PayPal\u2026"}),l("div",{ref:d}),p&&l(Ne,{role:"alert",children:p}),l("button",{type:"button",onClick:a,className:"self-center font-mono text-[11px] uppercase tracking-[0.24em] text-fg-dim underline-offset-4 transition-colors hover:text-accent hover:underline",children:"Pay later \u2014 our team will be in touch"})]})]})})}var Sa="square-web-sdk",jn=null;function Cs(e){let t=e==="sandbox"?"sandbox":"production";if(jn?.key===t)return jn.promise;let n=new Promise((r,a)=>{document.getElementById(Sa)?.remove();let c=document.createElement("script");c.id=Sa,c.src=t==="sandbox"?"https://sandbox.web.squarecdn.com/v1/square.js":"https://web.squarecdn.com/v1/square.js",c.onload=()=>{let d=window.Square;d?r(d):a(new Error("Square SDK loaded without its namespace"))},c.onerror=()=>a(new Error("Square SDK failed to load")),document.head.appendChild(c)});return jn={key:t,promise:n},n}function Ps({confirmation:e,applicationId:t,locationId:n,environment:r,idemKey:a,onPaid:c,onSkip:d}){let{formatMoney:g}=ye(),f=it(null),p=it(null),h=it(null),[k,v]=Je(!1),[y,E]=Je(!1),[C,R]=Je(null);Ea(()=>{let O=!1,S=null;return Cs(r).then(async B=>{if(O||!f.current)return;let X=B.payments(t,n);h.current=X,S=await X.card(),await S.attach(f.current),p.current=S,O||v(!0)}).catch(()=>{O||R("Square could not be loaded. You can pay later \u2014 your order stands either way.")}),()=>{O=!0,S?.destroy?.()}},[t,n,r]);async function D(){let O=p.current;if(!(!O||y)){E(!0),R(null);try{let S=await O.tokenize();if(S.status!=="OK"||!S.token){R(S.errors?.[0]?.message??"Please check the card details and try again."),E(!1);return}let B;try{B=(await h.current?.verifyBuyer?.(S.token,{amount:String(e.grandTotal),currencyCode:e.currency,intent:"CHARGE"}))?.token}catch{}if((await $.chargeSquare({idempotencyKey:a,sourceId:S.token,...B?{verificationToken:B}:{}})).status==="paid"){c();return}R("Square did not complete the payment. Please try again.")}catch(S){R(S instanceof ue?S.message:"Square payment failed. Please try again.")}E(!1)}}return l("div",{className:"flex min-h-screen flex-col items-center justify-center gap-6 bg-bg px-6 py-16 text-fg",children:x("div",{className:"w-full max-w-xl border border-line bg-bg",children:[x("header",{className:"flex items-center justify-between gap-4 border-b border-line bg-surface px-6 py-4",children:[l("span",{className:"inline-flex items-center justify-center bg-accent px-3 py-1 font-mono text-[11px] font-bold uppercase tracking-[0.24em] text-bg",children:e.orderNumber}),l("h1",{className:"font-display text-[26px] font-medium uppercase leading-none tracking-[-0.02em] text-fg",children:"Card"})]}),x("div",{className:"flex flex-col gap-4 px-6 py-6",children:[x("p",{className:"font-mono text-[12px] uppercase tracking-[0.2em] text-fg-dim",children:["Your order is placed. Pay"," ",l("span",{className:"text-fg",children:g(Number(e.grandTotal),e.currency)})," ","by card to confirm it now."]}),!k&&!C&&l("p",{className:"font-mono text-[11px] uppercase tracking-[0.2em] text-fg-dim",children:"Loading card form\u2026"}),l("div",{ref:f}),C&&l(Ne,{role:"alert",children:C}),l("button",{type:"button",onClick:D,disabled:!k||y,className:["group flex items-center justify-between border px-5 py-5 font-mono text-[14px] font-medium uppercase tracking-[0.3em] transition-all",!k||y?"cursor-not-allowed border-line bg-surface text-fg-dim":"border-btn bg-btn text-btn-ink hover:border-fg hover:bg-fg"].join(" "),children:y?x(H,{children:["Processing\u2026 ",l("span",{children:"\xB7"})]}):x(H,{children:["Pay ",g(Number(e.grandTotal),e.currency),l("span",{className:"transition-transform group-hover:translate-x-1",children:"\u2192"})]})}),l("button",{type:"button",onClick:d,disabled:y,className:"self-center font-mono text-[11px] uppercase tracking-[0.24em] text-fg-dim underline-offset-4 transition-colors hover:text-accent hover:underline",children:"Pay later \u2014 our team will be in touch"})]})]})})}import{jsx as tn}from"react/jsx-runtime";function ws(){let{settings:e,websiteName:t}=qr(),n=t?{...bn,name:t}:bn,r=e?{url:e.logoUrl,reversed:e.logoReversed??null,inkIsDark:e.logoInkIsDark??null,reverse:e.reverseLogo,size:e.logoSize,sizePx:e.logoSizePx,sizeUnit:e.logoSizeUnit??null}:null;return tn("div",{style:{position:"fixed",inset:0,zIndex:2147482e3,overflowY:"auto",background:"var(--bg)",color:"var(--fg)"},children:tn(Br,{children:tn(Hr,{preview:!0,children:tn(Un,{site:n,logo:r,preview:!0})})})})}export{ws as default};