efficient-storefront-blocks 0.118.1 → 0.118.3

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.
@@ -3,14 +3,8 @@ import { type HeroPriceTemplateProps } from "./ProductHeroPanel.js";
3
3
  import type { HeroPricePlacement } from "../lib/sections/hero-price-placement.js";
4
4
  import type { HeroLayout, HeroTextAlign } from "../lib/sections/hero-arrangement.js";
5
5
  import type { HeroGalleryMode, HeroImageFit } from "../lib/sections/hero-gallery.js";
6
- import { type Tyre, type Wheel } from "../lib/api/index.js";
7
- export type LinkedHeroRecord = {
8
- kind: "wheel";
9
- wheel: Wheel;
10
- } | {
11
- kind: "tyre";
12
- tyre: Tyre;
13
- };
6
+ import { type LinkedHeroRecord } from "../lib/document/linked-hero-hydrate.js";
7
+ export type { LinkedHeroRecord };
14
8
  interface HeroArrangement extends HeroPriceTemplateProps {
15
9
  heroLayout?: HeroLayout;
16
10
  imageRatio?: number;
@@ -21,10 +15,11 @@ interface HeroArrangement extends HeroPriceTemplateProps {
21
15
  imageFit?: HeroImageFit;
22
16
  trustBullets?: ReactNode;
23
17
  }
24
- export default function LinkedProductHero({ slug, kind, editing, pricePlacement, showVehicleFitment, ...arrangement }: {
18
+ export default function LinkedProductHero({ slug, kind, editing, pricePlacement, showVehicleFitment, initialRecord, ...arrangement }: {
25
19
  slug: string;
26
20
  kind?: "wheel" | "tyre";
27
21
  editing?: boolean;
22
+ initialRecord?: LinkedHeroRecord;
28
23
  pricePlacement?: HeroPricePlacement;
29
24
  showVehicleFitment?: boolean;
30
25
  } & HeroArrangement): import("react").JSX.Element;
@@ -34,4 +29,3 @@ export declare function LinkedHeroLoaded({ record, editing, pricePlacement, show
34
29
  pricePlacement?: HeroPricePlacement;
35
30
  showVehicleFitment?: boolean;
36
31
  } & HeroArrangement): import("react").JSX.Element;
37
- export {};
@@ -1 +1 @@
1
- "use client";import{jsx as i,Fragment as x,jsxs as g}from"react/jsx-runtime";import{useEffect as L,useState as f}from"react";import P from"./ProductHeroPanel.js";import y from"./ProductLightbox.js";import a from"./SectionNotice.js";import{useLightbox as w}from"./useLightbox.js";import{useProductSelection as b}from"./useProductSelection.js";import{fromTyre as j}from"../lib/catalog/from-tyre.js";import{fromWheel as k}from"../lib/catalog/from-wheel.js";import{products as h}from"../lib/api/index.js";function F({slug:e,kind:r="wheel",editing:l=!1,pricePlacement:s,showVehicleFitment:m=!0,...n}){const[c,t]=f(null),[p,u]=f(!1);return L(()=>{let d=!1;return t(null),u(!1),(r==="tyre"?h.getTyre(e).then(o=>({kind:"tyre",tyre:o})):h.getWheel(e).then(o=>({kind:"wheel",wheel:o}))).then(o=>{d||t(o)}).catch(()=>{d||u(!0)}),()=>{d=!0}},[e,r]),p?i(a,{size:"tall",children:"Couldn’t load this product."}):c?i(H,{record:c,editing:l,pricePlacement:s,showVehicleFitment:m,...n}):i(a,{size:"tall",children:"Loading product…"})}function H({record:e,editing:r=!1,pricePlacement:l,showVehicleFitment:s=!0,...m}){const n=e.kind==="tyre"?j(e.tyre):k(e.wheel),c=b(n,{editing:r}),t=w();return g(x,{children:[i(P,{product:n,selection:c,onLightbox:t.open,editing:r,pricePlacement:l,showVehicleFitment:s,...m}),i(y,{item:t.item,onClose:t.close})]})}export{H as LinkedHeroLoaded,F as default};
1
+ "use client";import{jsx as i,Fragment as L,jsxs as P}from"react/jsx-runtime";import{useEffect as y,useState as h}from"react";import w from"./ProductHeroPanel.js";import b from"./ProductLightbox.js";import p from"./SectionNotice.js";import{useLightbox as j}from"./useLightbox.js";import{useProductSelection as k}from"./useProductSelection.js";import{fromTyre as F}from"../lib/catalog/from-tyre.js";import{fromWheel as H}from"../lib/catalog/from-wheel.js";import{products as x}from"../lib/api/index.js";import{matchingLinkedRecord as S}from"../lib/document/linked-hero-hydrate.js";function _({slug:e,kind:r="wheel",editing:c=!1,pricePlacement:l,showVehicleFitment:s=!0,initialRecord:n,...m}){const t=S(n,r,e),[f,d]=h(t??null),[g,a]=h(!1);return y(()=>{if(a(!1),t){d(t);return}let u=!1;return d(null),(r==="tyre"?x.getTyre(e).then(o=>({kind:"tyre",tyre:o})):x.getWheel(e).then(o=>({kind:"wheel",wheel:o}))).then(o=>{u||d(o)}).catch(()=>{u||a(!0)}),()=>{u=!0}},[e,r,t]),g?i(p,{size:"tall",children:"Couldn’t load this product."}):f?i(z,{record:f,editing:c,pricePlacement:l,showVehicleFitment:s,...m}):i(p,{size:"tall",children:"Loading product…"})}function z({record:e,editing:r=!1,pricePlacement:c,showVehicleFitment:l=!0,...s}){const n=e.kind==="tyre"?F(e.tyre):H(e.wheel),m=k(n,{editing:r}),t=j();return P(L,{children:[i(w,{product:n,selection:m,onLightbox:t.open,editing:r,pricePlacement:c,showVehicleFitment:l,...s}),i(b,{item:t.item,onClose:t.close})]})}export{z as LinkedHeroLoaded,_ as default};
@@ -1 +1 @@
1
- "use client";import{jsx as e,Fragment as v,jsxs as a}from"react/jsx-runtime";import{useId as j}from"react";import V from"next/image";import X from"next/link";import{lineTotal as Z,useCart as J}from"../CartContext.js";import{useCurrency as ee}from"../CurrencyContext.js";import{Notice as _}from"../Notice.js";import{FREE_PRICE as O}from"../../lib/wheels/price-display.js";import te from"../CouponField.js";import{COUPON_DEFERRED_TOTAL as ne}from"../../lib/cart/coupon-preview.js";import{orderReference as ae}from"../../lib/checkout/pay-first.js";import{PRICES_REQUOTED as re}from"../../lib/checkout/checkout-memory.js";import{shippingWords as ie,TAX_PENDING as le}from"../../lib/cart/shipping-status.js";import{DEFAULT_FINISH_COLOR as oe}from"../../lib/wheels/finish-defaults.js";import D from"../ThemedSelect.js";import g from"../WebFormField.js";import se from"../WheelSvg.js";import{NO_PAYMENT_METHOD_NOTE as ce,placedOrderLockNote as de,SHIPPING_RETRY_NOTE as pe,useCheckout as S}from"./checkout-state.js";import{FIELD_INPUT_CLASS as u}from"../../lib/field-input.js";import{FIGURE_UPDATING as P}from"../../lib/wheels/price-display.js";function $e(){const{email:t,setEmail:i,firstName:n,setFirstName:l,lastName:c,setLastName:d,company:f,setCompany:y,me:b,checkoutSignOut:h,orderLocked:x,unpaidOrder:o}=S(),s=j();return a(L,{num:"N° 01",title:"Contact",children:[x&&o&&e(he,{orderNumber:o.orderNumber}),e(g,{label:"Email",htmlFor:s,hint:b?a(v,{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:s,type:"email",value:t,onChange:p=>i(p.target.value),placeholder:"you@example.com",readOnly:b!==null,className:u})}),a(U,{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:c,onChange:p=>d(p.target.value),className:u})})]}),e(g,{label:"Company (optional)",children:e("input",{type:"text",value:f,onChange:p=>y(p.target.value),autoComplete:"organization",className:u})})]})}function De(){const{pickupLocation:t,servedCountries:i,address1:n,setAddress1:l,address2:c,setAddress2:d,city:f,setCity:y,postcode:b,setPostcode:h,phone:x,setPhone:o,country:s,setCountry:p,subdivision:C,setSubdivision:m,subdivisions:w,destination:N,postcodeLabel:q,subdivisionLabel:z,me:A,savedAddresses:B,selectedAddressId:I,setSelectedAddressId:T,saveAddress:R,setSaveAddress:H,saveLabel:G,setSaveLabel:W,fillFromAddress:K,orderLocked:Q}=S(),$=j(),F=j();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(v,{children:[A!==null&&B.length>0&&a("div",{className:"grid gap-3",children:[B.map(r=>e(E,{active:I===r.id,onClick:()=>{T(r.id),K(r)},title:r.label,body:r.formatted_address,price:null},r.id)),e(E,{active:I==="new",onClick:()=>T("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:c,onChange:r=>d(r.target.value),placeholder:"Apartment, unit, garage bay…",className:u})}),a(U,{cols:"three",children:[e(g,{label:"City",children:e("input",{type:"text",value:f,onChange:r=>y(r.target.value),className:u})}),e(g,{label:q,children:e("input",{type:"text",value:b,onChange:r=>h(r.target.value),className:u})}),e(g,{label:"Country",separate:!0,htmlFor:$,children:e(D,{id:$,value:s,onChange:r=>p(r.target.value),className:u+" pr-10",style:Y,children:i.map(r=>e("option",{value:r.code,children:r.name},r.code))})})]}),e(g,{label:z,separate:!0,htmlFor:F,children:w.length>0?a(D,{id:F,value:C,onChange:r=>m(r.target.value),className:u+" pr-10",style:Y,children:[e("option",{value:"",children:"Select…"}),w.map(r=>e("option",{value:r.code||r.name,children:r.name},r.code||r.name))]}):e("input",{id:F,type:"text",value:C,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&&A!==null&&I==="new"&&!Q&&a(v,{children:[e(ge,{checked:R,onChange:H,label:"Save this address to my account"}),R&&e(g,{label:"Address label",children:e("input",{type:"text",value:G,onChange:r=>W(r.target.value),placeholder:"Home",className:u})})]})]})}function Me(){const{totals:t,coupon:i,deliveryOptions:n,shippingMethodId:l,setShippingMethodId:c,pickupLocation:d,formatMoney:f,city:y,destination:b,courierUnavailable:h,retryCourier:x}=S();return e(L,{num:"N° 03",title:"Shipping",children:a("div",{className:"grid gap-3",children:[n.map(o=>{const s=o.pickupLocation,p=s?[s.address,s.city,s.state,s.zipCode].filter(Boolean).join(", "):null;return e(E,{active:l===o.id,onClick:()=>c(o.id),title:s?`${o.name} — ${s.name}`:o.name,body:s?[p,s.openingHours,s.readyIn,s.instructions,o.description].filter(Boolean).join(" · "):o.description||null,price:t.freeShipping||o.amount===0?O: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:[pe," ",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 Ye(){const{payChoice:t,setPayChoice:i,payment:n,payOptions:l,noPaymentMethod:c}=S();return a(L,{num:"N° 04",title:"Payment",children:[c&&e("p",{className:"font-mono text-[11px] uppercase tracking-[0.2em] text-fg-dim",children:ce}),e("div",{className:"grid gap-3",children:l.map(d=>e(E,{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 Ue(){const{site:t,items:i,totals:n,coupon:l,formatMoney:c,payChoice:d,placing:f,email:y,orderError:b,payment:h,noPaymentMethod:x,unpaidOrder:o,formLocked:s,restoredPrices:p,placeOrder:C}=S(),m=p==="waiting",w=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(M,{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(M,{href:"/wheels",className:"text-accent underline-offset-4 hover:underline",children:"Browse the catalog →"})]}):i.map(N=>e(fe,{slug:N.slug,name:N.name,qty:N.qty,config:N.config,configSummary:xe(N.config),price:w||m?null:Z(N,n.currency)??0,currency:n.currency},N.id))}),e(ue,{locked:s,className:"border-t border-line px-6 pt-5",children:e(te,{customerEmail:y,disabled:s})}),a("div",{className:"flex flex-col gap-2 border-t border-line mt-5 px-6 pt-5",children:[e(k,{label:"Subtotal",value:m?P:c(w?n.serverSubtotal??0:n.subtotal,n.currency)}),n.discount>0&&l?.valid&&e(k,{label:`Coupon · ${l.code}`,value:a("span",{className:"font-semibold text-green",children:["− ",c(n.discount,n.currency)]})}),l?.deferred&&e(k,{label:`Coupon · ${l.code}`,value:ne}),l?.valid&&l.effects?.gift&&e(k,{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:O})}),e(k,{label:"Shipping",value:n.shippingStatus==="free"?e("span",{className:"font-semibold text-green",children:O}):ie(n.shippingStatus)??c(n.shipping,n.currency)}),n.tax&&(n.tax.charged?e(k,{label:n.tax.inclusive?`${n.tax.name} included · ${n.tax.rate}%`:n.tax.name,value:c(n.tax.amount,n.currency)}):n.tax.name?e(k,{label:n.tax.name,value:le}):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?P:c(n.grand,n.currency)})]}),a("div",{className:"flex flex-col gap-3 px-6 pt-5 pb-6",children:[w&&e(_,{tone:"quiet",children:re}),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:C,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",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(v,{children:["Building order… ",e("span",{children:"·"})]}):x?a(v,{children:["No online payment ",e("span",{children:"·"})]}):o?a(v,{children:["Try payment again · ",ae(o),e("span",{className:"transition-transform group-hover:translate-x-1",children:"→"})]}):n.repricing?a(v,{children:[P," ",e("span",{children:"·"})]}):a(v,{children:[d==="bank"?"Place order":"Continue to payment"," ·"," ",c(n.grand,n.currency),e("span",{className:"transition-transform group-hover:translate-x-1",children:"→"})]})})]})]})}const me=" [&:disabled_:disabled]:cursor-not-allowed! [&:disabled_:disabled]:opacity-70! [&_input[readonly]]:cursor-not-allowed [&_input[readonly]]:opacity-70";function ue({locked:t,className:i="",children:n}){return e("fieldset",{disabled:t,className:"m-0 min-w-0 border-0 p-0 "+i+me,children:n})}function M({href:t,className:i="",children:n,...l}){const{placing:c}=S();return c?e("span",{"aria-disabled":"true","aria-label":l["aria-label"],className:i+" pointer-events-none",children:n}):e(X,{href:t,"aria-label":l["aria-label"],className:i,children:n})}function he({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:de(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 U({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 E({active:t,onClick:i,title:n,body:l,price:c,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:c})]})}function ge({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 fe({slug:t,name:i,qty:n,config:l,configSummary:c,price:d,currency:f}){const{catalog:y}=J(),{formatMoney:b}=ee(),h=y.find(m=>m.slug===t),x=h?.spokes??5,o=h?.mesh??!1,s=l.find(m=>m.gold)?.label,p=h?.finishes.find(m=>m.name===s&&m.src)??h?.finishes.find(m=>m.src),C=h?.finishes[0]?.color??oe;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(V,{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:C},children:e(se,{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:c})]}),e("span",{className:"text-right font-display text-[17px] font-bold tracking-[-0.005em] text-fg",children:d===null?null:b(d,f)})]})}function k({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 xe(t){return t.map(i=>i.label).join(" · ")}export{$e as CheckoutContact,Ue as CheckoutOrderSummary,Ye as CheckoutPayment,De as CheckoutShippingAddress,Me as CheckoutShippingMethod,ue as FormLock,M 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 V from"next/image";import X from"next/link";import{lineTotal as Z,useCart as J}from"../CartContext.js";import{useCurrency as ee}from"../CurrencyContext.js";import{Notice as _}from"../Notice.js";import{FREE_PRICE as A}from"../../lib/wheels/price-display.js";import te from"../CouponField.js";import{COUPON_DEFERRED_TOTAL as ne}from"../../lib/cart/coupon-preview.js";import{orderReference as ae}from"../../lib/checkout/pay-first.js";import{PRICES_REQUOTED as re,PRICES_UNCHECKED as ie}from"../../lib/checkout/checkout-memory.js";import{shippingWords as le,TAX_PENDING as oe}from"../../lib/cart/shipping-status.js";import{DEFAULT_FINISH_COLOR as ce}from"../../lib/wheels/finish-defaults.js";import U from"../ThemedSelect.js";import g from"../WebFormField.js";import se from"../WheelSvg.js";import{NO_PAYMENT_METHOD_NOTE as de,placedOrderLockNote as pe,SHIPPING_RETRY_NOTE as me,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 $e(){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(ge,{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(z,{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 Me(){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:H,saveLabel:G,setSaveLabel:W,fillFromAddress:K,orderLocked:Q}=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),K(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(z,{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"&&!Q&&a(N,{children:[e(fe,{checked:$,onChange:H,label:"Save this address to my account"}),$&&e(g,{label:"Address label",children:e("input",{type:"text",value:G,onChange:r=>W(r.target.value),placeholder:"Home",className:u})})]})]})}function Ue(){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:[me," ",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 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:de}),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: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(xe,{slug:y.slug,name:y.name,qty:y.qty,config:y.config,configSummary:be(y.config),price:S||F?null:Z(y,n.currency)??0,currency:n.currency},y.id))}),e(he,{locked:c,className:"border-t border-line px-6 pt-5",children:e(te,{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:ne}),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}):le(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:oe}):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:re}),k&&a(_,{role:"alert",children:[ie," ",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",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:["Try payment again · ",ae(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:[d==="bank"?"Place order":"Continue to payment"," ·"," ",s(n.grand,n.currency),e("span",{className:"transition-transform group-hover:translate-x-1",children:"→"})]})})]})]})}const ue=" [&:disabled_:disabled]:cursor-not-allowed! [&:disabled_:disabled]:opacity-70! [&_input[readonly]]:cursor-not-allowed [&_input[readonly]]:opacity-70";function he({locked:t,className:i="",children:n}){return e("fieldset",{disabled:t,className:"m-0 min-w-0 border-0 p-0 "+i+ue,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(X,{href:t,"aria-label":l["aria-label"],className:i,children:n})}function ge({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:pe(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 z({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 fe({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 xe({slug:t,name:i,qty:n,config:l,configSummary:s,price:d,currency:f}){const{catalog:v}=J(),{formatMoney:b}=ee(),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??ce;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(V,{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(se,{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 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 be(t){return t.map(i=>i.label).join(" · ")}export{$e as CheckoutContact,qe as CheckoutOrderSummary,Ye as CheckoutPayment,Me as CheckoutShippingAddress,Ue as CheckoutShippingMethod,he as FormLock,Y as LeaveLink};
@@ -189,6 +189,8 @@ declare function useCheckoutState({ site, logo, preview }: CheckoutProps): {
189
189
  orderLocked: boolean;
190
190
  formLocked: boolean;
191
191
  restoredPrices: "waiting" | "changed" | "same" | null;
192
+ quoteFailed: boolean;
193
+ retryQuote: () => void;
192
194
  payNote: PayNote | null;
193
195
  afterpayConfirming: boolean;
194
196
  gocardlessConfirming: boolean;
@@ -1,3 +1,3 @@
1
- "use client";import{jsx as R}from"react/jsx-runtime";import{createContext as fr,useContext as mr,useEffect as h,useMemo as an,useRef as y,useState as s}from"react";import{isOrderable as un,useCart as yr}from"../CartContext.js";import{useCurrency as hr}from"../CurrencyContext.js";import{getClickIds as gr}from"../../lib/click-ids.js";import{adConsentForOrder as kr}from"../../lib/consent/choice.js";import{trackBeginCheckout as Cr,trackPurchase as wr}from"../../lib/google-tag.js";import{trackMetaPurchase as Pr}from"../../lib/meta-pixel.js";import{ApiError as Fe,api as me,products as w}from"../../lib/api/index.js";import{uuid as qe}from"../../lib/uuid.js";import{orderLinesForSets as br}from"../../lib/commerce.js";import{canPersist as Nr,safeSessionStorage as st}from"efficient-web-builder/format/lib/safe-storage";import{AFTERPAY_CONTEXT_KEY as Sr,AFTERPAY_RETURN as Ar,GOCARDLESS_CONTEXT_KEY as vr,GOCARDLESS_RETURN as Or,KLARNA_CONTEXT_KEY as Er,KLARNA_RETURN as Rr,ZIP_CONTEXT_KEY as Kr,ZIP_RETURN as Mr,runWalletReturn as $e}from"../../lib/checkout/wallet-return.js";import{matchSubdivision as Lr}from"../../lib/checkout/match-subdivision.js";import{clearCheckoutMemory as Tr,holdsPress as _r,parkCheckoutMemory as xr,parkForm as Ir,parkOrder as Fr,parkRequest as ln,readCheckoutMemory as qr,sameGoods as $r,sendableRequest as Br}from"../../lib/checkout/checkout-memory.js";import{checkoutGone as ct,checkoutWaiting as dn,BANK_WAITING as Ur,DROPPABLE_INTENT as Yr,NOT_CHECKED as at,LOST_CHANGE as it,PAY_FIRST_FLOW as ut,paysFirst as Hr,readIntentStatus as Gr,releaseHeldCheckout as pn,CHECKOUT_COMMITTED as Dr,goodsShapeOf as zr,refusedForGood as fn,settlePayFirst as Wr}from"../../lib/checkout/pay-first.js";import{couponCodeForOrder as mn,couponRefusedByOrder as Jr}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 Co="This shop does not take payment online yet. Please contact the shop to order.";class Be extends Error{}function gn(o,g){if(!o.orderNumber&&ct(g))return g.message;const f=g instanceof Fe?` (${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 Xr=3e3,Zr=.005,kn=new Set(["paypal","square","afterpay","gocardless","zip","klarna"]);function Cn(){const o=kr();return{...o==="denied"?{}:gr(),...o?{adConsent:o}:{}}}const v=o=>JSON.parse(o),jr={lastPress:null,keptCardKey:null,placedShape:null,placedRequest:null,unpaidOrder:null},Qr={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&&Fr(o)};function wn(o,g){const f={};for(const a of Object.keys(o))f[a]=o[a](g[a]);return f}const wo="Shipping cannot be calculated right now. Please try again.";function Po(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 Vr({site:o,logo:g,preview:f=!1}){const{items:a,totals:P,coupon:K,refuseCoupon:bn,deliveryOptions:lt,shippingMethodId:Q,setShippingMethodId:dt,setQuoteDestination:ye,courier:Nn,requote:Ue,identify:pt,clearCapturedCart:he,replaceItems:Ye,removeCoupon:ft,applyCoupon:Sn}=yr(),An=lt.find(e=>e.id===Q)?.pickupLocation??null,{country:mt,countries:V,activeCountry:yt,formatMoney:vn}=hr(),[C,ge]=s(()=>hn(o)[0]?.key??null),[ht,On]=s(!0);h(()=>{On(Nr(st))},[]);const[M,He]=s(!1),[I,ke]=s(""),[L,Ce]=s(""),[H,we]=s(""),[Pe,Ge]=s(""),[ee,te]=s(""),[be,ne]=s(""),[F,re]=s(""),[T,oe]=s(""),[G,se]=s(""),[m,ce]=s(()=>mt||V[0]?.code||""),[O,Ne]=s(""),[ae,gt]=s([]),[De,ze]=s(null),[Se,D]=s(null),kt=an(()=>V.find(e=>e.code===m)??yt,[V,m,yt]),En=kt?.postalLabel||"Postal Code",Rn=ae[0]?.divisionType||"State / Province";h(()=>{if(!m){gt([]),ze(m);return}ze(null);let e=!1;return w.listCountrySubdivisions(m).then(t=>{e||(gt(t),ze(m),Ne(""))}),()=>{e=!0}},[m]);const Ct=ee.trim()!==""&&F.trim()!==""&&T.trim()!==""&&De===m&&(ae.length===0||O!=="")?T.trim():"";h(()=>{ye(m?{country:m,subdivision:O,postcode:Ct}:null)},[m,O,Ct,ye]),h(()=>()=>ye(null),[ye]);const Kn=Nn?.status==="unavailable",Mn=Ue,[ie,wt]=s(null),[Ln,Pt]=s([]),[We,Ae]=s("new"),[bt,Nt]=s(!1),[Je,Tn]=s("Home"),[_n,St]=s(null),[xn,Xe]=s(null),[q,ve]=s(()=>qe()),At=y(null),[Ze,z]=s(null),[In,N]=s(null),[vt,Oe]=s(null),[Ot,Fn]=s(!1),[Et,qn]=s(!1),[_,W]=s(null),[$n,Ee]=s(!1),[k,S]=s(null),Rt=!!k?.orderNumber,Bn=Rt||M,[Un,Yn]=s(null),[Hn,Gn]=s(!1),[Dn,zn]=s(!1),[Wn,Jn]=s(!1),[Xn,Zn]=s(!1),[Kt,jn]=s(!1),[Qn,je]=s(!1),[ue,Mt]=s(null),i=y({...jr});i.current.unpaidOrder=k;const Qe=y(!1),$=y(a),Lt=!!(Ze||ue&&ue.kind!=="processing"||Kt||Ot||Et||vt&&_?.orderNumber);h(()=>{Lt&&(Ye([]),ft())},[Lt,Ye,ft]);const Tt=y(!1);h(()=>{f||Tt.current||!a.some(un)||(Tt.current=!0,Cr({lines:a,currency:P.currency,value:P.subtotal-P.discount,coupon:K?.valid?K.code:void 0}))},[a,P,K,f]),h(()=>{pt(I,L.trim()||void 0)},[I,L,pt]);const _t=y(null),[Re,Vn]=s(null);h(()=>{const e=_t.current;if(!Re||!e)return;const t=()=>e.style.setProperty("--sf-checkout-header-h",`${Re.offsetHeight}px`);t();const r=new ResizeObserver(t);return r.observe(Re),()=>r.disconnect()},[Re]),h(()=>{const e=r=>({setConfirming:r,land:z,markPaid:()=>Ee(!0),note:(c,n)=>Yn({text:c,warning:n}),fail:N,clearCart:he,lostChange:()=>Xe(it)}),t={search:window.location.search,storage:st,scrubQuery:()=>window.history.replaceState(null,"",window.location.pathname)};$e(Ar,{...t,capture:w.captureAfterpayPayment,page:e(Gn)}),$e(Mr,{...t,capture:w.captureZipPayment,page:e(Jn)}),$e(Or,{...t,capture:w.completeGocardlessPayment,page:e(zn)}),$e(Rr,{...t,capture:w.captureKlarnaPayment,page:e(Zn)})},[]);function xt(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(Se){if((Se.country||m)!==m){D(null);return}De===m&&(Ne(Lr(m,Se.state,ae)),D(null))}},[Se,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;wt(t);const n=c.filter(p=>p.is_active);Pt(n),ke(t.email);const u=(r?.contact_name??"").split(/\s+/);Ce(t.first_name||u[0]||""),we(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)Ae(l.id),xt(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??""})}Ie.current&&Ht(Ie.current,!1)}catch{}})(),()=>{e=!0}},[]);function er(){me.logout(),le.current=!0,Ie.current=null,xe.current=null,de(),wt(null),Pt([]),Ae("new"),Nt(!1),ke(""),Ce(""),we(""),Ge(""),te(""),ne(""),re(""),oe(""),se(""),ce(mt||V[0]?.code||""),Ne(""),D(null)}const J=an(()=>hn(o,{canParkContext:ht}),[o,ht]);h(()=>{J.some(e=>e.key===C)||ge(J[0]?.key??null)},[J,C]);const tr=J.length===0,Ke=be.trim()?`${ee}
3
- ${be.trim()}`:ee,nr=zr({email:I,firstName:L,lastName:H,company:Pe.trim(),phone:G,address:Ke,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),Me=y(!1),x=y(!1),X=y(null),Le=y(!1),A=y(b);A.current=b;const It=y(M);It.current=M;const Te=y(null);h(()=>{const e=()=>{const t=Te.current;t&&(Te.current=null,S(t),He(!1))};return window.addEventListener("pageshow",e),()=>window.removeEventListener("pageshow",e)},[]);function _e(e,t,r,c){const n={idempotencyKey:t,confirmation:r};Xt()&&(n.lostChange=!0),st.setItem(e,JSON.stringify(n)),window.location.assign(c),Te.current=r}async function Ft(e){He(!0);try{await e()}finally{Te.current||He(!1)}}const qt=y(!1),$t=!!(Ze||ue&&ue.kind!=="processing");h(()=>{$t&&(qt.current=!0,de())},[$t]);const xe=y(null),le=y(!1),et=y(null);function de(){et.current=null,Tr()}const Ie=y(null),[Z,rr]=s(!1);function tt(e){if(qt.current||f||le.current)return;const t={key:e,authed:Qe.current,parkedAt:et.current??=Date.now(),press:wn(Qr,i.current),lines:a.length>0?a:$.current,form:Ir({email:I,firstName:L,lastName:H,company:Pe,address1:ee,address2:be,city:F,postcode:T,phone:G,country:m,subdivision:O,selectedAddressId:We,shippingMethodId:Q,couponCode:K?.valid?K.code:null})};_r(t.press)?xr(t):de()}const Bt=y(C);Bt.current=C;function nt(e){return{...Br(e),...Cn(),...e.payFirst?{checkoutFlow:ut}:{}}}function or(e,t){let r=e.request.payFirst?"":null,c=e.plainPressed?null:"";const n=()=>Bt.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),Ut=sr?!P.quoted||P.serverSubtotal===null?"waiting":Math.abs(P.serverSubtotal-P.subtotal)<Zr?"same":"changed":null,rt=!k&&Ut==="waiting",ar=rt?{...P,repricing:!0}:P,Yt=rt&&P.quoteFailed;h(()=>{if(!Yt)return;const e=setInterval(Ue,Xr);return()=>clearInterval(e)},[Yt,Ue]);function Ht(e,t=!0){ke(e.email),Ce(e.firstName),we(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}),Ae(e.selectedAddressId),e.shippingMethodId&&dt(e.shippingMethodId),t&&(xe.current=e.couponCode)}h(()=>{let e=f?null:qr();const t=!!(e&&a.length>0);if(e&&t&&!$r(e.lines,a)&&(de(),e=null),e){const r=e.authed?w.createOrderAuthed:w.createOrder;ve(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&&(Ie.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=xe.current;!Z||!e||a.length===0||(xe.current=null,Sn(e,I||void 0))},[Z,a.length]),h(()=>{!Z||M||tt(q)},[Z,M,q,k]);const B=y(null);h(()=>{It.current||(b!==B.current&&(B.current=null),!(!x.current||!k||k.orderNumber)&&(b===i.current.placedShape||b===B.current||Ft(()=>Gt(k))))},[b,k]);async function Gt(e){if(Le.current)return null;Le.current=!0;try{const t=X.current?await Gr(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||!Yr.has(t))return B.current=A.current,S(e),N(t==="requires_action"?Ur:at),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(at),null;x.current=!1,X.current=null,B.current=null,N(null),S(null);const c=qe();return ve(c),c}finally{Le.current=!1}}async function ir(){f||M||Le.current||await Ft(ur)}async function ur(){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),Me.current=!1,await ot();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&&ge(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=>br(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:Pe.trim()||void 0,address:Ke,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(),...Hr(C)?{checkoutFlow:ut}:{}};i.current.placedRequest={body:l,send:()=>d(l)},Qe.current=!!ie,le.current=!1,Xe(null),Ve.current=null,Me.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=""),lr(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&&ge(Y.method),r.orderNumber&&(Qt(r),he()),await ot()}catch(d){const l=Jr(d);l?(bn(l),N(`${l} Your order has not been placed. Place it again to continue without the code.`)):d instanceof Be?N(at):N(d instanceof Fe?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)} ${it}`),S(e)}function Wt(e,t){fn(e)&&!dn(e)&&i.current.lastPress?.key===t&&(i.current.lastPress=null)}async function lr(e,t,r){if(ct(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 Be;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 Be});return i.current.placedShape=n.shape,{answer:j,request:e,method:n.method}}const u={...e,checkoutFlow:ut},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 Be;return p?.orderNumber&&p.status!==Dr?(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 ot(),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]&&(Me.current=!0),Xe(Xt()?it:null)}function Xt(){return Me.current||pe()}async function Zt(e,t){const r={...e,idempotencyKey:qe()};i.current.keptCardKey=null,ve(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){wr({confirmation:e,lines:$.current,adsSendTo:o.googleAdsId&&o.googleAdsConversionLabel?`${o.googleAdsId}/${o.googleAdsConversionLabel}`:null}),Pr({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){Ee(!0),z(t);return}await Vt(t.checkoutNumber,r)}async function Vt(e,t){he(),await Wr({checkoutNumber:e,resend:t,page:{setConfirming:jn,land:z,markPaid:()=>Ee(!0),track:Qt,unplaced:Mt}})}function en(e=_){if(e){if(e.orderNumber){z(e);return}he(),Mt({kind:"processing",checkoutNumber:e.checkoutNumber})}}async function ot(){const e=JSON.stringify([Je.trim(),L,H,G.trim(),Ke,F,O,T,m]);if(!(!ie||!bt||We!=="new"||At.current===e))try{await me.createAddress({label:Je.trim()||"Home",contact_name:`${L} ${H}`.trim(),phone:G.trim(),address:Ke,city:F,zip_code:T,state:O,country:m}),At.current=e,St("Address saved to your account.")}catch{St("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),Oe(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`});_e(Sr,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`});_e(vr,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`});_e(Kr,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`});_e(Er,c,e,u.redirectUrl);return}else E(t),z(e)}catch(n){if((r||t==="card")&&n instanceof Fe&&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&&ct(t)?(x.current=!1,ve(qe())):S(e)}async function dr(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,Oe(r)}catch(r){if(r instanceof Fe&&r.status===409){await U();return}Oe(null),W(null),rn(t,r)}}function pr(){_&&(x.current=!0,S(_),Oe(null),W(null),je(!1))}return{site:o,logo:g,items:a,totals:ar,coupon:K,deliveryOptions:lt,courierUnavailable:Kn,retryCourier:Mn,shippingMethodId:Q,setShippingMethodId:dt,pickupLocation:An,servedCountries:V,formatMoney:vn,payChoice:C,setPayChoice:ge,placing:M,email:I,setEmail:ke,firstName:L,setFirstName:Ce,lastName:H,setLastName:we,company:Pe,setCompany:Ge,address1:ee,setAddress1:te,address2:be,setAddress2:ne,city:F,setCity:re,postcode:T,setPostcode:oe,phone:G,setPhone:se,country:m,setCountry:ce,subdivision:O,setSubdivision:Ne,subdivisions:ae,destination:kt,postcodeLabel:En,subdivisionLabel:Rn,me:ie,savedAddresses:Ln,selectedAddressId:We,setSelectedAddressId:Ae,saveAddress:bt,setSaveAddress:Nt,saveLabel:Je,setSaveLabel:Tn,addressSaveNote:_n,lostChangeNote:xn,idemKey:q,confirmation:Ze,setConfirmation:z,orderError:In,payment:vt,paypalStep:Ot,squareStep:Et,pendingConf:_,paid:$n,setPaid:Ee,unpaidOrder:k,orderLocked:Rt,formLocked:Bn,restoredPrices:Ut,payNote:Un,afterpayConfirming:Hn,gocardlessConfirming:Dn,zipConfirming:Wn,klarnaConfirming:Xn,cardConfirming:Kt,checkoutResult:ue,confirmCardPayment:U,cardStillProcessing:en,renewCardPayment:dr,holdRenewed:Qn,leaveCardPayment:pr,checkoutRootRef:_t,setCheckoutHeaderEl:Vn,fillFromAddress:xt,checkoutSignOut:er,payOptions:J,noPaymentMethod:tr,placeOrder:ir}}const Pn=fr(null);function bo({children:o,...g}){const f=Vr(g);return R(Pn.Provider,{value:f,children:o})}function No(){const o=mr(Pn);if(!o)throw new Error("useCheckout must be used inside CheckoutStateProvider");return o}export{bo as CheckoutStateProvider,Co as NO_PAYMENT_METHOD_NOTE,wo as SHIPPING_RETRY_NOTE,hn as buildPayOptions,gn as paymentNotStartedMessage,Po as placedOrderLockNote,No as useCheckout};
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};
@@ -2,6 +2,7 @@ import type { CartLine } from "../../components/CartContext.js";
2
2
  import type { OrderConfirmation, OrderRequest } from "../api/index.js";
3
3
  export declare const CHECKOUT_MEMORY_KEY = "checkout-memory-context";
4
4
  export declare const PRICES_REQUOTED = "Prices have changed since this checkout started. The total shows today's prices.";
5
+ export declare const PRICES_UNCHECKED = "We couldn't check today's prices for your basket. Try again in a moment \u2014 you can place the order once the total is confirmed.";
5
6
  export declare const CHECKOUT_MEMORY_LIFE_MS: number;
6
7
  export declare function parkLine(line: CartLine): CartLine;
7
8
  export declare function sameGoods(a: CartLine[], b: CartLine[]): boolean;
@@ -1 +1 @@
1
- import{safeSessionStorage as i}from"efficient-web-builder/format/lib/safe-storage";import{orderLinesForSets as g}from"../commerce.js";const c="checkout-memory-context",P="Prices have changed since this checkout started. The total shows today's prices.",d=3,k=3600*1e3;function N(e){return{id:e.id,slug:e.slug,name:{lead:e.name?.lead,accent:e.name?.accent},process:e.process,positionNo:e.positionNo,config:(e.config??[]).map(t=>({label:t.label,gold:t.gold})),finishName:e.finishName,size:e.size,qty:e.qty,href:e.href,kind:e.kind,sku:e.sku,components:e.components.map(t=>({partNumber:t.partNumber,wheels:t.wheels,prices:{...t.prices},hand:t.hand}))}}const a=e=>e.map(N);function I(e,t){const n=o=>JSON.stringify(o.map(r=>[r.id,r.qty]).sort(([r],[u])=>r<u?-1:r>u?1:0));return n(e)===n(t)}function l(e){const t=e.customer;return{customer:{email:t.email,name:t.name,phone:t.phone,companyName:t.companyName,address:t.address,city:t.city,state:t.state,zipCode:t.zipCode,country:t.country},items:e.items.flatMap(n=>g([{partNumber:n.partNumber,wheels:n.quantity,prices:{}}],1)),currency:e.currency,idempotencyKey:e.idempotencyKey,shippingMethodId:e.shippingMethodId,couponCode:e.couponCode}}function K(e){return{...l(e),payFirst:!!e.checkoutFlow}}function L(e){return l(e)}const A={lastPress:null,keptCardKey:null,placedShape:null,placedRequest:null,unpaidOrder:null};function b(e){const t=n=>typeof n=="string"?n:"";return{email:t(e.email),firstName:t(e.firstName),lastName:t(e.lastName),company:t(e.company),address1:t(e.address1),address2:t(e.address2),city:t(e.city),postcode:t(e.postcode),phone:t(e.phone),country:t(e.country),subdivision:t(e.subdivision),selectedAddressId:t(e.selectedAddressId),shippingMethodId:typeof e.shippingMethodId=="string"?e.shippingMethodId:null,couponCode:typeof e.couponCode=="string"?e.couponCode:null}}function C(e){return{orderNumber:e.orderNumber,checkoutNumber:e.checkoutNumber,expiresAt:e.expiresAt,status:e.status,total:e.total,currency:e.currency,freightCharge:e.freightCharge,discountAmount:e.discountAmount,grandTotal:e.grandTotal,shippingMethod:e.shippingMethod,couponCode:e.couponCode}}function x(e){return e.lastPress!==null||e.unpaidOrder!==null||e.keptCardKey!==null}function M(e){const t=e.parkedAt+k,n=e.press.unpaidOrder,o=n&&!n.orderNumber?n.expiresAt:null,r=o?Date.parse(o):NaN;return Number.isNaN(r)?t:Math.min(t,r)}function _(e){try{const t={...e,lines:a(e.lines),press:f(e.press)};i.setItem(c,JSON.stringify({v:d,...t}))}catch{}}const s=e=>!!e&&typeof e=="object"&&!Array.isArray(e),y=e=>s(e)&&typeof e.idempotencyKey=="string"&&Array.isArray(e.items)&&e.items.every(t=>s(t)&&typeof t.partNumber=="string"&&typeof t.quantity=="number")&&s(e.customer)&&typeof e.payFirst=="boolean",p=e=>s(e)&&typeof e.id=="string"&&typeof e.qty=="number"&&Array.isArray(e.components);function O(e){return s(e)&&typeof e.key=="string"&&y(e.request)&&Array.isArray(e.lines)&&e.lines.every(p)&&Array.isArray(e.plainLines)&&e.plainLines.every(p)?{key:e.key,request:e.request,lines:a(e.lines),goods:typeof e.goods=="string"?e.goods:"",plainPressed:e.plainPressed===!0,plainLines:a(e.plainLines),plainGoods:typeof e.plainGoods=="string"?e.plainGoods:""}:null}const m=e=>typeof e=="string"?e:null,h={lastPress:O,keptCardKey:m,placedShape:m,placedRequest:e=>y(e)?e:null,unpaidOrder:e=>s(e)?C(e):null};function f(e){const t=s(e)?e:{},n={...A};for(const o of Object.keys(h))n[o]=h[o](t[o]);return n}function q(){let e;try{e=i.getItem(c)}catch{return null}if(!e)return null;try{const t=JSON.parse(e);if(t.v!==d||typeof t.key!="string"||!t.key||!Array.isArray(t.lines)||!t.lines.every(p)||typeof t.parkedAt!="number")return null;const n={key:t.key,authed:t.authed===!0,parkedAt:t.parkedAt,press:f(t.press),lines:a(t.lines),form:t.form&&typeof t.form=="object"?b(t.form):null};return Date.now()>=M(n)?(S(),null):x(n.press)?n:null}catch{return null}}function S(){try{i.removeItem(c)}catch{}}export{c as CHECKOUT_MEMORY_KEY,k as CHECKOUT_MEMORY_LIFE_MS,A as NO_PRESS,h as PARKED_PRESS_READERS,P as PRICES_REQUOTED,S as clearCheckoutMemory,x as holdsPress,_ as parkCheckoutMemory,b as parkForm,N as parkLine,C as parkOrder,K as parkRequest,q as readCheckoutMemory,I as sameGoods,L as sendableRequest};
1
+ import{safeSessionStorage as i}from"efficient-web-builder/format/lib/safe-storage";import{orderLinesForSets as g}from"../commerce.js";const c="checkout-memory-context",P="Prices have changed since this checkout started. The total shows today's prices.",I="We couldn't check today's prices for your basket. Try again in a moment — you can place the order once the total is confirmed.",d=3,k=3600*1e3;function N(e){return{id:e.id,slug:e.slug,name:{lead:e.name?.lead,accent:e.name?.accent},process:e.process,positionNo:e.positionNo,config:(e.config??[]).map(t=>({label:t.label,gold:t.gold})),finishName:e.finishName,size:e.size,qty:e.qty,href:e.href,kind:e.kind,sku:e.sku,components:e.components.map(t=>({partNumber:t.partNumber,wheels:t.wheels,prices:{...t.prices},hand:t.hand}))}}const a=e=>e.map(N);function K(e,t){const n=o=>JSON.stringify(o.map(r=>[r.id,r.qty]).sort(([r],[u])=>r<u?-1:r>u?1:0));return n(e)===n(t)}function l(e){const t=e.customer;return{customer:{email:t.email,name:t.name,phone:t.phone,companyName:t.companyName,address:t.address,city:t.city,state:t.state,zipCode:t.zipCode,country:t.country},items:e.items.flatMap(n=>g([{partNumber:n.partNumber,wheels:n.quantity,prices:{}}],1)),currency:e.currency,idempotencyKey:e.idempotencyKey,shippingMethodId:e.shippingMethodId,couponCode:e.couponCode}}function _(e){return{...l(e),payFirst:!!e.checkoutFlow}}function L(e){return l(e)}const b={lastPress:null,keptCardKey:null,placedShape:null,placedRequest:null,unpaidOrder:null};function A(e){const t=n=>typeof n=="string"?n:"";return{email:t(e.email),firstName:t(e.firstName),lastName:t(e.lastName),company:t(e.company),address1:t(e.address1),address2:t(e.address2),city:t(e.city),postcode:t(e.postcode),phone:t(e.phone),country:t(e.country),subdivision:t(e.subdivision),selectedAddressId:t(e.selectedAddressId),shippingMethodId:typeof e.shippingMethodId=="string"?e.shippingMethodId:null,couponCode:typeof e.couponCode=="string"?e.couponCode:null}}function C(e){return{orderNumber:e.orderNumber,checkoutNumber:e.checkoutNumber,expiresAt:e.expiresAt,status:e.status,total:e.total,currency:e.currency,freightCharge:e.freightCharge,discountAmount:e.discountAmount,grandTotal:e.grandTotal,shippingMethod:e.shippingMethod,couponCode:e.couponCode}}function x(e){return e.lastPress!==null||e.unpaidOrder!==null||e.keptCardKey!==null}function E(e){const t=e.parkedAt+k,n=e.press.unpaidOrder,o=n&&!n.orderNumber?n.expiresAt:null,r=o?Date.parse(o):NaN;return Number.isNaN(r)?t:Math.min(t,r)}function q(e){try{const t={...e,lines:a(e.lines),press:f(e.press)};i.setItem(c,JSON.stringify({v:d,...t}))}catch{}}const s=e=>!!e&&typeof e=="object"&&!Array.isArray(e),y=e=>s(e)&&typeof e.idempotencyKey=="string"&&Array.isArray(e.items)&&e.items.every(t=>s(t)&&typeof t.partNumber=="string"&&typeof t.quantity=="number")&&s(e.customer)&&typeof e.payFirst=="boolean",p=e=>s(e)&&typeof e.id=="string"&&typeof e.qty=="number"&&Array.isArray(e.components);function S(e){return s(e)&&typeof e.key=="string"&&y(e.request)&&Array.isArray(e.lines)&&e.lines.every(p)&&Array.isArray(e.plainLines)&&e.plainLines.every(p)?{key:e.key,request:e.request,lines:a(e.lines),goods:typeof e.goods=="string"?e.goods:"",plainPressed:e.plainPressed===!0,plainLines:a(e.plainLines),plainGoods:typeof e.plainGoods=="string"?e.plainGoods:""}:null}const m=e=>typeof e=="string"?e:null,h={lastPress:S,keptCardKey:m,placedShape:m,placedRequest:e=>y(e)?e:null,unpaidOrder:e=>s(e)?C(e):null};function f(e){const t=s(e)?e:{},n={...b};for(const o of Object.keys(h))n[o]=h[o](t[o]);return n}function w(){let e;try{e=i.getItem(c)}catch{return null}if(!e)return null;try{const t=JSON.parse(e);if(t.v!==d||typeof t.key!="string"||!t.key||!Array.isArray(t.lines)||!t.lines.every(p)||typeof t.parkedAt!="number")return null;const n={key:t.key,authed:t.authed===!0,parkedAt:t.parkedAt,press:f(t.press),lines:a(t.lines),form:t.form&&typeof t.form=="object"?A(t.form):null};return Date.now()>=E(n)?(M(),null):x(n.press)?n:null}catch{return null}}function M(){try{i.removeItem(c)}catch{}}export{c as CHECKOUT_MEMORY_KEY,k as CHECKOUT_MEMORY_LIFE_MS,b as NO_PRESS,h as PARKED_PRESS_READERS,P as PRICES_REQUOTED,I as PRICES_UNCHECKED,M as clearCheckoutMemory,x as holdsPress,q as parkCheckoutMemory,A as parkForm,N as parkLine,C as parkOrder,_ as parkRequest,w as readCheckoutMemory,K as sameGoods,L as sendableRequest};
@@ -1 +1 @@
1
- import{jsx as r}from"react/jsx-runtime";import{SITE_WIDTH_CAP as g}from"efficient-web-builder/format/lib/content/page-width";import{resolveWidth as R}from"efficient-web-builder/format/lib/content/section-width";import A from"../../../../../components/LinkedProductHero.js";import l from"../../../../../components/pdp-dynamic/DynamicProductHero.js";import y from"../../../../../components/SectionNotice.js";import{trustBulletsRow as F,trustBulletsSlot as w}from"../../../../../components/product-hero/trust-bullets.js";import{TRUST_BULLETS_SLOT as D}from"../../../../sections/hero-trust-bullets.js";import{HERO_OPTION_SLOT as m}from"../../../../content/hero-option-seed.js";import{HERO_BUY_SLOT as u}from"../../../../content/hero-buy-seed.js";import{cardPressTitlesOf as I}from"efficient-web-builder/render/lib/document/card-press-titles";import{useCurrentProduct as S}from"../../../current-product.js";import{isEditorOnDynamicPage as U}from"efficient-web-builder/format/lib/document/editor-page-context";import{DEFAULT_HERO_PRICE_PLACEMENT as B,parseHeroPricePlacement as M}from"../../../../sections/hero-price-placement.js";import{DEFAULT_HERO_LAYOUT as k,DEFAULT_HERO_RATIO as p,DEFAULT_HERO_TEXT_ALIGN as x,parseHeroLayout as C,parseHeroRatio as G,parseHeroTextAlign as N}from"../../../../sections/hero-arrangement.js";import{DEFAULT_HERO_GALLERY_MODE as b,DEFAULT_HERO_IMAGE_FIT as V,parseHeroGalleryMode as Y,parseHeroImageFit as j}from"../../../../sections/hero-gallery.js";import{say as v}from"efficient-web-builder/format/lib/editor-words";import{ProductHeroMeta as Q}from"./meta.js";import{HideTaker as W}from"efficient-web-builder/render/components/ViewHideRoot";function z({source:e,editing:t=!1,pricePlacement:i=B,showVehicleFitment:o=!0,heroLayout:a=k,imageRatio:c=p,textAlign:f=x,showSpecTable:d=!0,showPriceQuote:T=!0,galleryMode:s=b,imageFit:E=V,trustBullets:_,nodeId:H,priceTemplate:P,optionTemplate:L,optionPressTitles:h,buyTemplate:O}){const n={heroLayout:a,imageRatio:c,textAlign:f,showSpecTable:d,showPriceQuote:T,galleryMode:s,imageFit:E,trustBullets:F(_,t),nodeId:H,priceTemplate:P,optionTemplate:L,optionPressTitles:h,buyTemplate:O};return S()||t&&U()?r(l,{editing:t,pricePlacement:i,showVehicleFitment:o,...n}):e?.slug?r(A,{slug:e.slug,kind:e.kind??"wheel",editing:t,pricePlacement:i,showVehicleFitment:o,...n}):t?r(y,{size:"tall",children:v("Pick a product in the panel to fill this hero.")}):r(l,{pricePlacement:i,showVehicleFitment:o,...n})}function X(e,t){return R(e,"full").mode!=="page"?t:r(W,{as:"div",style:{"--sf-content-cap":g},children:t})}const Ee={...Q,render:e=>X(e,r(z,{source:e.source,editing:e.editor?.isEditing,pricePlacement:M(e.pricePlacement),showVehicleFitment:e.showVehicleFitment??!0,heroLayout:C(e.heroLayout),imageRatio:G(e.imageRatio),textAlign:N(e.textAlign),showSpecTable:e.showSpecTable??!0,showPriceQuote:e.showPriceQuote??!0,galleryMode:Y(e.galleryMode),imageFit:j(e.imageFit),trustBullets:w(e[D]),nodeId:typeof e.id=="string"?e.id:void 0,priceTemplate:typeof e.template=="function"?e.template:void 0,optionTemplate:typeof e[m]=="function"?e[m]:void 0,optionPressTitles:I(e,m),buyTemplate:typeof e[u]=="function"?e[u]:void 0}))};export{Ee as ProductHeroRender};
1
+ import{jsx as r}from"react/jsx-runtime";import{SITE_WIDTH_CAP as A}from"efficient-web-builder/format/lib/content/page-width";import{resolveWidth as y}from"efficient-web-builder/format/lib/content/section-width";import F from"../../../../../components/LinkedProductHero.js";import a from"../../../../../components/pdp-dynamic/DynamicProductHero.js";import D from"../../../../../components/SectionNotice.js";import{trustBulletsRow as I,trustBulletsSlot as w}from"../../../../../components/product-hero/trust-bullets.js";import{TRUST_BULLETS_SLOT as S}from"../../../../sections/hero-trust-bullets.js";import{HERO_OPTION_SLOT as m}from"../../../../content/hero-option-seed.js";import{HERO_BUY_SLOT as u}from"../../../../content/hero-buy-seed.js";import{cardPressTitlesOf as U}from"efficient-web-builder/render/lib/document/card-press-titles";import{useCurrentProduct as k}from"../../../current-product.js";import{LINKED_HERO_RECORD_PROP as B,matchingLinkedRecord as C}from"../../../linked-hero-hydrate.js";import{isEditorOnDynamicPage as M}from"efficient-web-builder/format/lib/document/editor-page-context";import{DEFAULT_HERO_PRICE_PLACEMENT as x,parseHeroPricePlacement as p}from"../../../../sections/hero-price-placement.js";import{DEFAULT_HERO_LAYOUT as N,DEFAULT_HERO_RATIO as G,DEFAULT_HERO_TEXT_ALIGN as b,parseHeroLayout as V,parseHeroRatio as Y,parseHeroTextAlign as j}from"../../../../sections/hero-arrangement.js";import{DEFAULT_HERO_GALLERY_MODE as v,DEFAULT_HERO_IMAGE_FIT as Q,parseHeroGalleryMode as W,parseHeroImageFit as z}from"../../../../sections/hero-gallery.js";import{say as K}from"efficient-web-builder/format/lib/editor-words";import{ProductHeroMeta as X}from"./meta.js";import{HideTaker as q}from"efficient-web-builder/render/components/ViewHideRoot";function J({source:e,editing:t=!1,pricePlacement:i=x,showVehicleFitment:o=!0,heroLayout:c=N,imageRatio:d=G,textAlign:f=b,showSpecTable:T=!0,showPriceQuote:E=!0,galleryMode:_=v,imageFit:s=Q,trustBullets:R,nodeId:P,priceTemplate:H,optionTemplate:L,optionPressTitles:O,buyTemplate:h,linkedRecord:g}){const n={heroLayout:c,imageRatio:d,textAlign:f,showSpecTable:T,showPriceQuote:E,galleryMode:_,imageFit:s,trustBullets:I(R,t),nodeId:P,priceTemplate:H,optionTemplate:L,optionPressTitles:O,buyTemplate:h};if(k()||t&&M())return r(a,{editing:t,pricePlacement:i,showVehicleFitment:o,...n});if(e?.slug){const l=e.kind??"wheel";return r(F,{slug:e.slug,kind:l,initialRecord:C(g,l,e.slug),editing:t,pricePlacement:i,showVehicleFitment:o,...n})}return t?r(D,{size:"tall",children:K("Pick a product in the panel to fill this hero.")}):r(a,{pricePlacement:i,showVehicleFitment:o,...n})}function Z(e,t){return y(e,"full").mode!=="page"?t:r(q,{as:"div",style:{"--sf-content-cap":A},children:t})}const Le={...X,render:e=>Z(e,r(J,{source:e.source,editing:e.editor?.isEditing,pricePlacement:p(e.pricePlacement),showVehicleFitment:e.showVehicleFitment??!0,heroLayout:V(e.heroLayout),imageRatio:Y(e.imageRatio),textAlign:j(e.textAlign),showSpecTable:e.showSpecTable??!0,showPriceQuote:e.showPriceQuote??!0,galleryMode:W(e.galleryMode),imageFit:z(e.imageFit),trustBullets:w(e[S]),nodeId:typeof e.id=="string"?e.id:void 0,priceTemplate:typeof e.template=="function"?e.template:void 0,optionTemplate:typeof e[m]=="function"?e[m]:void 0,optionPressTitles:U(e,m),buyTemplate:typeof e[u]=="function"?e[u]:void 0,linkedRecord:e[B]}))};export{Le as ProductHeroRender};
@@ -0,0 +1,8 @@
1
+ import type { Data } from "efficient-easel/blocks";
2
+ import type { Tyre, Wheel } from "../api/index.js";
3
+ import { type LinkedHeroRecord } from "./linked-hero-hydrate.js";
4
+ export interface LinkedHeroReads {
5
+ getWheel(slug: string): Promise<Wheel>;
6
+ getTyre(slug: string): Promise<Tyre>;
7
+ }
8
+ export declare function fetchLinkedHeroRecords(data: Data | null | undefined, reads: LinkedHeroReads): Promise<LinkedHeroRecord[]>;
@@ -0,0 +1 @@
1
+ import{linkedHeroSources as o}from"./linked-hero-hydrate.js";async function a(n,r){return(await Promise.allSettled(o(n).map(({kind:e,slug:l})=>e==="tyre"?r.getTyre(l).then(t=>({kind:"tyre",tyre:t})):r.getWheel(l).then(t=>({kind:"wheel",wheel:t}))))).flatMap(e=>e.status==="fulfilled"?[e.value]:[])}export{a as fetchLinkedHeroRecords};
@@ -0,0 +1,25 @@
1
+ import type { Data } from "efficient-easel/blocks";
2
+ import type { Tyre, Wheel } from "../api/index.js";
3
+ export type LinkedHeroRecord = {
4
+ kind: "wheel";
5
+ wheel: Wheel;
6
+ } | {
7
+ kind: "tyre";
8
+ tyre: Tyre;
9
+ };
10
+ export interface LinkedHeroSource {
11
+ kind: "wheel" | "tyre";
12
+ slug: string;
13
+ }
14
+ export declare const LINKED_HERO_RECORD_PROP = "linkedRecord";
15
+ interface ContentNode {
16
+ type?: string;
17
+ props?: Record<string, unknown>;
18
+ }
19
+ export declare function matchingLinkedRecord(value: unknown, kind: "wheel" | "tyre", slug: string): LinkedHeroRecord | undefined;
20
+ export declare function linkedHeroSources(data: Data | null | undefined): LinkedHeroSource[];
21
+ export declare function pageHasLinkedHero(data: Data | null | undefined): boolean;
22
+ export declare function hydrateLinkedHeroes(data: Data, records: readonly LinkedHeroRecord[]): Data;
23
+ export declare function stripLinkedHeroRecord<T extends ContentNode>(node: T): T;
24
+ export declare function stripLinkedHeroRecords(data: Data): Data;
25
+ export {};
@@ -0,0 +1 @@
1
+ import{PRODUCT_HERO_TYPE as p,documentNodes as f,mapDocumentNodes as s}from"./document-nodes.js";const u="linkedRecord";function i(r){if(r?.type!==p)return null;const e=r.props?.source;return typeof e?.slug!="string"||!e.slug?null:{kind:e.kind==="tyre"?"tyre":"wheel",slug:e.slug}}function d(r,e,n){const t=r;if(!t||t.kind!==e)return;const o=e==="tyre"?t.tyre:t.wheel;return o&&typeof o=="object"&&o.slug===n?t:void 0}function l(r){const e=[];for(const n of f(r)){const t=i(n);t&&!e.some(o=>o.kind===t.kind&&o.slug===t.slug)&&e.push(t)}return e}function R(r){return l(r).length>0}function y(r,e){return e.length===0?r:s(r,n=>{const t=i(n);if(!t)return n;const o=e.find(c=>d(c,t.kind,t.slug));return o?{...n,props:{...n.props??{},[u]:o}}:n})}function g(r){if(!r?.props||!(u in r.props))return r;const{[u]:e,...n}=r.props;return{...r,props:n}}function H(r){return s(r,e=>g(e))}export{u as LINKED_HERO_RECORD_PROP,y as hydrateLinkedHeroes,l as linkedHeroSources,d as matchingLinkedRecord,R as pageHasLinkedHero,g as stripLinkedHeroRecord,H as stripLinkedHeroRecords};
@@ -1 +1 @@
1
- import{cardHoverOf as E}from"efficient-web-builder/format/lib/animation/hover";import{resolvePlpKinds as G}from"../catalog/plp-item.js";import{GRID_TOP_UP_SPARE as L,gridPagingOf as I}from"../sections/product-grid-pages.js";import{gridKindsOf as O,gridRowsOf as W,isAllProductsSource as v,isLinkedSource as C}from"./grid-source.js";import{ALLOY_WHEELS_LISTING_TYPE as u,FILTER_BLOCK_TYPE as T,PRODUCT_GRID_TYPE as R,documentNodes as N,mapDocumentNodes as U}from"../document/document-nodes.js";import{selectedRangesOf as D,stripSelectedRanges as g}from"./selected-ranges.js";import{withShopperFirstPaint as H,withoutShopperFirstPaint as B,withoutShopperFirstPaintNode as w}from"./shopper-first-paint.js";const h="catalog",F="catalogTotal",K="CatalogFilterBar",f="fieldUsage";function l(e){return e.props?.source}function p(e){return e?.type===R&&C(l(e))}function a(e){return e?.type===K||e?.type===T}function S(e,t){if(t)return;const{limit:r,cap:o}=I(e.props??{});return o?Math.ceil(r)+L:void 0}function m(e){return e?.type===u||p(e)||a(e)}const c=e=>N(e);function Y(e){return e?c(e).some(t=>t?.type===u||p(t)):!1}function te(e){return e?Y(e)||c(e).some(t=>w(t)!==t)||g(e)!==e:!1}function re(e){return e?c(e).some(m):!1}function ne(e,t){return t.length===0?e:x(e,m,r=>({...r,props:{...r.props??{},[f]:t}}))}function M(e){if(!e)return[];const t=new Set;for(const r of c(e)){if(r?.type!==u&&!p(r))continue;const o=r.props?.kinds;for(const n of p(r)?O(l(r),o):G(o))t.add(n)}return[...t]}function oe(e){if(!e)return;const t=c(e);if(t.some(a))return;const r=M(e).length;let o;for(const n of t){if(n?.type===u)return;if(!p(n))continue;const s=S(n,!1),i=n.props??{},d=new Set(O(l(n),i.kinds)),A=["num","title","description","linkText"].some(y=>typeof i[y]=="string"&&i[y]!=="");if(s===void 0||!v(l(n))||d.size!==r||A)return;o=Math.max(o??0,s)}return o}function se(e){return e.length===1&&e[0]==="alloy-wheel"}function ie(e,t,{everyHoverPhoto:r=!1}={}){const o=D(e.root?.props),n=c(e).some(a),s=r?z:b;return H(j(e,i=>p(i)?V(i,t,S(i,n),s):{...i,props:{...P(i).props,products:s(i,t)}}),o)}const z=(e,t)=>[...t];function b(e,t){const r=E(e.props??{},e.type??""),o=r.kind==="nextImage"&&r.media&&r.media.kind!=="renderings"?r.media.kind:null;return t.map(n=>{const{hoverMedia:s,...i}=n;return s===void 0?n:o&&s?.[o]?{...i,hoverMedia:{[o]:s[o]}}:i})}function V(e,t,r,o){const n=o(e,W(l(e),e.props?.kinds,t)),s={..._(e).props};return r!==void 0&&n.length>r?(s[h]=n.slice(0,r),s[F]=n.length):s[h]=n,{...e,props:s}}function pe(e){return B(x(g(e),m,t=>a(t)?k(t):p(t)?_(t):P(t)))}function k(e){if(!e.props||!(f in e.props))return e;const{[f]:t,...r}=e.props;return{...e,props:r}}function _(e){const{[h]:t,[F]:r,[f]:o,...n}=e.props??{},s=n.source;if(s&&"wheels"in s){const{wheels:i,...d}=s;n.source=d}return{...e,props:n}}function ue(e){const t=g({content:[e]}).content[0],r=w(t);return p(r)?_(r):a(r)?k(r):r?.type===u?P(r):r}function P(e){const{wheels:t,products:r,[f]:o,...n}=e.props??{};return{...e,props:n}}function j(e,t){return x(e,r=>r?.type===u||p(r),t)}function x(e,t,r){return U(e,o=>t(o)?r(o):o)}export{K as CATALOG_FILTER_BAR_TYPE,f as FIELD_USAGE_PROP,T as FILTER_BLOCK_TYPE,h as GRID_CATALOG_PROP,F as GRID_CATALOG_TOTAL_PROP,L as GRID_TOP_UP_SPARE,R as PRODUCT_GRID_TYPE,pe as dehydrateWheelsListing,ue as dehydrateWheelsListingNode,ne as hydrateFieldUsage,ie as hydrateWheelsListing,oe as listingCatalogBound,M as listingCatalogKinds,se as listingWantsWheelsOnly,te as pageHasHydratedValues,Y as pageHasWheelsListing,re as pageReadsFieldUsage};
1
+ import{cardHoverOf as G}from"efficient-web-builder/format/lib/animation/hover";import{resolvePlpKinds as I}from"../catalog/plp-item.js";import{GRID_TOP_UP_SPARE as O,gridPagingOf as W}from"../sections/product-grid-pages.js";import{gridKindsOf as R,gridRowsOf as v,isAllProductsSource as C,isLinkedSource as H}from"./grid-source.js";import{ALLOY_WHEELS_LISTING_TYPE as u,FILTER_BLOCK_TYPE as T,PRODUCT_GRID_TYPE as w,documentNodes as N,mapDocumentNodes as U}from"../document/document-nodes.js";import{stripLinkedHeroRecords as g}from"../document/linked-hero-hydrate.js";import{selectedRangesOf as D,stripSelectedRanges as h}from"./selected-ranges.js";import{withShopperFirstPaint as B,withoutShopperFirstPaint as K,withoutShopperFirstPaintNode as k}from"./shopper-first-paint.js";const m="catalog",F="catalogTotal",Y="CatalogFilterBar",f="fieldUsage";function l(e){return e.props?.source}function p(e){return e?.type===w&&H(l(e))}function a(e){return e?.type===Y||e?.type===T}function S(e,r){if(r)return;const{limit:t,cap:o}=W(e.props??{});return o?Math.ceil(t)+O:void 0}function _(e){return e?.type===u||p(e)||a(e)}const c=e=>N(e);function M(e){return e?c(e).some(r=>r?.type===u||p(r)):!1}function ne(e){return e?M(e)||c(e).some(r=>k(r)!==r)||h(e)!==e||g(e)!==e:!1}function oe(e){return e?c(e).some(_):!1}function se(e,r){return r.length===0?e:y(e,_,t=>({...t,props:{...t.props??{},[f]:r}}))}function z(e){if(!e)return[];const r=new Set;for(const t of c(e)){if(t?.type!==u&&!p(t))continue;const o=t.props?.kinds;for(const n of p(t)?R(l(t),o):I(o))r.add(n)}return[...r]}function ie(e){if(!e)return;const r=c(e);if(r.some(a))return;const t=z(e).length;let o;for(const n of r){if(n?.type===u)return;if(!p(n))continue;const s=S(n,!1),i=n.props??{},d=new Set(R(l(n),i.kinds)),E=["num","title","description","linkText"].some(L=>typeof i[L]=="string"&&i[L]!=="");if(s===void 0||!C(l(n))||d.size!==t||E)return;o=Math.max(o??0,s)}return o}function pe(e){return e.length===1&&e[0]==="alloy-wheel"}function ue(e,r,{everyHoverPhoto:t=!1}={}){const o=D(e.root?.props),n=c(e).some(a),s=t?b:V;return B(q(e,i=>p(i)?j(i,r,S(i,n),s):{...i,props:{...x(i).props,products:s(i,r)}}),o)}const b=(e,r)=>[...r];function V(e,r){const t=G(e.props??{},e.type??""),o=t.kind==="nextImage"&&t.media&&t.media.kind!=="renderings"?t.media.kind:null;return r.map(n=>{const{hoverMedia:s,...i}=n;return s===void 0?n:o&&s?.[o]?{...i,hoverMedia:{[o]:s[o]}}:i})}function j(e,r,t,o){const n=o(e,v(l(e),e.props?.kinds,r)),s={...P(e).props};return t!==void 0&&n.length>t?(s[m]=n.slice(0,t),s[F]=n.length):s[m]=n,{...e,props:s}}function ce(e){return K(y(g(h(e)),_,r=>a(r)?A(r):p(r)?P(r):x(r)))}function A(e){if(!e.props||!(f in e.props))return e;const{[f]:r,...t}=e.props;return{...e,props:t}}function P(e){const{[m]:r,[F]:t,[f]:o,...n}=e.props??{},s=n.source;if(s&&"wheels"in s){const{wheels:i,...d}=s;n.source=d}return{...e,props:n}}function fe(e){const r=g(h({content:[e]})).content[0],t=k(r);return p(t)?P(t):a(t)?A(t):t?.type===u?x(t):t}function x(e){const{wheels:r,products:t,[f]:o,...n}=e.props??{};return{...e,props:n}}function q(e,r){return y(e,t=>t?.type===u||p(t),r)}function y(e,r,t){return U(e,o=>r(o)?t(o):o)}export{Y as CATALOG_FILTER_BAR_TYPE,f as FIELD_USAGE_PROP,T as FILTER_BLOCK_TYPE,m as GRID_CATALOG_PROP,F as GRID_CATALOG_TOTAL_PROP,O as GRID_TOP_UP_SPARE,w as PRODUCT_GRID_TYPE,ce as dehydrateWheelsListing,fe as dehydrateWheelsListingNode,se as hydrateFieldUsage,ue as hydrateWheelsListing,ie as listingCatalogBound,z as listingCatalogKinds,pe as listingWantsWheelsOnly,ne as pageHasHydratedValues,M as pageHasWheelsListing,oe as pageReadsFieldUsage};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "efficient-storefront-blocks",
3
- "version": "0.118.1",
3
+ "version": "0.118.3",
4
4
  "description": "The EFFICIENT storefront's website editor — the website builder assembled with the storefront's own sections — for an app that edits a storefront website inside its own page. Built from the efficient-storefront-blocks repository.",
5
5
  "license": "UNLICENSED",
6
6
  "author": "Efficient Pty Ltd",