efficient-storefront-blocks 0.130.12 → 0.130.13

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 +1 @@
1
- "use client";import{jsx as t,jsxs as m}from"react/jsx-runtime";import O from"next/link";import{useEffect as L}from"react";import{FormFieldInput as S,FormHoneypot as j,successMessageFor as I,useBoundForm as P,useFormSubmission as B}from"./formSubmission.js";import k from"./SectionNotice.js";import{ThanksCard as M}from"./ThanksCard.js";import{showsSentOnCanvas as _}from"../lib/content/thanks-slot.js";import{say as w}from"efficient-web-builder/format/lib/editor-words";import q from"./WebFormField.js";import{usePopupScope as W}from"./PopupHost.js";import{FIELD_INPUT_CLASS as F}from"../lib/field-input.js";import{cornerSidesShorthand as A,normalizeCornerSides as E}from"efficient-web-builder/format/lib/content/section-corners";import{cssLengthOf as H}from"efficient-web-builder/format/lib/content/css-length";import{withSideOnce as D}from"efficient-web-builder/format/lib/content/page-width";import{useSideSpaceOnce as R}from"efficient-web-builder/render/components/SideSpaceOnce";import{withRootPad as U}from"efficient-web-builder/render/lib/content/section-own-pads";import{useSectionPad as Y}from"./SectionPadScope.js";function $({field:e,value:n,onChange:a,cornersClass:o=""}){const r={field:e,value:n,onChange:a};return e.type==="checkbox"?m("label",{className:"flex items-start gap-3",children:[t(S,{...r,className:"mt-1 size-4 accent-accent"}),m("span",{className:"font-mono text-[12px] font-semibold uppercase tracking-[0.16em] text-fg",children:[e.label,e.required?t("span",{className:"text-accent",children:" *"}):null]})]}):t(q,{label:e.label,required:e.required,children:t(S,{...r,className:(e.type==="textarea"?F+" resize-y":F)+o})})}function G(e,n,a){if(typeof e!="number"||!Number.isFinite(e))return null;const o=H(Math.max(0,e),a),r=E(n);return{style:{"--form-control-radius":r===null?o:A(o,r)},className:" [border-radius:var(--form-control-radius)]"}}function J({formSlug:e,heading:n,intro:a,submitText:o,finePrint:r,form:u,editing:i=!1,nodeId:d="",thanks:x,showSent:f,buttonCorners:h,buttonCornerSides:g,buttonCornersUnit:b}={}){const N=R(),p=Y(),s=P(e,u),y=W();if(s===void 0)return t(k,{size:"short",children:w("Loading form…")});if(s===null)return t(k,{size:"short",children:i?w("Choose a form in the inspector, under Form."):"This form is unavailable."});const l=(n??"").trim()||s.title;return t("section",{className:"relative z-[2] border-t border-line bg-surface",children:m("div",{...U(D("mx-auto max-w-[var(--sf-site-width,1600px)] px-[var(--sf-site-gutter,40px)] py-[84px] max-[960px]:px-[min(24px,var(--sf-site-gutter,40px))]",N),p),children:[l&&t("h2",{className:"mb-4 font-heading2 text-[length:min(var(--size-headingMedium,44px),var(--sf-heading-max,9999px))] font-medium uppercase leading-none tracking-[-0.02em] text-fg max-view-wide:text-[length:min(var(--size-headingMedium,32px),var(--sf-heading-max,9999px))]",children:l}),(a??"").trim()&&t("p",{className:"mb-12 max-w-[640px] font-display text-[16px] leading-[1.6] text-fg-dim",children:a}),t(Q,{form:s,formSlug:e,submitText:o,finePrint:r,editing:i,onSent:y?.markSent,nodeId:d,thanks:x,showSent:f,corners:G(h,g,b)})]})})}function K({account:e}){const n="font-mono text-[12px] uppercase tracking-[0.18em] text-fg-dim";switch(e?.status){case"approved":return m("p",{className:n,children:["Your account is ready."," ",t(O,{href:"/account",className:"underline",children:"Sign in"})]});case"pending":return t("p",{className:n,children:"We're reviewing your application and will email you once it's approved."});case"rejected":return t("p",{className:n,children:"We couldn't open an account from this application. Please contact the shop."});default:return null}}function Q({form:e,formSlug:n,submitText:a,finePrint:o,editing:r=!1,onSent:u,corners:i=null,nodeId:d="",thanks:x,showSent:f}){const{valueOf:h,set:g,honeypot:b,setHoneypot:N,submitting:p,done:s,account:y,error:l,handleSubmit:C}=B({form:e,formSlug:n,editing:r});L(()=>{s&&u?.()},[s]);const T=(a??"").trim()||e.submitButtonText?.trim()||"Submit",v=c=>m("div",{role:"status",className:"flex max-w-[560px] flex-col gap-3",children:[t("p",{className:"font-serif text-[19px] italic leading-[1.6] text-fg-dim",children:I(e)}),c,t(K,{account:y})]});return s||_(f,r)?t(M,{ownerId:d,ownerType:"Form",Template:x,message:v(null),children:v}):m("form",{className:"flex max-w-[720px] flex-col gap-5",style:i?.style,onSubmit:C,children:[e.fields.map(c=>t($,{field:c,value:h(c.key),onChange:z=>g(c.key,z),cornersClass:i?.className},c.key)),t(j,{value:b,onChange:N}),l&&t("p",{role:"alert",className:"font-mono text-[12px] uppercase tracking-[0.18em] text-alert",children:l}),t("button",{type:r?"button":"submit",disabled:p,className:`cursor-pointer self-start bg-btn px-8 py-4 font-mono text-[14px] uppercase tracking-[0.32em] text-btn-ink transition-colors hover:bg-fg hover:text-bg disabled:cursor-wait disabled:opacity-60${i?.className??""}`,children:p?"Sending…":T}),e.consentText?.trim()&&t("span",{className:"font-mono text-[12px] uppercase tracking-[0.18em] text-fg-dim/70",children:e.consentText}),(o??"").trim()&&t("span",{className:"font-mono text-[12px] uppercase tracking-[0.18em] text-fg-dim/70",children:o})]})}export{K as AccountOutcome,Q as FormBody,J as default};
1
+ "use client";import{jsx as t,jsxs as c}from"react/jsx-runtime";import O from"next/link";import{useEffect as L}from"react";import{FormFieldInput as S,FormHoneypot as j,successMessageFor as I,useBoundForm as P,useFormSubmission as B}from"./formSubmission.js";import k from"./SectionNotice.js";import{ThanksCard as M}from"./ThanksCard.js";import{showsSentOnCanvas as _}from"../lib/content/thanks-slot.js";import{say as w}from"efficient-web-builder/format/lib/editor-words";import q from"./WebFormField.js";import{usePopupScope as W}from"./PopupHost.js";import{FIELD_INPUT_CLASS as F}from"../lib/field-input.js";import{cornerSidesShorthand as A,normalizeCornerSides as E}from"efficient-web-builder/format/lib/content/section-corners";import{cssLengthOf as H}from"efficient-web-builder/format/lib/content/css-length";import{withSideOnce as D}from"efficient-web-builder/format/lib/content/page-width";import{useSideSpaceOnce as R}from"efficient-web-builder/render/components/SideSpaceOnce";import{withRootPad as U}from"efficient-web-builder/render/lib/content/section-own-pads";import{useSectionPad as $}from"./SectionPadScope.js";function G({field:e,value:r,onChange:s,cornersClass:o=""}){const n={field:e,value:r,onChange:s};return e.type==="checkbox"?c("label",{className:"flex items-start gap-3",children:[t(S,{...n,className:"mt-1 size-4 accent-accent"}),c("span",{className:"font-mono text-[12px] font-semibold uppercase tracking-[0.16em] text-fg",children:[e.label,e.required?t("span",{className:"text-accent",children:" *"}):null]})]}):t(q,{label:e.label,required:e.required,children:t(S,{...n,className:(e.type==="textarea"?F+" resize-y":F)+o})})}function J(e,r,s){if(typeof e!="number"||!Number.isFinite(e))return null;const o=H(Math.max(0,e),s),n=E(r);return{style:{"--form-control-radius":n===null?o:A(o,n)},className:" [border-radius:var(--form-control-radius)]"}}function K({formSlug:e,heading:r,intro:s,submitText:o,finePrint:n,form:u,editing:i=!1,nodeId:d="",thanks:x,showSent:f,buttonCorners:h,buttonCornerSides:g,buttonCornersUnit:b}={}){const y=R(),p=$(),a=P(e,u),N=W();if(a===void 0)return t(k,{size:"short",children:w("Loading form…")});if(a===null)return t(k,{size:"short",children:i?w("Choose a form in the inspector, under Form."):"This form is unavailable."});const l=(r??"").trim()||a.title;return t("section",{className:"relative z-[2] border-t border-line bg-surface",children:c("div",{...U(D("mx-auto max-w-[var(--sf-site-width,1600px)] px-[var(--sf-site-gutter,40px)] py-[84px] max-[960px]:px-[min(24px,var(--sf-site-gutter,40px))]",y),p),children:[l&&t("h2",{className:"mb-4 font-heading2 text-[length:min(var(--size-headingMedium,44px),var(--sf-heading-max,9999px))] font-medium uppercase leading-none tracking-[-0.02em] text-fg max-view-wide:text-[length:min(var(--size-headingMedium,32px),var(--sf-heading-max,9999px))]",children:l}),(s??"").trim()&&t("p",{className:"mb-12 max-w-[640px] font-display text-[16px] leading-[1.6] text-fg-dim",children:s}),t(V,{form:a,formSlug:e,submitText:o,finePrint:n,editing:i,onSent:N?.markSent,nodeId:d,thanks:x,showSent:f,corners:J(h,g,b)})]})})}function Q({account:e}){const r="font-mono text-[12px] uppercase tracking-[0.18em] text-fg-dim";switch(e?.status){case"approved":return c("p",{className:r,children:["Check your email to set your password, then"," ",t(O,{href:"/login",className:"underline",children:"Sign in"})]});case"pending":return t("p",{className:r,children:"We're reviewing your application and will email you once it's approved."});case"rejected":return t("p",{className:r,children:"We couldn't open an account from this application. Please contact the shop."});default:return null}}function V({form:e,formSlug:r,submitText:s,finePrint:o,editing:n=!1,onSent:u,corners:i=null,nodeId:d="",thanks:x,showSent:f}){const{valueOf:h,set:g,honeypot:b,setHoneypot:y,submitting:p,done:a,account:N,error:l,handleSubmit:C}=B({form:e,formSlug:r,editing:n});L(()=>{a&&u?.()},[a]);const T=(s??"").trim()||e.submitButtonText?.trim()||"Submit",v=m=>c("div",{role:"status",className:"flex max-w-[560px] flex-col gap-3",children:[t("p",{className:"font-serif text-[19px] italic leading-[1.6] text-fg-dim",children:I(e)}),m,t(Q,{account:N})]});return a||_(f,n)?t(M,{ownerId:d,ownerType:"Form",Template:x,message:v(null),children:v}):c("form",{className:"flex max-w-[720px] flex-col gap-5",style:i?.style,onSubmit:C,children:[e.fields.map(m=>t(G,{field:m,value:h(m.key),onChange:z=>g(m.key,z),cornersClass:i?.className},m.key)),t(j,{value:b,onChange:y}),l&&t("p",{role:"alert",className:"font-mono text-[12px] uppercase tracking-[0.18em] text-alert",children:l}),t("button",{type:n?"button":"submit",disabled:p,className:`cursor-pointer self-start bg-btn px-8 py-4 font-mono text-[14px] uppercase tracking-[0.32em] text-btn-ink transition-colors hover:bg-fg hover:text-bg disabled:cursor-wait disabled:opacity-60${i?.className??""}`,children:p?"Sending…":T}),e.consentText?.trim()&&t("span",{className:"font-mono text-[12px] uppercase tracking-[0.18em] text-fg-dim/70",children:e.consentText}),(o??"").trim()&&t("span",{className:"font-mono text-[12px] uppercase tracking-[0.18em] text-fg-dim/70",children:o})]})}export{Q as AccountOutcome,V as FormBody,K as default};
@@ -1 +1 @@
1
- "use client";import{jsx as e,Fragment as N,jsxs as a}from"react/jsx-runtime";import{useId as O}from"react";import X from"next/image";import Z from"next/link";import{lineTotal as J,useCart as ee}from"../CartContext.js";import{useCurrency as te}from"../CurrencyContext.js";import{Notice as _}from"../Notice.js";import{FREE_PRICE as A}from"../../lib/wheels/price-display.js";import ne from"../CouponField.js";import{COUPON_DEFERRED_TOTAL as ae}from"../../lib/cart/coupon-preview.js";import{orderReference as re}from"../../lib/checkout/pay-first.js";import{PRICES_REQUOTED as ie,PRICES_UNCHECKED as le}from"../../lib/checkout/checkout-memory.js";import{shippingWords as oe,TAX_PENDING as ce}from"../../lib/cart/shipping-status.js";import{DEFAULT_FINISH_COLOR as se}from"../../lib/wheels/finish-defaults.js";import U from"../ThemedSelect.js";import g from"../WebFormField.js";import de from"../WheelSvg.js";import{NO_PAYMENT_METHOD_NOTE as pe,placedOrderLockNote as me,SHIPPING_RETRY_NOTE as ue,useCheckout as w}from"./checkout-state.js";import{FIELD_INPUT_CLASS as u}from"../../lib/field-input.js";import{FIGURE_UPDATING as T}from"../../lib/wheels/price-display.js";function Me(){const{email:t,setEmail:i,firstName:n,setFirstName:l,lastName:s,setLastName:d,company:f,setCompany:v,me:b,checkoutSignOut:h,orderLocked:x,unpaidOrder:o}=w(),c=O();return a(L,{num:"N° 01",title:"Contact",children:[x&&o&&e(fe,{orderNumber:o.orderNumber}),e(g,{label:"Email",htmlFor:c,hint:b?a(N,{children:["Signed in ·"," ",e("button",{type:"button",onClick:h,className:"underline transition-colors enabled:hover:text-accent",children:"Not you? Sign out"})]}):void 0,children:e("input",{id:c,type:"email",value:t,onChange:p=>i(p.target.value),placeholder:"you@example.com",readOnly:b!==null,className:u})}),a(H,{children:[e(g,{label:"First name",children:e("input",{type:"text",value:n,onChange:p=>l(p.target.value),className:u})}),e(g,{label:"Last name",children:e("input",{type:"text",value:s,onChange:p=>d(p.target.value),className:u})})]}),e(g,{label:"Company (optional)",children:e("input",{type:"text",value:f,onChange:p=>v(p.target.value),autoComplete:"organization",className:u})})]})}function Ue(){const{pickupLocation:t,servedCountries:i,address1:n,setAddress1:l,address2:s,setAddress2:d,city:f,setCity:v,postcode:b,setPostcode:h,phone:x,setPhone:o,country:c,setCountry:p,subdivision:k,setSubdivision:m,subdivisions:E,destination:F,postcodeLabel:S,subdivisionLabel:y,me:B,savedAddresses:R,selectedAddressId:P,setSelectedAddressId:D,saveAddress:$,setSaveAddress:G,saveLabel:W,setSaveLabel:K,fillFromAddress:Q,orderLocked:V}=w(),M=O(),j=O();return a(L,{num:"N° 02",title:t?"Collection":"Shipping address",children:[t?a("div",{className:"grid gap-2 text-[14px] leading-[1.6]",children:[e("span",{className:"font-medium",children:t.name}),[t.address,t.city,t.state,t.zipCode,t.country].filter(Boolean).length>0&&e("span",{className:"opacity-80",children:[t.address,t.city,t.state,t.zipCode,t.country].filter(Boolean).join(", ")}),t.openingHours&&e("span",{className:"opacity-80",children:t.openingHours}),t.readyIn&&e("span",{className:"opacity-80",children:t.readyIn}),t.instructions&&e("span",{className:"opacity-80",children:t.instructions}),e("span",{className:"mt-1 font-mono text-[11px] uppercase tracking-[0.2em] text-fg-dim",children:"No delivery address needed"})]}):a(N,{children:[B!==null&&R.length>0&&a("div",{className:"grid gap-3",children:[R.map(r=>e(I,{active:P===r.id,onClick:()=>{D(r.id),Q(r)},title:r.label,body:r.formatted_address,price:null},r.id)),e(I,{active:P==="new",onClick:()=>D("new"),title:"New address",body:null,price:null})]}),e(g,{label:"Address line 1",children:e("input",{type:"text",value:n,onChange:r=>l(r.target.value),className:u})}),e(g,{label:"Address line 2",children:e("input",{type:"text",value:s,onChange:r=>d(r.target.value),placeholder:"Apartment, unit, garage bay…",className:u})}),a(H,{cols:"three",children:[e(g,{label:"City",children:e("input",{type:"text",value:f,onChange:r=>v(r.target.value),className:u})}),e(g,{label:S,children:e("input",{type:"text",value:b,onChange:r=>h(r.target.value),className:u})}),e(g,{label:"Country",separate:!0,htmlFor:M,children:e(U,{id:M,value:c,onChange:r=>p(r.target.value),className:u+" pr-10",style:q,children:i.map(r=>e("option",{value:r.code,children:r.name},r.code))})})]}),e(g,{label:y,separate:!0,htmlFor:j,children:E.length>0?a(U,{id:j,value:k,onChange:r=>m(r.target.value),className:u+" pr-10",style:q,children:[e("option",{value:"",children:"Select…"}),E.map(r=>e("option",{value:r.code||r.name,children:r.name},r.code||r.name))]}):e("input",{id:j,type:"text",value:k,onChange:r=>m(r.target.value),className:u})})]}),e(g,{label:"Phone",children:e("input",{type:"tel",value:x,onChange:r=>o(r.target.value),className:u})}),!t&&B!==null&&P==="new"&&!V&&a(N,{children:[e(xe,{checked:$,onChange:G,label:"Save this address to my account"}),$&&e(g,{label:"Address label",children:e("input",{type:"text",value:W,onChange:r=>K(r.target.value),placeholder:"Home",className:u})})]})]})}function Ye(){const{totals:t,coupon:i,deliveryOptions:n,shippingMethodId:l,setShippingMethodId:s,pickupLocation:d,formatMoney:f,city:v,destination:b,courierUnavailable:h,retryCourier:x}=w();return e(L,{num:"N° 03",title:"Shipping",children:a("div",{className:"grid gap-3",children:[n.map(o=>{const c=o.pickupLocation,p=c?[c.address,c.city,c.state,c.zipCode].filter(Boolean).join(", "):null;return e(I,{active:l===o.id,onClick:()=>s(o.id),title:c?`${o.name} — ${c.name}`:o.name,body:c?[p,c.openingHours,c.readyIn,c.instructions,o.description].filter(Boolean).join(" · "):o.description||null,price:t.freeShipping||o.amount===0?A:f(o.amount,t.currency),tag:o.tag||void 0},o.id)}),h?a("p",{className:"font-mono text-[11px] uppercase tracking-[0.2em] text-fg-dim",children:[ue," ",e("button",{type:"button",onClick:x,className:"underline transition-colors enabled:hover:text-accent",children:"Try again"})]}):n.length===0&&e("p",{className:"font-mono text-[11px] uppercase tracking-[0.2em] text-fg-dim",children:"Shipping is arranged after your order is reviewed."})]})})}function qe(){const{payChoice:t,setPayChoice:i,payment:n,payOptions:l,noPaymentMethod:s}=w();return a(L,{num:"N° 04",title:"Payment",children:[s&&e("p",{className:"font-mono text-[11px] uppercase tracking-[0.2em] text-fg-dim",children:pe}),e("div",{className:"grid gap-3",children:l.map(d=>e(I,{active:t===d.key,onClick:()=>i(d.key),title:d.title,body:d.body,price:d.price,tag:d.tag},d.key))}),t==="card"?e("p",{className:"font-mono text-[11px] uppercase tracking-[0.2em] text-fg-dim",children:"You’ll enter card details on the secure payment step after placing the order."}):t==="paypal"?e("p",{className:"font-mono text-[11px] uppercase tracking-[0.2em] text-fg-dim",children:"You’ll approve the payment with PayPal on the payment step after placing the order."}):t==="afterpay"?e("p",{className:"font-mono text-[11px] uppercase tracking-[0.2em] text-fg-dim",children:"You’ll be taken to Afterpay to approve four interest-free payments, then brought straight back."}):t==="square"?e("p",{className:"font-mono text-[11px] uppercase tracking-[0.2em] text-fg-dim",children:"You’ll enter card details on the secure payment step after placing the order."}):t==="gocardless"?e("p",{className:"font-mono text-[11px] uppercase tracking-[0.2em] text-fg-dim",children:"You’ll set up a bank direct debit with GoCardless, then be brought straight back. Direct debits clear in a few days."}):t==="zip"?e("p",{className:"font-mono text-[11px] uppercase tracking-[0.2em] text-fg-dim",children:"You’ll be taken to Zip to approve four instalments, then brought straight back."}):t==="klarna"?e("p",{className:"font-mono text-[11px] uppercase tracking-[0.2em] text-fg-dim",children:"You’ll be taken to Klarna to choose how to pay, then brought straight back."}):t==="bank"?e("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 He(){const{site:t,items:i,totals:n,coupon:l,formatMoney:s,payChoice:d,placing:f,email:v,orderError:b,payment:h,noPaymentMethod:x,unpaidOrder:o,formLocked:c,restoredPrices:p,quoteFailed:k,retryQuote:m,placeOrder:E}=w(),F=p==="waiting",S=p==="changed";return a("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:[a("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:[e("span",{children:"Your order"}),e(Y,{href:"/wheels",className:"text-bg/80 transition-colors hover:text-bg",children:"Edit ↗"})]}),e("div",{className:"flex flex-col px-6 py-2",children:i.length===0?a("div",{className:"py-8 text-center font-serif text-[16px] italic leading-[1.5] text-fg-dim",children:["Your cart is empty. ",e(Y,{href:"/wheels",className:"text-accent underline-offset-4 hover:underline",children:"Browse the catalog →"})]}):i.map(y=>e(be,{slug:y.slug,name:y.name,qty:y.qty,config:y.config,configSummary:ye(y.config),price:S||F?null:J(y,n.currency)??0,currency:n.currency},y.id))}),e(ge,{locked:c,className:"border-t border-line px-6 pt-5",children:e(ne,{customerEmail:v,disabled:c})}),a("div",{className:"flex flex-col gap-2 border-t border-line mt-5 px-6 pt-5",children:[e(C,{label:"Subtotal",value:F?T:s(S?n.serverSubtotal??0:n.subtotal,n.currency)}),n.discount>0&&l?.valid&&e(C,{label:`Coupon · ${l.code}`,value:a("span",{className:"font-semibold text-green",children:["− ",s(n.discount,n.currency)]})}),l?.deferred&&e(C,{label:`Coupon · ${l.code}`,value:ae}),l?.valid&&l.effects?.gift&&e(C,{label:`Free gift · ${l.effects.gift.partNumber}${l.effects.gift.quantity>1?` ×${l.effects.gift.quantity}`:""}`,value:e("span",{className:"font-semibold text-green",children:A})}),e(C,{label:"Shipping",value:n.shippingStatus==="free"?e("span",{className:"font-semibold text-green",children:A}):oe(n.shippingStatus)??s(n.shipping,n.currency)}),n.tax&&(n.tax.charged?e(C,{label:n.tax.inclusive?`${n.tax.name} included · ${n.tax.rate}%`:n.tax.name,value:s(n.tax.amount,n.currency)}):n.tax.name?e(C,{label:n.tax.name,value:ce}):null)]}),a("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:[e("span",{className:"font-display text-[20px] font-bold uppercase tracking-[0.04em] text-fg",children:"Total"}),e("span",{className:"text-right font-display text-[34px] font-bold leading-none tracking-[-0.025em] text-fg",children:n.repricing?T:s(n.grand,n.currency)})]}),a("div",{className:"flex flex-col gap-3 px-6 pt-5 pb-6",children:[S&&e(_,{tone:"quiet",children:ie}),k&&a(_,{role:"alert",children:[le," ",e("button",{type:"button",onClick:m,className:"underline transition-colors enabled:hover:text-accent",children:"Try again"})]}),b&&e(_,{role:"alert",children:b}),n.hasUnpricedLine&&a(_,{role:"status",children:["One or more items have no price in ",n.currency,". Remove them, or switch region, to continue."]}),e("button",{type:"button",onClick:E,disabled:f||!o&&(x||i.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 max-[640px]:whitespace-nowrap max-[640px]:tracking-[0.04em]",f||!o&&(i.length===0||x||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:f?a(N,{children:["Building order… ",e("span",{children:"·"})]}):x?a(N,{children:["No online payment ",e("span",{children:"·"})]}):o?a(N,{children:[a("span",{children:["Try payment again",a(z,{children:[" · ",re(o)]})]}),e("span",{className:"transition-transform group-hover:translate-x-1",children:"→"})]}):k?a(N,{children:["Total not confirmed ",e("span",{children:"·"})]}):n.repricing?a(N,{children:[T," ",e("span",{children:"·"})]}):a(N,{children:[a("span",{children:[d==="bank"?"Place order":"Continue to payment",a(z,{children:[" · ",s(n.grand,n.currency)]})]}),e("span",{className:"transition-transform group-hover:translate-x-1",children:"→"})]})})]})]})}const he=" [&:disabled_:disabled]:cursor-not-allowed! [&:disabled_:disabled]:opacity-70! [&_input[readonly]]:cursor-not-allowed [&_input[readonly]]:opacity-70";function ge({locked:t,className:i="",children:n}){return e("fieldset",{disabled:t,className:"m-0 min-w-0 border-0 p-0 "+i+he,children:n})}function Y({href:t,className:i="",children:n,...l}){const{placing:s}=w();return s?e("span",{"aria-disabled":"true","aria-label":l["aria-label"],className:i+" pointer-events-none",children:n}):e(Z,{href:t,"aria-label":l["aria-label"],className:i,children:n})}function fe({orderNumber:t}){return e(_,{tone:"quiet",role:"status",children:a("span",{className:"flex items-start gap-2",children:[a("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:[e("rect",{x:"3",y:"7",width:"10",height:"7",rx:"1"}),e("path",{d:"M5 7V5a3 3 0 0 1 6 0v2"})]}),e("span",{children:me(t)})]})})}const q={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 L({num:t,title:i,children:n}){return a("section",{className:"mb-6 border border-line bg-bg",children:[a("header",{className:"flex items-center gap-4 border-b border-line bg-surface px-6 py-4",children:[e("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:t}),e("h2",{className:"font-display text-[26px] font-medium uppercase leading-none tracking-[-0.02em] text-fg",children:i})]}),e("div",{className:"flex flex-col gap-4 px-6 py-6",children:n})]})}function H({cols:t="two",children:i}){return e("div",{className:["grid gap-3 max-[640px]:grid-cols-1",t==="two"?"grid-cols-2":"grid-cols-[1.2fr_1fr_1fr]"].join(" "),children:i})}function I({active:t,onClick:i,title:n,body:l,price:s,tag:d}){return a("button",{type:"button",onClick:i,"aria-pressed":t,className:["relative grid grid-cols-[auto_1fr_auto] items-center gap-5 border bg-bg px-6 py-5 text-left transition-colors",t?"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:t?{background:"color-mix(in oklab, var(--accent) 14%, var(--bg))"}:void 0,children:[t&&e("span",{"aria-hidden":!0,className:"absolute inset-y-0 left-0 w-[3px] bg-accent"}),e("span",{className:["flex h-[18px] w-[18px] items-center justify-center rounded-full border-2",t?"border-accent":"border-fg-dim"].join(" "),children:t&&e("span",{className:"block h-2.5 w-2.5 rounded-full bg-accent"})}),a("span",{className:"flex min-w-0 flex-col gap-1",children:[a("span",{className:"flex flex-wrap items-baseline gap-3 font-display text-[18px] font-medium tracking-[-0.01em] text-fg",children:[n,d&&e("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:d})]}),l&&e("span",{className:"font-mono text-[12px] uppercase tracking-[0.22em] text-fg-dim",children:l})]}),e("span",{className:"whitespace-nowrap font-display text-[18px] font-medium tracking-[-0.01em] text-fg",children:s})]})}function xe({checked:t,onChange:i,label:n,sub:l}){return a("div",{className:"flex items-start gap-3 border-t border-line py-4 first:border-t-0 first:pt-0",children:[e("button",{type:"button",onClick:()=>i(!t),"aria-pressed":t,"aria-label":n,className:["mt-px flex h-5 w-5 flex-shrink-0 items-center justify-center border transition-colors",t?"border-accent":"border-line"].join(" "),style:t?{background:"color-mix(in oklab, var(--accent) 18%, transparent)"}:void 0,children:t&&e("span",{className:"text-[13px] text-accent",children:"✓"})}),a("span",{className:"flex-1 font-display text-[16px] leading-[1.5] text-fg",children:[n,l&&e("small",{className:"mt-1 block font-mono text-[12px] uppercase tracking-[0.18em] text-fg-dim",children:l})]})]})}function be({slug:t,name:i,qty:n,config:l,configSummary:s,price:d,currency:f}){const{catalog:v}=ee(),{formatMoney:b}=te(),h=v.find(m=>m.slug===t),x=h?.spokes??5,o=h?.mesh??!1,c=l.find(m=>m.gold)?.label,p=h?.finishes.find(m=>m.name===c&&m.src)??h?.finishes.find(m=>m.src),k=h?.finishes[0]?.color??se;return a("div",{className:"grid grid-cols-[60px_1fr_auto] items-center gap-4 border-b border-line py-4 last:border-b-0",children:[a("div",{className:"relative aspect-square",children:[e("div",{className:"flex h-full w-full items-center justify-center overflow-hidden border border-line bg-surface",children:p?.src?e(X,{src:p.src,alt:`${i.lead}${i.accent} — ${p.name}`,width:120,height:120,sizes:"60px",className:"block h-full w-full object-contain p-2"}):e("div",{className:"block w-[78%]",style:{color:k},children:e(de,{spokes:x,mesh:o,className:"block w-full"})})}),e("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})]}),a("div",{className:"flex min-w-0 flex-col gap-0.5",children:[a("span",{className:"font-display text-[17px] font-bold uppercase leading-none tracking-[-0.005em] text-fg",children:[i.lead,e("em",{className:"font-serif font-normal italic text-accent tracking-[-0.005em] normal-case",children:i.accent})]}),e("span",{className:"font-mono text-[12px] uppercase leading-[1.5] tracking-[0.18em] text-fg-dim",children:s})]}),e("span",{className:"text-right font-display text-[17px] font-bold tracking-[-0.005em] text-fg",children:d===null?null:b(d,f)})]})}function z({children:t}){return e("span",{className:"max-[640px]:sr-only",children:t})}function C({label:t,value:i}){return a("div",{className:"flex items-center justify-between font-mono text-[13px] font-medium uppercase tracking-[0.18em] text-fg",children:[e("span",{children:t}),e("strong",{className:"font-display text-[16px] font-medium tracking-[-0.005em] normal-case text-fg",children:i})]})}function ye(t){return t.map(i=>i.label).join(" · ")}export{Me as CheckoutContact,He as CheckoutOrderSummary,qe as CheckoutPayment,Ue as CheckoutShippingAddress,Ye as CheckoutShippingMethod,ge as FormLock,Y as LeaveLink};
1
+ "use client";import{jsx as e,Fragment as N,jsxs as a}from"react/jsx-runtime";import{useId as O}from"react";import X from"next/image";import Z from"next/link";import{lineTotal as J,useCart as ee}from"../CartContext.js";import{useCurrency as te}from"../CurrencyContext.js";import{Notice as _}from"../Notice.js";import{FREE_PRICE as A}from"../../lib/wheels/price-display.js";import ne from"../CouponField.js";import{COUPON_DEFERRED_TOTAL as ae}from"../../lib/cart/coupon-preview.js";import{orderReference as re}from"../../lib/checkout/pay-first.js";import{PRICES_REQUOTED as ie,PRICES_UNCHECKED as le}from"../../lib/checkout/checkout-memory.js";import{shippingWords as oe,TAX_PENDING as ce}from"../../lib/cart/shipping-status.js";import{DEFAULT_FINISH_COLOR as se}from"../../lib/wheels/finish-defaults.js";import U from"../ThemedSelect.js";import f from"../WebFormField.js";import de from"../WheelSvg.js";import{NO_PAYMENT_METHOD_NOTE as pe,placedOrderLockNote as me,SHIPPING_RETRY_NOTE as ue,useCheckout as w}from"./checkout-state.js";import{FIELD_INPUT_CLASS as g}from"../../lib/field-input.js";import{FIGURE_UPDATING as T}from"../../lib/wheels/price-display.js";function He(){const{email:t,setEmail:i,firstName:n,setFirstName:l,lastName:s,setLastName:d,company:x,setCompany:k,me:y,signInHref:m,checkoutSignOut:b,orderLocked:o,unpaidOrder:c}=w(),u=O();return a(L,{num:"N° 01",title:"Contact",children:[o&&c&&e(fe,{orderNumber:c.orderNumber}),e(f,{label:"Email",htmlFor:u,hint:y?a(N,{children:["Signed in ·"," ",e("button",{type:"button",onClick:b,className:"underline transition-colors enabled:hover:text-accent",children:"Not you? Sign out"})]}):m?a(N,{children:["Have an account?"," ",e(B,{href:m,className:"underline transition-colors hover:text-accent",children:"Sign in"})]}):void 0,children:e("input",{id:u,type:"email",value:t,onChange:p=>i(p.target.value),placeholder:"you@example.com",readOnly:y!==null,className:g})}),a(q,{children:[e(f,{label:"First name",children:e("input",{type:"text",value:n,onChange:p=>l(p.target.value),className:g})}),e(f,{label:"Last name",children:e("input",{type:"text",value:s,onChange:p=>d(p.target.value),className:g})})]}),e(f,{label:"Company (optional)",children:e("input",{type:"text",value:x,onChange:p=>k(p.target.value),autoComplete:"organization",className:g})})]})}function Me(){const{pickupLocation:t,servedCountries:i,address1:n,setAddress1:l,address2:s,setAddress2:d,city:x,setCity:k,postcode:y,setPostcode:m,phone:b,setPhone:o,country:c,setCountry:u,subdivision:p,setSubdivision:h,subdivisions:E,destination:F,postcodeLabel:S,subdivisionLabel:v,me:R,savedAddresses:D,selectedAddressId:P,setSelectedAddressId:$,saveAddress:H,setSaveAddress:G,saveLabel:W,setSaveLabel:K,fillFromAddress:Q,orderLocked:V}=w(),M=O(),j=O();return a(L,{num:"N° 02",title:t?"Collection":"Shipping address",children:[t?a("div",{className:"grid gap-2 text-[14px] leading-[1.6]",children:[e("span",{className:"font-medium",children:t.name}),[t.address,t.city,t.state,t.zipCode,t.country].filter(Boolean).length>0&&e("span",{className:"opacity-80",children:[t.address,t.city,t.state,t.zipCode,t.country].filter(Boolean).join(", ")}),t.openingHours&&e("span",{className:"opacity-80",children:t.openingHours}),t.readyIn&&e("span",{className:"opacity-80",children:t.readyIn}),t.instructions&&e("span",{className:"opacity-80",children:t.instructions}),e("span",{className:"mt-1 font-mono text-[11px] uppercase tracking-[0.2em] text-fg-dim",children:"No delivery address needed"})]}):a(N,{children:[R!==null&&D.length>0&&a("div",{className:"grid gap-3",children:[D.map(r=>e(I,{active:P===r.id,onClick:()=>{$(r.id),Q(r)},title:r.label,body:r.formatted_address,price:null},r.id)),e(I,{active:P==="new",onClick:()=>$("new"),title:"New address",body:null,price:null})]}),e(f,{label:"Address line 1",children:e("input",{type:"text",value:n,onChange:r=>l(r.target.value),className:g})}),e(f,{label:"Address line 2",children:e("input",{type:"text",value:s,onChange:r=>d(r.target.value),placeholder:"Apartment, unit, garage bay…",className:g})}),a(q,{cols:"three",children:[e(f,{label:"City",children:e("input",{type:"text",value:x,onChange:r=>k(r.target.value),className:g})}),e(f,{label:S,children:e("input",{type:"text",value:y,onChange:r=>m(r.target.value),className:g})}),e(f,{label:"Country",separate:!0,htmlFor:M,children:e(U,{id:M,value:c,onChange:r=>u(r.target.value),className:g+" pr-10",style:Y,children:i.map(r=>e("option",{value:r.code,children:r.name},r.code))})})]}),e(f,{label:v,separate:!0,htmlFor:j,children:E.length>0?a(U,{id:j,value:p,onChange:r=>h(r.target.value),className:g+" pr-10",style:Y,children:[e("option",{value:"",children:"Select…"}),E.map(r=>e("option",{value:r.code||r.name,children:r.name},r.code||r.name))]}):e("input",{id:j,type:"text",value:p,onChange:r=>h(r.target.value),className:g})})]}),e(f,{label:"Phone",children:e("input",{type:"tel",value:b,onChange:r=>o(r.target.value),className:g})}),!t&&R!==null&&P==="new"&&!V&&a(N,{children:[e(xe,{checked:H,onChange:G,label:"Save this address to my account"}),H&&e(f,{label:"Address label",children:e("input",{type:"text",value:W,onChange:r=>K(r.target.value),placeholder:"Home",className:g})})]})]})}function Ue(){const{totals:t,coupon:i,deliveryOptions:n,shippingMethodId:l,setShippingMethodId:s,pickupLocation:d,formatMoney:x,city:k,destination:y,courierUnavailable:m,retryCourier:b}=w();return e(L,{num:"N° 03",title:"Shipping",children:a("div",{className:"grid gap-3",children:[n.map(o=>{const c=o.pickupLocation,u=c?[c.address,c.city,c.state,c.zipCode].filter(Boolean).join(", "):null;return e(I,{active:l===o.id,onClick:()=>s(o.id),title:c?`${o.name} — ${c.name}`:o.name,body:c?[u,c.openingHours,c.readyIn,c.instructions,o.description].filter(Boolean).join(" · "):o.description||null,price:t.freeShipping||o.amount===0?A:x(o.amount,t.currency),tag:o.tag||void 0},o.id)}),m?a("p",{className:"font-mono text-[11px] uppercase tracking-[0.2em] text-fg-dim",children:[ue," ",e("button",{type:"button",onClick:b,className:"underline transition-colors enabled:hover:text-accent",children:"Try again"})]}):n.length===0&&e("p",{className:"font-mono text-[11px] uppercase tracking-[0.2em] text-fg-dim",children:"Shipping is arranged after your order is reviewed."})]})})}function Ye(){const{payChoice:t,setPayChoice:i,payment:n,payOptions:l,noPaymentMethod:s}=w();return a(L,{num:"N° 04",title:"Payment",children:[s&&e("p",{className:"font-mono text-[11px] uppercase tracking-[0.2em] text-fg-dim",children:pe}),e("div",{className:"grid gap-3",children:l.map(d=>e(I,{active:t===d.key,onClick:()=>i(d.key),title:d.title,body:d.body,price:d.price,tag:d.tag},d.key))}),t==="card"?e("p",{className:"font-mono text-[11px] uppercase tracking-[0.2em] text-fg-dim",children:"You’ll enter card details on the secure payment step after placing the order."}):t==="paypal"?e("p",{className:"font-mono text-[11px] uppercase tracking-[0.2em] text-fg-dim",children:"You’ll approve the payment with PayPal on the payment step after placing the order."}):t==="afterpay"?e("p",{className:"font-mono text-[11px] uppercase tracking-[0.2em] text-fg-dim",children:"You’ll be taken to Afterpay to approve four interest-free payments, then brought straight back."}):t==="square"?e("p",{className:"font-mono text-[11px] uppercase tracking-[0.2em] text-fg-dim",children:"You’ll enter card details on the secure payment step after placing the order."}):t==="gocardless"?e("p",{className:"font-mono text-[11px] uppercase tracking-[0.2em] text-fg-dim",children:"You’ll set up a bank direct debit with GoCardless, then be brought straight back. Direct debits clear in a few days."}):t==="zip"?e("p",{className:"font-mono text-[11px] uppercase tracking-[0.2em] text-fg-dim",children:"You’ll be taken to Zip to approve four instalments, then brought straight back."}):t==="klarna"?e("p",{className:"font-mono text-[11px] uppercase tracking-[0.2em] text-fg-dim",children:"You’ll be taken to Klarna to choose how to pay, then brought straight back."}):t==="bank"?e("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 qe(){const{site:t,items:i,totals:n,coupon:l,formatMoney:s,payChoice:d,placing:x,email:k,orderError:y,payment:m,noPaymentMethod:b,unpaidOrder:o,formLocked:c,restoredPrices:u,quoteFailed:p,retryQuote:h,placeOrder:E}=w(),F=u==="waiting",S=u==="changed";return a("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:[a("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:[e("span",{children:"Your order"}),e(B,{href:"/wheels",className:"text-bg/80 transition-colors hover:text-bg",children:"Edit ↗"})]}),e("div",{className:"flex flex-col px-6 py-2",children:i.length===0?a("div",{className:"py-8 text-center font-serif text-[16px] italic leading-[1.5] text-fg-dim",children:["Your cart is empty. ",e(B,{href:"/wheels",className:"text-accent underline-offset-4 hover:underline",children:"Browse the catalog →"})]}):i.map(v=>e(be,{slug:v.slug,name:v.name,qty:v.qty,config:v.config,configSummary:ye(v.config),price:S||F?null:J(v,n.currency)??0,currency:n.currency},v.id))}),e(ge,{locked:c,className:"border-t border-line px-6 pt-5",children:e(ne,{customerEmail:k,disabled:c})}),a("div",{className:"flex flex-col gap-2 border-t border-line mt-5 px-6 pt-5",children:[e(C,{label:"Subtotal",value:F?T:s(S?n.serverSubtotal??0:n.subtotal,n.currency)}),n.discount>0&&l?.valid&&e(C,{label:`Coupon · ${l.code}`,value:a("span",{className:"font-semibold text-green",children:["− ",s(n.discount,n.currency)]})}),l?.deferred&&e(C,{label:`Coupon · ${l.code}`,value:ae}),l?.valid&&l.effects?.gift&&e(C,{label:`Free gift · ${l.effects.gift.partNumber}${l.effects.gift.quantity>1?` ×${l.effects.gift.quantity}`:""}`,value:e("span",{className:"font-semibold text-green",children:A})}),e(C,{label:"Shipping",value:n.shippingStatus==="free"?e("span",{className:"font-semibold text-green",children:A}):oe(n.shippingStatus)??s(n.shipping,n.currency)}),n.tax&&(n.tax.charged?e(C,{label:n.tax.inclusive?`${n.tax.name} included · ${n.tax.rate}%`:n.tax.name,value:s(n.tax.amount,n.currency)}):n.tax.name?e(C,{label:n.tax.name,value:ce}):null)]}),a("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:[e("span",{className:"font-display text-[20px] font-bold uppercase tracking-[0.04em] text-fg",children:"Total"}),e("span",{className:"text-right font-display text-[34px] font-bold leading-none tracking-[-0.025em] text-fg",children:n.repricing?T:s(n.grand,n.currency)})]}),a("div",{className:"flex flex-col gap-3 px-6 pt-5 pb-6",children:[S&&e(_,{tone:"quiet",children:ie}),p&&a(_,{role:"alert",children:[le," ",e("button",{type:"button",onClick:h,className:"underline transition-colors enabled:hover:text-accent",children:"Try again"})]}),y&&e(_,{role:"alert",children:y}),n.hasUnpricedLine&&a(_,{role:"status",children:["One or more items have no price in ",n.currency,". Remove them, or switch region, to continue."]}),e("button",{type:"button",onClick:E,disabled:x||!o&&(b||i.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 max-[640px]:whitespace-nowrap max-[640px]:tracking-[0.04em]",x||!o&&(i.length===0||b||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:x?a(N,{children:["Building order… ",e("span",{children:"·"})]}):b?a(N,{children:["No online payment ",e("span",{children:"·"})]}):o?a(N,{children:[a("span",{children:["Try payment again",a(z,{children:[" · ",re(o)]})]}),e("span",{className:"transition-transform group-hover:translate-x-1",children:"→"})]}):p?a(N,{children:["Total not confirmed ",e("span",{children:"·"})]}):n.repricing?a(N,{children:[T," ",e("span",{children:"·"})]}):a(N,{children:[a("span",{children:[d==="bank"?"Place order":"Continue to payment",a(z,{children:[" · ",s(n.grand,n.currency)]})]}),e("span",{className:"transition-transform group-hover:translate-x-1",children:"→"})]})})]})]})}const he=" [&:disabled_:disabled]:cursor-not-allowed! [&:disabled_:disabled]:opacity-70! [&_input[readonly]]:cursor-not-allowed [&_input[readonly]]:opacity-70";function ge({locked:t,className:i="",children:n}){return e("fieldset",{disabled:t,className:"m-0 min-w-0 border-0 p-0 "+i+he,children:n})}function B({href:t,className:i="",children:n,...l}){const{placing:s}=w();return s?e("span",{"aria-disabled":"true","aria-label":l["aria-label"],className:i+" pointer-events-none",children:n}):e(Z,{href:t,"aria-label":l["aria-label"],className:i,children:n})}function fe({orderNumber:t}){return e(_,{tone:"quiet",role:"status",children:a("span",{className:"flex items-start gap-2",children:[a("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:[e("rect",{x:"3",y:"7",width:"10",height:"7",rx:"1"}),e("path",{d:"M5 7V5a3 3 0 0 1 6 0v2"})]}),e("span",{children:me(t)})]})})}const Y={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 L({num:t,title:i,children:n}){return a("section",{className:"mb-6 border border-line bg-bg",children:[a("header",{className:"flex items-center gap-4 border-b border-line bg-surface px-6 py-4",children:[e("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:t}),e("h2",{className:"font-display text-[26px] font-medium uppercase leading-none tracking-[-0.02em] text-fg",children:i})]}),e("div",{className:"flex flex-col gap-4 px-6 py-6",children:n})]})}function q({cols:t="two",children:i}){return e("div",{className:["grid gap-3 max-[640px]:grid-cols-1",t==="two"?"grid-cols-2":"grid-cols-[1.2fr_1fr_1fr]"].join(" "),children:i})}function I({active:t,onClick:i,title:n,body:l,price:s,tag:d}){return a("button",{type:"button",onClick:i,"aria-pressed":t,className:["relative grid grid-cols-[auto_1fr_auto] items-center gap-5 border bg-bg px-6 py-5 text-left transition-colors",t?"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:t?{background:"color-mix(in oklab, var(--accent) 14%, var(--bg))"}:void 0,children:[t&&e("span",{"aria-hidden":!0,className:"absolute inset-y-0 left-0 w-[3px] bg-accent"}),e("span",{className:["flex h-[18px] w-[18px] items-center justify-center rounded-full border-2",t?"border-accent":"border-fg-dim"].join(" "),children:t&&e("span",{className:"block h-2.5 w-2.5 rounded-full bg-accent"})}),a("span",{className:"flex min-w-0 flex-col gap-1",children:[a("span",{className:"flex flex-wrap items-baseline gap-3 font-display text-[18px] font-medium tracking-[-0.01em] text-fg",children:[n,d&&e("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:d})]}),l&&e("span",{className:"font-mono text-[12px] uppercase tracking-[0.22em] text-fg-dim",children:l})]}),e("span",{className:"whitespace-nowrap font-display text-[18px] font-medium tracking-[-0.01em] text-fg",children:s})]})}function xe({checked:t,onChange:i,label:n,sub:l}){return a("div",{className:"flex items-start gap-3 border-t border-line py-4 first:border-t-0 first:pt-0",children:[e("button",{type:"button",onClick:()=>i(!t),"aria-pressed":t,"aria-label":n,className:["mt-px flex h-5 w-5 flex-shrink-0 items-center justify-center border transition-colors",t?"border-accent":"border-line"].join(" "),style:t?{background:"color-mix(in oklab, var(--accent) 18%, transparent)"}:void 0,children:t&&e("span",{className:"text-[13px] text-accent",children:"✓"})}),a("span",{className:"flex-1 font-display text-[16px] leading-[1.5] text-fg",children:[n,l&&e("small",{className:"mt-1 block font-mono text-[12px] uppercase tracking-[0.18em] text-fg-dim",children:l})]})]})}function be({slug:t,name:i,qty:n,config:l,configSummary:s,price:d,currency:x}){const{catalog:k}=ee(),{formatMoney:y}=te(),m=k.find(h=>h.slug===t),b=m?.spokes??5,o=m?.mesh??!1,c=l.find(h=>h.gold)?.label,u=m?.finishes.find(h=>h.name===c&&h.src)??m?.finishes.find(h=>h.src),p=m?.finishes[0]?.color??se;return a("div",{className:"grid grid-cols-[60px_1fr_auto] items-center gap-4 border-b border-line py-4 last:border-b-0",children:[a("div",{className:"relative aspect-square",children:[e("div",{className:"flex h-full w-full items-center justify-center overflow-hidden border border-line bg-surface",children:u?.src?e(X,{src:u.src,alt:`${i.lead}${i.accent} — ${u.name}`,width:120,height:120,sizes:"60px",className:"block h-full w-full object-contain p-2"}):e("div",{className:"block w-[78%]",style:{color:p},children:e(de,{spokes:b,mesh:o,className:"block w-full"})})}),e("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})]}),a("div",{className:"flex min-w-0 flex-col gap-0.5",children:[a("span",{className:"font-display text-[17px] font-bold uppercase leading-none tracking-[-0.005em] text-fg",children:[i.lead,e("em",{className:"font-serif font-normal italic text-accent tracking-[-0.005em] normal-case",children:i.accent})]}),e("span",{className:"font-mono text-[12px] uppercase leading-[1.5] tracking-[0.18em] text-fg-dim",children:s})]}),e("span",{className:"text-right font-display text-[17px] font-bold tracking-[-0.005em] text-fg",children:d===null?null:y(d,x)})]})}function z({children:t}){return e("span",{className:"max-[640px]:sr-only",children:t})}function C({label:t,value:i}){return a("div",{className:"flex items-center justify-between font-mono text-[13px] font-medium uppercase tracking-[0.18em] text-fg",children:[e("span",{children:t}),e("strong",{className:"font-display text-[16px] font-medium tracking-[-0.005em] normal-case text-fg",children:i})]})}function ye(t){return t.map(i=>i.label).join(" · ")}export{He as CheckoutContact,qe as CheckoutOrderSummary,Ye as CheckoutPayment,Me as CheckoutShippingAddress,Ue as CheckoutShippingMethod,ge as FormLock,B as LeaveLink};
@@ -35,8 +35,9 @@ export interface CheckoutProps {
35
35
  sizeUnit?: LengthUnit | null;
36
36
  } | null;
37
37
  preview?: boolean;
38
+ signInHref?: string | null;
38
39
  }
39
- declare function useCheckoutState({ site, logo, preview }: CheckoutProps): {
40
+ declare function useCheckoutState({ site, logo, signInHref, preview }: CheckoutProps): {
40
41
  site: SiteIdentity;
41
42
  logo: {
42
43
  url: string | null;
@@ -47,6 +48,7 @@ declare function useCheckoutState({ site, logo, preview }: CheckoutProps): {
47
48
  sizePx: number | null;
48
49
  sizeUnit?: LengthUnit | null;
49
50
  } | null | undefined;
51
+ signInHref: string | null;
50
52
  items: CartLine[];
51
53
  totals: {
52
54
  sets: number;
@@ -1,3 +1,3 @@
1
- "use client";import{jsx as R}from"react/jsx-runtime";import{createContext as mr,useContext as yr,useEffect as h,useMemo as an,useRef as y,useState as s}from"react";import{isOrderable as un,useCart as hr}from"../CartContext.js";import{useCurrency as gr}from"../CurrencyContext.js";import{getClickIds as kr}from"../../lib/click-ids.js";import{adConsentForOrder as Cr}from"../../lib/consent/choice.js";import{trackBeginCheckout as wr,trackPurchase as Pr}from"../../lib/google-tag.js";import{trackMetaPurchase as br}from"../../lib/meta-pixel.js";import{ApiError as qe,api as me,products as w}from"../../lib/api/index.js";import{uuid as $e}from"../../lib/uuid.js";import{orderLinesForSets as Nr}from"../../lib/commerce.js";import{canPersist as Sr,safeSessionStorage as ct}from"efficient-web-builder/format/lib/safe-storage";import{AFTERPAY_CONTEXT_KEY as Ar,AFTERPAY_RETURN as vr,GOCARDLESS_CONTEXT_KEY as Or,GOCARDLESS_RETURN as Er,KLARNA_CONTEXT_KEY as Rr,KLARNA_RETURN as Kr,ZIP_CONTEXT_KEY as Mr,ZIP_RETURN as Lr,runWalletReturn as Be}from"../../lib/checkout/wallet-return.js";import{matchSubdivision as Tr}from"../../lib/checkout/match-subdivision.js";import{clearCheckoutMemory as _r,holdsPress as xr,parkCheckoutMemory as Ir,parkForm as Fr,parkOrder as qr,parkRequest as ln,readCheckoutMemory as $r,sameGoods as Br,sendableRequest as Ur}from"../../lib/checkout/checkout-memory.js";import{checkoutGone as at,checkoutWaiting as dn,BANK_WAITING as Yr,DROPPABLE_INTENT as Hr,NOT_CHECKED as it,LOST_CHANGE as ut,PAY_FIRST_FLOW as lt,paysFirst as Gr,readIntentStatus as Dr,releaseHeldCheckout as pn,CHECKOUT_COMMITTED as zr,goodsShapeOf as Wr,refusedForGood as fn,settlePayFirst as Jr}from"../../lib/checkout/pay-first.js";import{couponCodeForOrder as mn,couponRefusedByOrder as Xr}from"../../lib/cart/coupon-preview.js";function yn(o){const g=o.indexOf(`
2
- `);return g===-1?[o,""]:[o.slice(0,g),o.slice(g+1)]}function hn(o,{canParkContext:g}={canParkContext:!0}){const f=o.paymentMethods,a=[];return f.includes("card")&&a.push({key:"card",title:"Card",body:null,price:R("span",{className:"font-mono text-[12px] uppercase tracking-[0.2em] text-accent",children:"VISA · MC · AMEX"})}),f.includes("paypal")&&o.paypalClientId&&a.push({key:"paypal",title:"PayPal",body:null,price:R("span",{className:"font-mono text-[12px] uppercase tracking-[0.2em] text-accent",children:"PAYPAL · CARDS"})}),f.includes("afterpay")&&a.push({key:"afterpay",title:"Afterpay",body:null,price:R("span",{className:"font-mono text-[12px] uppercase tracking-[0.2em] text-accent",children:"4 × INTEREST-FREE"})}),f.includes("square")&&o.squareApplicationId&&o.squareLocationId&&a.push({key:"square",title:"Card (Square)",body:null,price:R("span",{className:"font-mono text-[12px] uppercase tracking-[0.2em] text-accent",children:"VISA · MC · AMEX"})}),f.includes("gocardless")&&g&&a.push({key:"gocardless",title:"Bank Direct Debit",body:null,price:R("span",{className:"font-mono text-[12px] uppercase tracking-[0.2em] text-accent",children:"PAY BY BANK"})}),f.includes("zip")&&a.push({key:"zip",title:"Zip",body:null,price:R("span",{className:"font-mono text-[12px] uppercase tracking-[0.2em] text-accent",children:"PAY IN 4"})}),f.includes("klarna")&&g&&a.push({key:"klarna",title:"Klarna",body:null,price:R("span",{className:"font-mono text-[12px] uppercase tracking-[0.2em] text-accent",children:"PAY LATER"})}),f.includes("bank")&&a.push({key:"bank",title:"Bank transfer",body:null,price:R("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 Ue extends Error{}function gn(o,g){if(!o.orderNumber&&at(g))return g.message;const f=g instanceof qe?` (${g.message})`:"";return o.orderNumber?`Your order ${o.orderNumber} is saved, but the payment did not start${f}. Try the payment again — your order will not be placed twice.`:`Your items are held under ${o.checkoutNumber}, but the payment did not start${f}. Try the payment again — you will not be charged twice.`}const Zr=3e3,jr=.005,kn=new Set(["paypal","square","afterpay","gocardless","zip","klarna"]);function Cn(){const o=Cr();return{...o==="denied"?{}:kr(),...o?{adConsent:o}:{}}}const v=o=>JSON.parse(o),Qr={lastPress:null,keptCardKey:null,placedShape:null,placedRequest:null,unpaidOrder:null},Vr={lastPress:o=>o&&{key:o.key,request:ln(o.request),lines:o.lines,goods:v(o.shape)[0],plainPressed:!!o.plainMethod,plainLines:o.plainLines,plainGoods:v(o.plainShape)[0]},keptCardKey:o=>o,placedShape:o=>o===null?null:v(o)[0],placedRequest:o=>o&&ln(o.body),unpaidOrder:o=>o&&qr(o)};function wn(o,g){const f={};for(const a of Object.keys(o))f[a]=o[a](g[a]);return f}const Po="Shipping cannot be calculated right now. Please try again.";function bo(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 eo({site:o,logo:g,preview:f=!1}){const{items:a,totals:P,coupon:K,refuseCoupon:bn,deliveryOptions:dt,shippingMethodId:Q,setShippingMethodId:pt,setQuoteDestination:ye,courier:Nn,requote:he,identify:ft,clearCapturedCart:ge,replaceItems:Ye,removeCoupon:mt,applyCoupon:Sn}=hr(),An=dt.find(e=>e.id===Q)?.pickupLocation??null,{country:yt,countries:V,activeCountry:ht,formatMoney:vn}=gr(),[C,ke]=s(()=>hn(o)[0]?.key??null),[gt,On]=s(!0);h(()=>{On(Sr(ct))},[]);const[M,He]=s(!1),[I,Ce]=s(""),[L,we]=s(""),[H,Pe]=s(""),[be,Ge]=s(""),[ee,te]=s(""),[Ne,ne]=s(""),[F,re]=s(""),[T,oe]=s(""),[G,se]=s(""),[m,ce]=s(()=>yt||V[0]?.code||""),[O,Se]=s(""),[ae,kt]=s([]),[De,ze]=s(null),[Ae,D]=s(null),Ct=an(()=>V.find(e=>e.code===m)??ht,[V,m,ht]),En=Ct?.postalLabel||"Postal Code",Rn=ae[0]?.divisionType||"State / Province";h(()=>{if(!m){kt([]),ze(m);return}ze(null);let e=!1;return w.listCountrySubdivisions(m).then(t=>{e||(kt(t),ze(m),Se(""))}),()=>{e=!0}},[m]);const wt=ee.trim()!==""&&F.trim()!==""&&T.trim()!==""&&De===m&&(ae.length===0||O!=="")?T.trim():"";h(()=>{ye(m?{country:m,subdivision:O,postcode:wt}:null)},[m,O,wt,ye]),h(()=>()=>ye(null),[ye]);const Kn=Nn?.status==="unavailable",Mn=he,[ie,Pt]=s(null),[Ln,bt]=s([]),[We,ve]=s("new"),[Nt,St]=s(!1),[Je,Tn]=s("Home"),[_n,At]=s(null),[xn,Xe]=s(null),[q,Oe]=s(()=>$e()),vt=y(null),[Ze,z]=s(null),[In,N]=s(null),[Ot,Ee]=s(null),[Et,Fn]=s(!1),[Rt,qn]=s(!1),[_,W]=s(null),[$n,Re]=s(!1),[k,S]=s(null),Kt=!!k?.orderNumber,Bn=Kt||M,[Un,Yn]=s(null),[Hn,Gn]=s(!1),[Dn,zn]=s(!1),[Wn,Jn]=s(!1),[Xn,Zn]=s(!1),[Mt,jn]=s(!1),[Qn,je]=s(!1),[ue,Lt]=s(null),i=y({...Qr});i.current.unpaidOrder=k;const Qe=y(!1),$=y(a),Tt=!!(Ze||ue&&ue.kind!=="processing"||Mt||Et||Rt||Ot&&_?.orderNumber);h(()=>{Tt&&(Ye([]),mt())},[Tt,Ye,mt]);const _t=y(!1);h(()=>{f||_t.current||!a.some(un)||(_t.current=!0,wr({lines:a,currency:P.currency,value:P.subtotal-P.discount,coupon:K?.valid?K.code:void 0}))},[a,P,K,f]),h(()=>{ft(I,L.trim()||void 0)},[I,L,ft]);const xt=y(null),[Ke,Vn]=s(null);h(()=>{const e=xt.current;if(!Ke||!e)return;const t=()=>e.style.setProperty("--sf-checkout-header-h",`${Ke.offsetHeight}px`);t();const r=new ResizeObserver(t);return r.observe(Ke),()=>r.disconnect()},[Ke]),h(()=>{const e=r=>({setConfirming:r,land:z,markPaid:()=>Re(!0),note:(c,n)=>Yn({text:c,warning:n}),fail:N,clearCart:ge,lostChange:()=>Xe(ut)}),t={search:window.location.search,storage:ct,scrubQuery:()=>window.history.replaceState(null,"",window.location.pathname)};Be(vr,{...t,capture:w.captureAfterpayPayment,page:e(Gn)}),Be(Lr,{...t,capture:w.captureZipPayment,page:e(Jn)}),Be(Er,{...t,capture:w.completeGocardlessPayment,page:e(zn)}),Be(Kr,{...t,capture:w.captureKlarnaPayment,page:e(Zn)})},[]);function It(e){const[t,r]=yn(e.address);te(t),ne(r),re(e.city),oe(e.zip_code),e.country&&ce(e.country),e.phone&&se(e.phone),D({country:e.country||null,state:e.state??""})}h(()=>{if(Ae){if((Ae.country||m)!==m){D(null);return}De===m&&(Se(Tr(m,Ae.state,ae)),D(null))}},[Ae,m,De,ae]),h(()=>{let e=!1;return(async()=>{try{const[t,r,c]=await Promise.all([me.me(),me.myProfile().catch(()=>null),me.myAddresses().catch(()=>[])]);if(e)return;Pt(t);const n=c.filter(p=>p.is_active);bt(n),Ce(t.email);const u=(r?.contact_name??"").split(/\s+/);we(t.first_name||u[0]||""),Pe(t.last_name||u.slice(1).join(" "));const d=t.phone||r?.phone;d&&se(d);const l=n.find(p=>p.id===t.default_delivery_location)??n[0];if(l)ve(l.id),It(l);else if(r){const[p,j]=yn(r.address??"");te(p),ne(j),re(r.city??""),oe(r.zip_code??""),r.country&&ce(r.country),D({country:r.country||null,state:r.state??""})}Fe.current&&Ht(Fe.current,!1)}catch{}})(),()=>{e=!0}},[]);function er(){me.logout(),le.current=!0,Fe.current=null,Ie.current=null,de(),Pt(null),bt([]),ve("new"),St(!1),Ce(""),we(""),Pe(""),Ge(""),te(""),ne(""),re(""),oe(""),se(""),ce(yt||V[0]?.code||""),Se(""),D(null)}const J=an(()=>hn(o,{canParkContext:gt}),[o,gt]);h(()=>{J.some(e=>e.key===C)||ke(J[0]?.key??null)},[J,C]);const tr=J.length===0,Me=Ne.trim()?`${ee}
3
- ${Ne.trim()}`:ee,nr=Wr({email:I,firstName:L,lastName:H,company:be.trim(),phone:G,address:Me,city:F,subdivision:O,postcode:T,country:m,lines:a.map(e=>[e.id,e.qty]),shippingMethodId:Q,couponCode:mn(K),currency:P.currency,shopperId:ie?.id??null}),b=JSON.stringify([nr,C]),Ve=y(null),Le=y(!1),x=y(!1),X=y(null),Te=y(!1),A=y(b);A.current=b;const Ft=y(M);Ft.current=M;const _e=y(null);h(()=>{const e=()=>{const t=_e.current;t&&(_e.current=null,S(t),He(!1))};return window.addEventListener("pageshow",e),()=>window.removeEventListener("pageshow",e)},[]);function xe(e,t,r,c){const n={idempotencyKey:t,confirmation:r};Xt()&&(n.lostChange=!0),ct.setItem(e,JSON.stringify(n)),window.location.assign(c),_e.current=r}async function qt(e){He(!0);try{await e()}finally{_e.current||He(!1)}}const $t=y(!1),Bt=!!(Ze||ue&&ue.kind!=="processing");h(()=>{Bt&&($t.current=!0,de())},[Bt]);const Ie=y(null),le=y(!1),et=y(null);function de(){et.current=null,_r()}const Fe=y(null),[Z,rr]=s(!1);function tt(e){if($t.current||f||le.current)return;const t={key:e,authed:Qe.current,parkedAt:et.current??=Date.now(),press:wn(Vr,i.current),lines:a.length>0?a:$.current,form:Fr({email:I,firstName:L,lastName:H,company:be,address1:ee,address2:Ne,city:F,postcode:T,phone:G,country:m,subdivision:O,selectedAddressId:We,shippingMethodId:Q,couponCode:K?.valid?K.code:null})};xr(t.press)?Ir(t):de()}const Ut=y(C);Ut.current=C;function nt(e){return{...Ur(e),...Cn(),...e.payFirst?{checkoutFlow:lt}:{}}}function or(e,t){let r=e.request.payFirst?"":null,c=e.plainPressed?null:"";const n=()=>Ut.current??"";return{key:e.key,send:()=>t(nt(e.request)),request:nt(e.request),lines:e.lines,shape:JSON.stringify([e.goods,null]),get method(){return r??n()},set method(u){r=u},get plainMethod(){return c??n()},set plainMethod(u){c=u},plainLines:e.plainLines,plainShape:JSON.stringify([e.plainGoods,null])}}const[sr,cr]=s(!1),Yt=sr?!P.quoted||P.serverSubtotal===null?"waiting":Math.abs(P.serverSubtotal-P.subtotal)<jr?"same":"changed":null,rt=!k&&Yt==="waiting",ar=rt?{...P,repricing:!0}:P,ot=rt&&P.quoteFailed;h(()=>{if(!ot)return;const e=setInterval(he,Zr);return()=>clearInterval(e)},[ot,he]);const ir=he;function Ht(e,t=!0){Ce(e.email),we(e.firstName),Pe(e.lastName),Ge(e.company),te(e.address1),ne(e.address2),re(e.city),oe(e.postcode),se(e.phone),e.country&&ce(e.country),D({country:e.country||null,state:e.subdivision}),ve(e.selectedAddressId),e.shippingMethodId&&pt(e.shippingMethodId),t&&(Ie.current=e.couponCode)}h(()=>{let e=f?null:$r();const t=!!(e&&a.length>0);if(e&&t&&!Br(e.lines,a)&&(de(),e=null),e){const r=e.authed?w.createOrderAuthed:w.createOrder;Oe(e.key),et.current=e.parkedAt,Qe.current=e.authed;const c={lastPress:n=>n&&or(n,r),keptCardKey:n=>n,placedShape:n=>n===null?null:JSON.stringify([n,null]),placedRequest:n=>{if(!n)return null;const u=nt(n);return{body:u,send:()=>r(u)}},unpaidOrder:n=>n};i.current=wn(c,e.press),e.press.unpaidOrder&&S(e.press.unpaidOrder),e.lines.length>0&&!t&&(Ye(e.lines),$.current=e.lines,cr(!0)),e.form&&(Fe.current=e.form,Ht(e.form))}rr(!0)},[]),h(()=>{!Z||a.length>0||i.current.unpaidOrder||M||(le.current=!0,de())},[Z,a.length]),h(()=>{const e=Ie.current;!Z||!e||a.length===0||(Ie.current=null,Sn(e,I||void 0))},[Z,a.length]),h(()=>{!Z||M||tt(q)},[Z,M,q,k]);const B=y(null);h(()=>{Ft.current||(b!==B.current&&(B.current=null),!(!x.current||!k||k.orderNumber)&&(b===i.current.placedShape||b===B.current||qt(()=>Gt(k))))},[b,k]);async function Gt(e){if(Te.current)return null;Te.current=!0;try{const t=X.current?await Dr(X.current):"none";if(t==="succeeded"||t==="processing")return x.current=!1,S(null),E("card"),t==="succeeded"?await U(void 0,e):en(e),null;if(t===void 0||!Hr.has(t))return B.current=A.current,S(e),N(t==="requires_action"?Yr:it),null;const r=await pn(q);if(r==="committed")return x.current=!1,S(null),E("card"),await U(void 0,e),null;if(r!=="released")return B.current=A.current,S(e),N(it),null;x.current=!1,X.current=null,B.current=null,N(null),S(null);const c=$e();return Oe(c),c}finally{Te.current=!1}}async function ur(){f||M||Te.current||await qt(lr)}async function lr(){if(k){if((x.current?b!==i.current.placedShape:pe())&&!k.orderNumber){const c=await Gt(k);c&&A.current===b&&await Dt(c);return}N(null),Le.current=!1,await st();const t=v(A.current)[1],r=k.orderNumber?t:"card";if(r&&kn.has(r)&&pe()&&v(A.current)[0]!==Ve.current){zt(k);return}E(r),r!==C&&ke(r),await tn(k,r,!k.orderNumber);return}await Dt(q)}async function Dt(e){if(a.length===0||P.repricing||rt||!C||!J.some(d=>d.key===C))return;const t=a.filter(un).flatMap(d=>Nr(d.components,d.qty));if(t.length===0){N("Pick a size on each wheel's product page before checking out.");return}N(null);let r,c=e,n=C,u=!1;try{const d=ie?w.createOrderAuthed:w.createOrder,l={customer:{email:I,name:`${L} ${H}`.trim(),phone:G.trim()||void 0,companyName:be.trim()||void 0,address:Me,city:F,state:O||void 0,zipCode:T,country:m},items:t,currency:P.currency,idempotencyKey:e,shippingMethodId:Q??void 0,couponCode:mn(K),...Cn(),...Gr(C)?{checkoutFlow:lt}:{}};i.current.placedRequest={body:l,send:()=>d(l)},Qe.current=!!ie,le.current=!1,Xe(null),Ve.current=null,Le.current=!1,X.current=null,x.current=!1,B.current=null,i.current.placedShape=b,$.current=a;const p=i.current.lastPress,j=p?.key===l.idempotencyKey&&(p.shape!==b&&(!!l.checkoutFlow||!!p.method||!!p.plainMethod)||!!l.checkoutFlow&&!!p.plainMethod);j&&(i.current.keptCardKey=l.idempotencyKey);const on=jt(l,d),sn=j||!l.checkoutFlow&&i.current.keptCardKey===l.idempotencyKey,cn=!on&&!sn&&!l.checkoutFlow&&!!p&&!p.method;cn&&(p.plainMethod=C,p.plainLines=a,p.plainShape=b,tt(l.idempotencyKey));const Y=await(sn?Jt(l,d):d(l).then(fe=>({answer:fe,request:l})).catch(fe=>(on?Wt(fe,l.idempotencyKey):cn&&fn(fe)&&(p.plainMethod=""),dr(fe,l,d))));if(!Y)return;r=Y.answer,c=Y.request.idempotencyKey,n=Y.method??n,E(n),u=pe()||n!==v(A.current)[1],Y.method&&Y.method!==C&&ke(Y.method),r.orderNumber&&(Qt(r),ge()),await st()}catch(d){const l=Xr(d);l?(bn(l),N(`${l} Your order has not been placed. Place it again to continue without the code.`)):d instanceof Ue?N(it):N(d instanceof qe?d.message:"Could not place the order. Please try again.");return}if(n&&kn.has(n)&&(u||pe())){zt(r);return}await tn(r,n,!1,c)}function zt(e){Ve.current=v(A.current)[0],N(`${gn(e,null)} ${ut}`),S(e)}function Wt(e,t){fn(e)&&!dn(e)&&i.current.lastPress?.key===t&&(i.current.lastPress=null)}async function dr(e,t,r){if(at(e))return Zt(t,r);if(!dn(e))throw e;return i.current.keptCardKey=t.idempotencyKey,Jt(t,r,!0)}async function Jt(e,t,r=!1){const c=await pn(e.idempotencyKey);if(c==="released")return Zt(e,t);if(c!=="committed")throw new Ue;const n=i.current.lastPress?.key===e.idempotencyKey?i.current.lastPress:null;if($.current=n?.lines??a,n?.method&&!r){i.current.keptCardKey=null,i.current.placedRequest={body:n.request,send:n.send};const j=await n.send().catch(()=>{throw new Ue});return i.current.placedShape=n.shape,{answer:j,request:e,method:n.method}}const u={...e,checkoutFlow:lt},d=n&&!n.method?{body:n.request,send:n.send}:{body:u,send:()=>t(u)};i.current.placedRequest=d;const l=d.send,p=await l().catch(()=>null);if(!p&&n?.plainMethod)throw new Ue;return p?.orderNumber&&p.status!==zr?(i.current.keptCardKey=null,n?.plainMethod&&($.current=n.plainLines),n&&(i.current.placedShape=n.plainMethod?n.plainShape:n.shape),{answer:p,request:e,method:n?.plainMethod||void 0}):(n&&(i.current.placedShape=n.shape),E("card"),await Vt("",p?async()=>p:()=>Promise.reject(new Error("The order request did not answer."))),await st(),null)}function pe(){const e=i.current.placedShape;return e!==null&&v(e)[0]!==v(A.current)[0]}function E(e){e!==v(A.current)[1]&&(Le.current=!0),Xe(Xt()?ut:null)}function Xt(){return Le.current||pe()}async function Zt(e,t){const r={...e,idempotencyKey:$e()};i.current.keptCardKey=null,Oe(r.idempotencyKey),i.current.placedRequest={body:r,send:()=>t(r)},jt(r,t);try{return{answer:await t(r),request:r}}catch(c){throw Wt(c,r.idempotencyKey),c}}function jt(e,t){return i.current.lastPress?.key===e.idempotencyKey?!1:(i.current.lastPress={key:e.idempotencyKey,send:()=>t(e),request:e,lines:a,shape:b,method:e.checkoutFlow?"":C??"",plainMethod:"",plainLines:a,plainShape:b},le.current=!1,tt(e.idempotencyKey),!0)}function Qt(e){Pr({confirmation:e,lines:$.current,adsSendTo:o.googleAdsId&&o.googleAdsConversionLabel?`${o.googleAdsId}/${o.googleAdsConversionLabel}`:null}),br({confirmation:e,lines:$.current})}async function U(e,t=_){if(!t)return;const r=e?async()=>e:i.current.placedRequest?.send;if(t.orderNumber||!r){Re(!0),z(t);return}await Vt(t.checkoutNumber,r)}async function Vt(e,t){ge(),await Jr({checkoutNumber:e,resend:t,page:{setConfirming:jn,land:z,markPaid:()=>Re(!0),track:Qt,unplaced:Lt}})}function en(e=_){if(e){if(e.orderNumber){z(e);return}ge(),Lt({kind:"processing",checkoutNumber:e.checkoutNumber})}}async function st(){const e=JSON.stringify([Je.trim(),L,H,G.trim(),Me,F,O,T,m]);if(!(!ie||!Nt||We!=="new"||vt.current===e))try{await me.createAddress({label:Je.trim()||"Home",contact_name:`${L} ${H}`.trim(),phone:G.trim(),address:Me,city:F,zip_code:T,state:O,country:m}),vt.current=e,At("Address saved to your account.")}catch{At("We couldn't save the address to your account — you can add it under Account → Addresses.")}}async function tn(e,t=C,r=!1,c=q){S(null);try{if(t==="card"&&o.paymentMethods.includes("card")){const n=await w.createPaymentIntent({idempotencyKey:c});X.current=n;let u=e;if(r){const d=await i.current.placedRequest?.send().catch(()=>null);if(d?.orderNumber){E("card"),await U(d,e);return}u=nn(e,d)??{...e,expiresAt:null}}E("card"),W(u),je(!1),Ee(n)}else if(t==="paypal"&&o.paymentMethods.includes("paypal"))W(e),Fn(!0);else if(t==="afterpay"&&o.paymentMethods.includes("afterpay")){const n=window.location.origin,u=await w.createAfterpayCheckout({idempotencyKey:c,confirmUrl:`${n}/checkout?afterpay=confirm`,cancelUrl:`${n}/checkout?afterpay=cancel`});xe(Ar,c,e,u.redirectCheckoutUrl);return}else if(t==="square"&&o.paymentMethods.includes("square"))W(e),qn(!0);else if(t==="gocardless"&&o.paymentMethods.includes("gocardless")){const n=window.location.origin,u=await w.createGocardlessBillingRequest({idempotencyKey:c,confirmUrl:`${n}/checkout?gocardless=confirm`,cancelUrl:`${n}/checkout?gocardless=cancel`});xe(Or,c,e,u.authorisationUrl);return}else if(t==="zip"&&o.paymentMethods.includes("zip")){const n=window.location.origin,u=await w.createZipCheckout({idempotencyKey:c,redirectUrl:`${n}/checkout?zip=return`});xe(Mr,c,e,u.redirectUrl);return}else if(t==="klarna"&&o.paymentMethods.includes("klarna")){const n=window.location.origin,u=await w.createKlarnaCheckout({idempotencyKey:c,confirmUrl:`${n}/checkout?klarna=confirm`,cancelUrl:`${n}/checkout?klarna=cancel`});xe(Rr,c,e,u.redirectUrl);return}else E(t),z(e)}catch(n){if((r||t==="card")&&n instanceof qe&&n.status===409){E(t),await U(void 0,e);return}rn(e,n)}}function nn(e,t){return t&&!t.orderNumber&&t.status==="open"&&t.checkoutNumber===e.checkoutNumber?t:null}function rn(e,t){N(gn(e,t)),!e.orderNumber&&at(t)?(x.current=!1,Oe($e())):S(e)}async function pr(e){if(!_)return;const t=_;try{const r=await w.createPaymentIntent({idempotencyKey:q}),c=await i.current.placedRequest?.send().catch(()=>null);if(c?.orderNumber){await U(c);return}const n=nn(t,c);W(n??{...t,expiresAt:null}),je(e&&n!==null),X.current=r,Ee(r)}catch(r){if(r instanceof qe&&r.status===409){await U();return}Ee(null),W(null),rn(t,r)}}function fr(){_&&(x.current=!0,S(_),Ee(null),W(null),je(!1))}return{site:o,logo:g,items:a,totals:ar,coupon:K,deliveryOptions:dt,courierUnavailable:Kn,retryCourier:Mn,shippingMethodId:Q,setShippingMethodId:pt,pickupLocation:An,servedCountries:V,formatMoney:vn,payChoice:C,setPayChoice:ke,placing:M,email:I,setEmail:Ce,firstName:L,setFirstName:we,lastName:H,setLastName:Pe,company:be,setCompany:Ge,address1:ee,setAddress1:te,address2:Ne,setAddress2:ne,city:F,setCity:re,postcode:T,setPostcode:oe,phone:G,setPhone:se,country:m,setCountry:ce,subdivision:O,setSubdivision:Se,subdivisions:ae,destination:Ct,postcodeLabel:En,subdivisionLabel:Rn,me:ie,savedAddresses:Ln,selectedAddressId:We,setSelectedAddressId:ve,saveAddress:Nt,setSaveAddress:St,saveLabel:Je,setSaveLabel:Tn,addressSaveNote:_n,lostChangeNote:xn,idemKey:q,confirmation:Ze,setConfirmation:z,orderError:In,payment:Ot,paypalStep:Et,squareStep:Rt,pendingConf:_,paid:$n,setPaid:Re,unpaidOrder:k,orderLocked:Kt,formLocked:Bn,restoredPrices:Yt,quoteFailed:ot,retryQuote:ir,payNote:Un,afterpayConfirming:Hn,gocardlessConfirming:Dn,zipConfirming:Wn,klarnaConfirming:Xn,cardConfirming:Mt,checkoutResult:ue,confirmCardPayment:U,cardStillProcessing:en,renewCardPayment:pr,holdRenewed:Qn,leaveCardPayment:fr,checkoutRootRef:xt,setCheckoutHeaderEl:Vn,fillFromAddress:It,checkoutSignOut:er,payOptions:J,noPaymentMethod:tr,placeOrder:ur}}const Pn=mr(null);function No({children:o,...g}){const f=eo(g);return R(Pn.Provider,{value:f,children:o})}function So(){const o=yr(Pn);if(!o)throw new Error("useCheckout must be used inside CheckoutStateProvider");return o}export{No as CheckoutStateProvider,wo as NO_PAYMENT_METHOD_NOTE,Po as SHIPPING_RETRY_NOTE,hn as buildPayOptions,gn as paymentNotStartedMessage,bo as placedOrderLockNote,So as useCheckout};
1
+ "use client";import{jsx as K}from"react/jsx-runtime";import{createContext as yr,useContext as hr,useEffect as y,useMemo as un,useRef as m,useState as s}from"react";import{isOrderable as ln,useCart as gr}from"../CartContext.js";import{useCurrency as kr}from"../CurrencyContext.js";import{getClickIds as Cr}from"../../lib/click-ids.js";import{adConsentForOrder as wr}from"../../lib/consent/choice.js";import{trackBeginCheckout as Pr,trackPurchase as br}from"../../lib/google-tag.js";import{trackMetaPurchase as Nr}from"../../lib/meta-pixel.js";import{ApiError as $e,api as ye,products as P}from"../../lib/api/index.js";import{uuid as Be}from"../../lib/uuid.js";import{orderLinesForSets as Sr}from"../../lib/commerce.js";import{canPersist as Ar,safeSessionStorage as at}from"efficient-web-builder/format/lib/safe-storage";import{AFTERPAY_CONTEXT_KEY as vr,AFTERPAY_RETURN as Or,GOCARDLESS_CONTEXT_KEY as Er,GOCARDLESS_RETURN as Rr,KLARNA_CONTEXT_KEY as Kr,KLARNA_RETURN as Mr,ZIP_CONTEXT_KEY as Lr,ZIP_RETURN as Tr,runWalletReturn as Ue}from"../../lib/checkout/wallet-return.js";import{matchSubdivision as _r}from"../../lib/checkout/match-subdivision.js";import{clearCheckoutMemory as xr,holdsPress as Ir,parkCheckoutMemory as Fr,parkForm as qr,parkOrder as $r,parkRequest as dn,readCheckoutMemory as Br,sameGoods as Ur,sendableRequest as Yr}from"../../lib/checkout/checkout-memory.js";import{checkoutGone as it,checkoutWaiting as pn,BANK_WAITING as Hr,DROPPABLE_INTENT as Gr,NOT_CHECKED as ut,LOST_CHANGE as lt,PAY_FIRST_FLOW as dt,paysFirst as Dr,readIntentStatus as zr,releaseHeldCheckout as fn,CHECKOUT_COMMITTED as Wr,goodsShapeOf as Jr,refusedForGood as mn,settlePayFirst as Xr}from"../../lib/checkout/pay-first.js";import{couponCodeForOrder as yn,couponRefusedByOrder as Zr}from"../../lib/cart/coupon-preview.js";function hn(o){const k=o.indexOf(`
2
+ `);return k===-1?[o,""]:[o.slice(0,k),o.slice(k+1)]}function gn(o,{canParkContext:k}={canParkContext:!0}){const g=o.paymentMethods,h=[];return g.includes("card")&&h.push({key:"card",title:"Card",body:null,price:K("span",{className:"font-mono text-[12px] uppercase tracking-[0.2em] text-accent",children:"VISA · MC · AMEX"})}),g.includes("paypal")&&o.paypalClientId&&h.push({key:"paypal",title:"PayPal",body:null,price:K("span",{className:"font-mono text-[12px] uppercase tracking-[0.2em] text-accent",children:"PAYPAL · CARDS"})}),g.includes("afterpay")&&h.push({key:"afterpay",title:"Afterpay",body:null,price:K("span",{className:"font-mono text-[12px] uppercase tracking-[0.2em] text-accent",children:"4 × INTEREST-FREE"})}),g.includes("square")&&o.squareApplicationId&&o.squareLocationId&&h.push({key:"square",title:"Card (Square)",body:null,price:K("span",{className:"font-mono text-[12px] uppercase tracking-[0.2em] text-accent",children:"VISA · MC · AMEX"})}),g.includes("gocardless")&&k&&h.push({key:"gocardless",title:"Bank Direct Debit",body:null,price:K("span",{className:"font-mono text-[12px] uppercase tracking-[0.2em] text-accent",children:"PAY BY BANK"})}),g.includes("zip")&&h.push({key:"zip",title:"Zip",body:null,price:K("span",{className:"font-mono text-[12px] uppercase tracking-[0.2em] text-accent",children:"PAY IN 4"})}),g.includes("klarna")&&k&&h.push({key:"klarna",title:"Klarna",body:null,price:K("span",{className:"font-mono text-[12px] uppercase tracking-[0.2em] text-accent",children:"PAY LATER"})}),g.includes("bank")&&h.push({key:"bank",title:"Bank transfer",body:null,price:K("span",{className:"font-mono text-[12px] uppercase tracking-[0.2em] text-fg-dim",children:"Invoiced"})}),h}const Po="This shop does not take payment online yet. Please contact the shop to order.";class Ye extends Error{}function kn(o,k){if(!o.orderNumber&&it(k))return k.message;const g=k instanceof $e?` (${k.message})`:"";return o.orderNumber?`Your order ${o.orderNumber} is saved, but the payment did not start${g}. Try the payment again — your order will not be placed twice.`:`Your items are held under ${o.checkoutNumber}, but the payment did not start${g}. Try the payment again — you will not be charged twice.`}const jr=3e3,Qr=.005,Cn=new Set(["paypal","square","afterpay","gocardless","zip","klarna"]);function wn(){const o=wr();return{...o==="denied"?{}:Cr(),...o?{adConsent:o}:{}}}const O=o=>JSON.parse(o),Vr={lastPress:null,keptCardKey:null,placedShape:null,placedRequest:null,unpaidOrder:null},eo={lastPress:o=>o&&{key:o.key,request:dn(o.request),lines:o.lines,goods:O(o.shape)[0],plainPressed:!!o.plainMethod,plainLines:o.plainLines,plainGoods:O(o.plainShape)[0]},keptCardKey:o=>o,placedShape:o=>o===null?null:O(o)[0],placedRequest:o=>o&&dn(o.body),unpaidOrder:o=>o&&$r(o)};function Pn(o,k){const g={};for(const h of Object.keys(o))g[h]=o[h](k[h]);return g}const bo="Shipping cannot be calculated right now. Please try again.";function No(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 to({site:o,logo:k,signInHref:g=null,preview:h=!1}){const{items:f,totals:b,coupon:M,refuseCoupon:Nn,deliveryOptions:pt,shippingMethodId:V,setShippingMethodId:ft,setQuoteDestination:he,courier:Sn,requote:ge,identify:mt,clearCapturedCart:ke,replaceItems:He,removeCoupon:yt,applyCoupon:An}=gr(),vn=pt.find(e=>e.id===V)?.pickupLocation??null,{country:ht,countries:ee,activeCountry:gt,formatMoney:On}=kr(),[w,Ce]=s(()=>gn(o)[0]?.key??null),[kt,En]=s(!0);y(()=>{En(Ar(at))},[]);const[L,Ge]=s(!1),[F,we]=s(""),[T,Pe]=s(""),[G,be]=s(""),[Ne,De]=s(""),[te,ne]=s(""),[Se,re]=s(""),[q,oe]=s(""),[_,se]=s(""),[D,ce]=s(""),[p,ae]=s(()=>ht||ee[0]?.code||""),[E,Ae]=s(""),[ie,Ct]=s([]),[ze,We]=s(null),[ve,z]=s(null),wt=un(()=>ee.find(e=>e.code===p)??gt,[ee,p,gt]),Rn=wt?.postalLabel||"Postal Code",Kn=ie[0]?.divisionType||"State / Province";y(()=>{if(!p){Ct([]),We(p);return}We(null);let e=!1;return P.listCountrySubdivisions(p).then(t=>{e||(Ct(t),We(p),Ae(""))}),()=>{e=!0}},[p]);const Pt=te.trim()!==""&&q.trim()!==""&&_.trim()!==""&&ze===p&&(ie.length===0||E!=="")?_.trim():"";y(()=>{he(p?{country:p,subdivision:E,postcode:Pt}:null)},[p,E,Pt,he]),y(()=>()=>he(null),[he]);const Mn=Sn?.status==="unavailable",Ln=ge,[ue,bt]=s(null),[Tn,Nt]=s([]),[Je,Oe]=s("new"),[St,At]=s(!1),[Xe,_n]=s("Home"),[xn,vt]=s(null),[In,Ze]=s(null),[$,Ee]=s(()=>Be()),Ot=m(null),[je,W]=s(null),[Fn,S]=s(null),[Et,Re]=s(null),[Rt,qn]=s(!1),[Kt,$n]=s(!1),[x,J]=s(null),[Bn,Ke]=s(!1),[C,A]=s(null),Mt=!!C?.orderNumber,Un=Mt||L,[Yn,Hn]=s(null),[Gn,Dn]=s(!1),[zn,Wn]=s(!1),[Jn,Xn]=s(!1),[Zn,jn]=s(!1),[Lt,Qn]=s(!1),[Vn,Qe]=s(!1),[le,Tt]=s(null),a=m({...Vr});a.current.unpaidOrder=C;const Ve=m(!1),B=m(f),_t=!!(je||le&&le.kind!=="processing"||Lt||Rt||Kt||Et&&x?.orderNumber);y(()=>{_t&&(He([]),yt())},[_t,He,yt]);const xt=m(!1);y(()=>{h||xt.current||!f.some(ln)||(xt.current=!0,Pr({lines:f,currency:b.currency,value:b.subtotal-b.discount,coupon:M?.valid?M.code:void 0}))},[f,b,M,h]),y(()=>{mt(F,T.trim()||void 0)},[F,T,mt]);const It=m(null),[Me,er]=s(null);y(()=>{const e=It.current;if(!Me||!e)return;const t=()=>e.style.setProperty("--sf-checkout-header-h",`${Me.offsetHeight}px`);t();const r=new ResizeObserver(t);return r.observe(Me),()=>r.disconnect()},[Me]),y(()=>{const e=r=>({setConfirming:r,land:W,markPaid:()=>Ke(!0),note:(c,n)=>Hn({text:c,warning:n}),fail:S,clearCart:ke,lostChange:()=>Ze(lt)}),t={search:window.location.search,storage:at,scrubQuery:()=>window.history.replaceState(null,"",window.location.pathname)};Ue(Or,{...t,capture:P.captureAfterpayPayment,page:e(Dn)}),Ue(Tr,{...t,capture:P.captureZipPayment,page:e(Xn)}),Ue(Rr,{...t,capture:P.completeGocardlessPayment,page:e(Wn)}),Ue(Mr,{...t,capture:P.captureKlarnaPayment,page:e(jn)})},[]);function Ft(e){const[t,r]=hn(e.address);ne(t),re(r),oe(e.city),se(e.zip_code),e.country&&ae(e.country),e.phone&&ce(e.phone),z({country:e.country||null,state:e.state??""})}y(()=>{if(ve){if((ve.country||p)!==p){z(null);return}ze===p&&(Ae(_r(p,ve.state,ie)),z(null))}},[ve,p,ze,ie]),y(()=>{let e=!1;return(async()=>{try{const[t,r,c]=await Promise.all([ye.me(),ye.myProfile().catch(()=>null),ye.myAddresses().catch(()=>[])]);if(e)return;bt(t);const n=c.filter(d=>d.is_active);Nt(n),we(t.email);const i=(r?.contact_name??"").split(/\s+/);Pe(t.first_name||i[0]||""),be(t.last_name||i.slice(1).join(" "));const l=t.phone||r?.phone;l&&ce(l);const u=n.find(d=>d.id===t.default_delivery_location)??n[0];if(u)Oe(u.id),Ft(u);else if(r){const[d,Q]=hn(r.address??"");ne(d),re(Q),oe(r.city??""),se(r.zip_code??""),r.country&&ae(r.country),z({country:r.country||null,state:r.state??""})}qe.current&&Gt(qe.current,!1)}catch{}})(),()=>{e=!0}},[]);function tr(){ye.logout(),de.current=!0,qe.current=null,Fe.current=null,pe(),bt(null),Nt([]),Oe("new"),At(!1),we(""),Pe(""),be(""),De(""),ne(""),re(""),oe(""),se(""),ce(""),ae(ht||ee[0]?.code||""),Ae(""),z(null)}const X=un(()=>gn(o,{canParkContext:kt}),[o,kt]);y(()=>{X.some(e=>e.key===w)||Ce(X[0]?.key??null)},[X,w]);const nr=X.length===0,Le=Se.trim()?`${te}
3
+ ${Se.trim()}`:te,rr=Jr({email:F,firstName:T,lastName:G,company:Ne.trim(),phone:D,address:Le,city:q,subdivision:E,postcode:_,country:p,lines:f.map(e=>[e.id,e.qty]),shippingMethodId:V,couponCode:yn(M),currency:b.currency,shopperId:ue?.id??null}),N=JSON.stringify([rr,w]),et=m(null),Te=m(!1),I=m(!1),Z=m(null),_e=m(!1),v=m(N);v.current=N;const qt=m(L);qt.current=L;const xe=m(null);y(()=>{const e=()=>{const t=xe.current;t&&(xe.current=null,A(t),Ge(!1))};return window.addEventListener("pageshow",e),()=>window.removeEventListener("pageshow",e)},[]);function Ie(e,t,r,c){const n={idempotencyKey:t,confirmation:r};Zt()&&(n.lostChange=!0),at.setItem(e,JSON.stringify(n)),window.location.assign(c),xe.current=r}async function $t(e){Ge(!0);try{await e()}finally{xe.current||Ge(!1)}}const Bt=m(!1),Ut=!!(je||le&&le.kind!=="processing");y(()=>{Ut&&(Bt.current=!0,pe())},[Ut]);const Fe=m(null),de=m(!1),tt=m(null);function pe(){tt.current=null,xr()}const qe=m(null),[j,or]=s(!1);function nt(e){if(Bt.current||h||de.current)return;const t={key:e,authed:Ve.current,parkedAt:tt.current??=Date.now(),press:Pn(eo,a.current),lines:f.length>0?f:B.current,form:qr({email:F,firstName:T,lastName:G,company:Ne,address1:te,address2:Se,city:q,postcode:_,phone:D,country:p,subdivision:E,selectedAddressId:Je,shippingMethodId:V,couponCode:M?.valid?M.code:null})};Ir(t.press)?Fr(t):pe()}const Yt=m(w);Yt.current=w;function rt(e){return{...Yr(e),...wn(),...e.payFirst?{checkoutFlow:dt}:{}}}function sr(e,t){let r=e.request.payFirst?"":null,c=e.plainPressed?null:"";const n=()=>Yt.current??"";return{key:e.key,send:()=>t(rt(e.request)),request:rt(e.request),lines:e.lines,shape:JSON.stringify([e.goods,null]),get method(){return r??n()},set method(i){r=i},get plainMethod(){return c??n()},set plainMethod(i){c=i},plainLines:e.plainLines,plainShape:JSON.stringify([e.plainGoods,null])}}const[cr,ar]=s(!1),Ht=cr?!b.quoted||b.serverSubtotal===null?"waiting":Math.abs(b.serverSubtotal-b.subtotal)<Qr?"same":"changed":null,ot=!C&&Ht==="waiting",ir=ot?{...b,repricing:!0}:b,st=ot&&b.quoteFailed;y(()=>{if(!st)return;const e=setInterval(ge,jr);return()=>clearInterval(e)},[st,ge]);const ur=ge;function Gt(e,t=!0){we(e.email),Pe(e.firstName),be(e.lastName),De(e.company),ne(e.address1),re(e.address2),oe(e.city),se(e.postcode),ce(e.phone),e.country&&ae(e.country),z({country:e.country||null,state:e.subdivision}),Oe(e.selectedAddressId),e.shippingMethodId&&ft(e.shippingMethodId),t&&(Fe.current=e.couponCode)}y(()=>{let e=h?null:Br();const t=!!(e&&f.length>0);if(e&&t&&!Ur(e.lines,f)&&(pe(),e=null),e){const r=e.authed?P.createOrderAuthed:P.createOrder;Ee(e.key),tt.current=e.parkedAt,Ve.current=e.authed;const c={lastPress:n=>n&&sr(n,r),keptCardKey:n=>n,placedShape:n=>n===null?null:JSON.stringify([n,null]),placedRequest:n=>{if(!n)return null;const i=rt(n);return{body:i,send:()=>r(i)}},unpaidOrder:n=>n};a.current=Pn(c,e.press),e.press.unpaidOrder&&A(e.press.unpaidOrder),e.lines.length>0&&!t&&(He(e.lines),B.current=e.lines,ar(!0)),e.form&&(qe.current=e.form,Gt(e.form))}or(!0)},[]),y(()=>{!j||f.length>0||a.current.unpaidOrder||L||(de.current=!0,pe())},[j,f.length]),y(()=>{const e=Fe.current;!j||!e||f.length===0||(Fe.current=null,An(e,F||void 0))},[j,f.length]),y(()=>{!j||L||nt($)},[j,L,$,C]);const U=m(null);y(()=>{qt.current||(N!==U.current&&(U.current=null),!(!I.current||!C||C.orderNumber)&&(N===a.current.placedShape||N===U.current||$t(()=>Dt(C))))},[N,C]);async function Dt(e){if(_e.current)return null;_e.current=!0;try{const t=Z.current?await zr(Z.current):"none";if(t==="succeeded"||t==="processing")return I.current=!1,A(null),R("card"),t==="succeeded"?await Y(void 0,e):tn(e),null;if(t===void 0||!Gr.has(t))return U.current=v.current,A(e),S(t==="requires_action"?Hr:ut),null;const r=await fn($);if(r==="committed")return I.current=!1,A(null),R("card"),await Y(void 0,e),null;if(r!=="released")return U.current=v.current,A(e),S(ut),null;I.current=!1,Z.current=null,U.current=null,S(null),A(null);const c=Be();return Ee(c),c}finally{_e.current=!1}}async function lr(){h||L||_e.current||await $t(dr)}async function dr(){if(C){if((I.current?N!==a.current.placedShape:fe())&&!C.orderNumber){const c=await Dt(C);c&&v.current===N&&await zt(c);return}S(null),Te.current=!1,await ct();const t=O(v.current)[1],r=C.orderNumber?t:"card";if(r&&Cn.has(r)&&fe()&&O(v.current)[0]!==et.current){Wt(C);return}R(r),r!==w&&Ce(r),await nn(C,r,!C.orderNumber);return}await zt($)}async function zt(e){if(f.length===0||b.repricing||ot||!w||!X.some(l=>l.key===w))return;const t=f.filter(ln).flatMap(l=>Sr(l.components,l.qty));if(t.length===0){S("Pick a size on each wheel's product page before checking out.");return}S(null);let r,c=e,n=w,i=!1;try{const l=ue?P.createOrderAuthed:P.createOrder,u={customer:{email:F,name:`${T} ${G}`.trim(),phone:D.trim()||void 0,companyName:Ne.trim()||void 0,address:Le,city:q,state:E||void 0,zipCode:_,country:p},items:t,currency:b.currency,idempotencyKey:e,shippingMethodId:V??void 0,couponCode:yn(M),...wn(),...Dr(w)?{checkoutFlow:dt}:{}};a.current.placedRequest={body:u,send:()=>l(u)},Ve.current=!!ue,de.current=!1,Ze(null),et.current=null,Te.current=!1,Z.current=null,I.current=!1,U.current=null,a.current.placedShape=N,B.current=f;const d=a.current.lastPress,Q=d?.key===u.idempotencyKey&&(d.shape!==N&&(!!u.checkoutFlow||!!d.method||!!d.plainMethod)||!!u.checkoutFlow&&!!d.plainMethod);Q&&(a.current.keptCardKey=u.idempotencyKey);const sn=Qt(u,l),cn=Q||!u.checkoutFlow&&a.current.keptCardKey===u.idempotencyKey,an=!sn&&!cn&&!u.checkoutFlow&&!!d&&!d.method;an&&(d.plainMethod=w,d.plainLines=f,d.plainShape=N,nt(u.idempotencyKey));const H=await(cn?Xt(u,l):l(u).then(me=>({answer:me,request:u})).catch(me=>(sn?Jt(me,u.idempotencyKey):an&&mn(me)&&(d.plainMethod=""),pr(me,u,l))));if(!H)return;r=H.answer,c=H.request.idempotencyKey,n=H.method??n,R(n),i=fe()||n!==O(v.current)[1],H.method&&H.method!==w&&Ce(H.method),r.orderNumber&&(Vt(r),ke()),await ct()}catch(l){const u=Zr(l);u?(Nn(u),S(`${u} Your order has not been placed. Place it again to continue without the code.`)):l instanceof Ye?S(ut):S(l instanceof $e?l.message:"Could not place the order. Please try again.");return}if(n&&Cn.has(n)&&(i||fe())){Wt(r);return}await nn(r,n,!1,c)}function Wt(e){et.current=O(v.current)[0],S(`${kn(e,null)} ${lt}`),A(e)}function Jt(e,t){mn(e)&&!pn(e)&&a.current.lastPress?.key===t&&(a.current.lastPress=null)}async function pr(e,t,r){if(it(e))return jt(t,r);if(!pn(e))throw e;return a.current.keptCardKey=t.idempotencyKey,Xt(t,r,!0)}async function Xt(e,t,r=!1){const c=await fn(e.idempotencyKey);if(c==="released")return jt(e,t);if(c!=="committed")throw new Ye;const n=a.current.lastPress?.key===e.idempotencyKey?a.current.lastPress:null;if(B.current=n?.lines??f,n?.method&&!r){a.current.keptCardKey=null,a.current.placedRequest={body:n.request,send:n.send};const Q=await n.send().catch(()=>{throw new Ye});return a.current.placedShape=n.shape,{answer:Q,request:e,method:n.method}}const i={...e,checkoutFlow:dt},l=n&&!n.method?{body:n.request,send:n.send}:{body:i,send:()=>t(i)};a.current.placedRequest=l;const u=l.send,d=await u().catch(()=>null);if(!d&&n?.plainMethod)throw new Ye;return d?.orderNumber&&d.status!==Wr?(a.current.keptCardKey=null,n?.plainMethod&&(B.current=n.plainLines),n&&(a.current.placedShape=n.plainMethod?n.plainShape:n.shape),{answer:d,request:e,method:n?.plainMethod||void 0}):(n&&(a.current.placedShape=n.shape),R("card"),await en("",d?async()=>d:()=>Promise.reject(new Error("The order request did not answer."))),await ct(),null)}function fe(){const e=a.current.placedShape;return e!==null&&O(e)[0]!==O(v.current)[0]}function R(e){e!==O(v.current)[1]&&(Te.current=!0),Ze(Zt()?lt:null)}function Zt(){return Te.current||fe()}async function jt(e,t){const r={...e,idempotencyKey:Be()};a.current.keptCardKey=null,Ee(r.idempotencyKey),a.current.placedRequest={body:r,send:()=>t(r)},Qt(r,t);try{return{answer:await t(r),request:r}}catch(c){throw Jt(c,r.idempotencyKey),c}}function Qt(e,t){return a.current.lastPress?.key===e.idempotencyKey?!1:(a.current.lastPress={key:e.idempotencyKey,send:()=>t(e),request:e,lines:f,shape:N,method:e.checkoutFlow?"":w??"",plainMethod:"",plainLines:f,plainShape:N},de.current=!1,nt(e.idempotencyKey),!0)}function Vt(e){br({confirmation:e,lines:B.current,adsSendTo:o.googleAdsId&&o.googleAdsConversionLabel?`${o.googleAdsId}/${o.googleAdsConversionLabel}`:null}),Nr({confirmation:e,lines:B.current})}async function Y(e,t=x){if(!t)return;const r=e?async()=>e:a.current.placedRequest?.send;if(t.orderNumber||!r){Ke(!0),W(t);return}await en(t.checkoutNumber,r)}async function en(e,t){ke(),await Xr({checkoutNumber:e,resend:t,page:{setConfirming:Qn,land:W,markPaid:()=>Ke(!0),track:Vt,unplaced:Tt}})}function tn(e=x){if(e){if(e.orderNumber){W(e);return}ke(),Tt({kind:"processing",checkoutNumber:e.checkoutNumber})}}async function ct(){const e=JSON.stringify([Xe.trim(),T,G,D.trim(),Le,q,E,_,p]);if(!(!ue||!St||Je!=="new"||Ot.current===e))try{await ye.createAddress({label:Xe.trim()||"Home",contact_name:`${T} ${G}`.trim(),phone:D.trim(),address:Le,city:q,zip_code:_,state:E,country:p}),Ot.current=e,vt("Address saved to your account.")}catch{vt("We couldn't save the address to your account — you can add it under Account → Addresses.")}}async function nn(e,t=w,r=!1,c=$){A(null);try{if(t==="card"&&o.paymentMethods.includes("card")){const n=await P.createPaymentIntent({idempotencyKey:c});Z.current=n;let i=e;if(r){const l=await a.current.placedRequest?.send().catch(()=>null);if(l?.orderNumber){R("card"),await Y(l,e);return}i=rn(e,l)??{...e,expiresAt:null}}R("card"),J(i),Qe(!1),Re(n)}else if(t==="paypal"&&o.paymentMethods.includes("paypal"))J(e),qn(!0);else if(t==="afterpay"&&o.paymentMethods.includes("afterpay")){const n=window.location.origin,i=await P.createAfterpayCheckout({idempotencyKey:c,confirmUrl:`${n}/checkout?afterpay=confirm`,cancelUrl:`${n}/checkout?afterpay=cancel`});Ie(vr,c,e,i.redirectCheckoutUrl);return}else if(t==="square"&&o.paymentMethods.includes("square"))J(e),$n(!0);else if(t==="gocardless"&&o.paymentMethods.includes("gocardless")){const n=window.location.origin,i=await P.createGocardlessBillingRequest({idempotencyKey:c,confirmUrl:`${n}/checkout?gocardless=confirm`,cancelUrl:`${n}/checkout?gocardless=cancel`});Ie(Er,c,e,i.authorisationUrl);return}else if(t==="zip"&&o.paymentMethods.includes("zip")){const n=window.location.origin,i=await P.createZipCheckout({idempotencyKey:c,redirectUrl:`${n}/checkout?zip=return`});Ie(Lr,c,e,i.redirectUrl);return}else if(t==="klarna"&&o.paymentMethods.includes("klarna")){const n=window.location.origin,i=await P.createKlarnaCheckout({idempotencyKey:c,confirmUrl:`${n}/checkout?klarna=confirm`,cancelUrl:`${n}/checkout?klarna=cancel`});Ie(Kr,c,e,i.redirectUrl);return}else R(t),W(e)}catch(n){if((r||t==="card")&&n instanceof $e&&n.status===409){R(t),await Y(void 0,e);return}on(e,n)}}function rn(e,t){return t&&!t.orderNumber&&t.status==="open"&&t.checkoutNumber===e.checkoutNumber?t:null}function on(e,t){S(kn(e,t)),!e.orderNumber&&it(t)?(I.current=!1,Ee(Be())):A(e)}async function fr(e){if(!x)return;const t=x;try{const r=await P.createPaymentIntent({idempotencyKey:$}),c=await a.current.placedRequest?.send().catch(()=>null);if(c?.orderNumber){await Y(c);return}const n=rn(t,c);J(n??{...t,expiresAt:null}),Qe(e&&n!==null),Z.current=r,Re(r)}catch(r){if(r instanceof $e&&r.status===409){await Y();return}Re(null),J(null),on(t,r)}}function mr(){x&&(I.current=!0,A(x),Re(null),J(null),Qe(!1))}return{site:o,logo:k,signInHref:g,items:f,totals:ir,coupon:M,deliveryOptions:pt,courierUnavailable:Mn,retryCourier:Ln,shippingMethodId:V,setShippingMethodId:ft,pickupLocation:vn,servedCountries:ee,formatMoney:On,payChoice:w,setPayChoice:Ce,placing:L,email:F,setEmail:we,firstName:T,setFirstName:Pe,lastName:G,setLastName:be,company:Ne,setCompany:De,address1:te,setAddress1:ne,address2:Se,setAddress2:re,city:q,setCity:oe,postcode:_,setPostcode:se,phone:D,setPhone:ce,country:p,setCountry:ae,subdivision:E,setSubdivision:Ae,subdivisions:ie,destination:wt,postcodeLabel:Rn,subdivisionLabel:Kn,me:ue,savedAddresses:Tn,selectedAddressId:Je,setSelectedAddressId:Oe,saveAddress:St,setSaveAddress:At,saveLabel:Xe,setSaveLabel:_n,addressSaveNote:xn,lostChangeNote:In,idemKey:$,confirmation:je,setConfirmation:W,orderError:Fn,payment:Et,paypalStep:Rt,squareStep:Kt,pendingConf:x,paid:Bn,setPaid:Ke,unpaidOrder:C,orderLocked:Mt,formLocked:Un,restoredPrices:Ht,quoteFailed:st,retryQuote:ur,payNote:Yn,afterpayConfirming:Gn,gocardlessConfirming:zn,zipConfirming:Jn,klarnaConfirming:Zn,cardConfirming:Lt,checkoutResult:le,confirmCardPayment:Y,cardStillProcessing:tn,renewCardPayment:fr,holdRenewed:Vn,leaveCardPayment:mr,checkoutRootRef:It,setCheckoutHeaderEl:er,fillFromAddress:Ft,checkoutSignOut:tr,payOptions:X,noPaymentMethod:nr,placeOrder:lr}}const bn=yr(null);function So({children:o,...k}){const g=to(k);return K(bn.Provider,{value:g,children:o})}function Ao(){const o=hr(bn);if(!o)throw new Error("useCheckout must be used inside CheckoutStateProvider");return o}export{So as CheckoutStateProvider,Po as NO_PAYMENT_METHOD_NOTE,bo as SHIPPING_RETRY_NOTE,gn as buildPayOptions,kn as paymentNotStartedMessage,No as placedOrderLockNote,Ao as useCheckout};