1import{Z as j,$ as n,as as w,ar as I,at as $,a0 as A,j as e,aA as R,aB as U,r as u,S as B,L as F}from"./index-D2G60a0R.js";import{u as T}from"./useServerFn-CXyRoyBF.js";import{P as O}from"./PageHeader-DBxsBmT_.js";import{u as Q}from"./useReveal-jna7npkA.js";import{u as Y,m as p}from"./cart-Bhx5c-GO.js";import{E as H,a as Z,g as D,b as K}from"./stripe-CxgnYDkk.js";import{T as W}from"./trash-2-DVf2GQzF.js";const g=j({first_name:n().trim().min(1).max(60),last_name:n().trim().min(1).max(60),email:n().trim().email().max(255),phone:n().trim().max(40).optional().or(w("")),country:n().trim().length(2),region:n().trim().min(1).max(60),address1:n().trim().min(1).max(160),address2:n().trim().max(160).optional().or(w("")),city:n().trim().min(1).max(80),zip:n().trim().min(3).max(20)}),G=j({productId:n().trim().min(1).max(64),variantId:I().int().positive(),quantity:I().int().min(1).max(20)}),k=$(G).min(1).max(20);j({items:k,address:g});j({items:k,address:g,returnUrl:n().url().max(500),environment:A(["sandbox","live"])});function J({clientSecret:i}){return e.jsx("div",{id:"checkout",className:"overflow-hidden bg-white border border-cocoa/15 shadow-card",children:e.jsx(H,{stripe:D(),options:{fetchClientSecret:async()=>i},children:e.jsx(Z,{})})})}const V={first_name:"",last_name:"",email:"",phone:"",country:"US",region:"",address1:"",address2:"",city:"",zip:""};function le(){const i=Q(),{items:o,setQuantity:y,remove:b,subtotalCents:m}=Y(),E=T(R),P=T(U),[s,_]=u.useState(V),[c,f]=u.useState(null),[C,d]=u.useState(null),[x,h]=u.useState(!1),[N,q]=u.useState(null),r=t=>a=>{_(M=>({...M,[t]:a.target.value})),f(null)},S=o.map(t=>({productId:t.productId,variantId:t.variantId,quantity:t.quantity}));async function z(){d(null);const t=g.safeParse(s);if(!t.success){d(t.error.issues[0]?.message??"Please complete the shipping address.");return}h(!0);const a=await E({data:{items:S,address:t.data}});if(h(!1),"error"in a&&a.error){d(a.error);return}"shippingCents"in a&&f(a.shippingCents)}async function L(){d(null);const t=g.safeParse(s);if(!t.success){d("Please complete the shipping address.");return}h(!0);const a=await P({data:{items:S,address:t.data,returnUrl:`${window.location.origin}/shop/return?session_id={CHECKOUT_SESSION_ID}`,environment:K()}});if(h(!1),a.error){d(a.error);return}q(a.clientSecret??null)}return e.jsx(B,{children:e.jsxs("div",{ref:i,children:[e.jsx(O,{eyebrow:"The Little Wild Shop",title:"Almost",script:"yours",subtitle:"Tell us where to send it and we'll calculate shipping before you pay.",band:"cream"}),e.jsx("section",{className:"band-linen",children:e.jsx("div",{className:"container-page py-14 lg:py-20",children:o.length?N?e.jsx("div",{className:"mx-auto max-w-3xl",children:e.jsx(J,{clientSecret:N})}):e.jsxs("div",{className:"grid gap-12 lg:grid-cols-[1.1fr_.9fr]",children:[e.jsxs("div",{"data-reveal":!0,children:[e.jsx("h2",{className:"font-display text-2xl text-cocoa-deep",children:"Shipping address"}),e.jsxs("div",{className:"mt-6 grid gap-4 sm:grid-cols-2",children:[e.jsx(l,{label:"First name",value:s.first_name,onChange:r("first_name"),autoComplete:"given-name"}),e.jsx(l,{label:"Last name",value:s.last_name,onChange:r("last_name"),autoComplete:"family-name"}),e.jsx(l,{label:"Email",type:"email",value:s.email,onChange:r("email"),autoComplete:"email"}),e.jsx(l,{label:"Phone (optional)",type:"tel",value:s.phone??"",onChange:r("phone"),autoComplete:"tel"}),e.jsx("div",{className:"sm:col-span-2",children:e.jsx(l,{label:"Address",value:s.address1,onChange:r("address1"),autoComplete:"address-line1"})}),e.jsx("div",{className:"sm:col-span-2",children:e.jsx(l,{label:"Apt, suite (optional)",value:s.address2??"",onChange:r("address2"),autoComplete:"address-line2"})}),e.jsx(l,{label:"City",value:s.city,onChange:r("city"),autoComplete:"address-level2"}),e.jsx(l,{label:"State / region",value:s.region,onChange:r("region"),autoComplete:"address-level1"}),e.jsx(l,{label:"ZIP / postal code",value:s.zip,onChange:r("zip"),autoComplete:"postal-code"}),e.jsx(l,{label:"Country code",value:s.country,onChange:r("country"),autoComplete:"country"})]}),e.jsx("button",{type:"button",className:"btn-secondary mt-6",onClick:z,disabled:x,children:x?"Checkingâ¦":"Calculate shipping"}),C&&e.jsx("p",{role:"alert",className:"mt-4 text-sm text-red-700",children:C})]}),e.jsxs("aside",{"data-reveal":!0,className:"bg-white/70 border border-cocoa/12 p-6 lg:p-8 h-fit",children:[e.jsx("h2",{className:"font-display text-2xl text-cocoa-deep",children:"Your order"}),e.jsx("ul",{className:"mt-6 divide-y divide-cocoa/10",children:o.map(t=>e.jsxs("li",{className:"flex gap-4 py-4",children:[t.image&&e.jsx("img",{src:t.image,alt:"",className:"size-16 object-cover"}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("p",{className:"font-display text-cocoa-deep leading-snug",children:t.title}),e.jsx("p",{className:"text-xs text-cocoa/60",children:t.variantTitle}),e.jsxs("div",{className:"mt-2 flex items-center gap-3",children:[e.jsx("input",{type:"number",min:1,max:20,value:t.quantity,"aria-label":`Quantity for ${t.title}`,onChange:a=>y(t.productId,t.variantId,Math.max(1,Math.min(20,Number(a.target.value)||1))),className:"w-16 border border-cocoa/25 bg-white px-2 py-1 text-sm"}),e.jsx("button",{type:"button",onClick:()=>b(t.productId,t.variantId),"aria-label":`Remove ${t.title}`,className:"text-cocoa/50 hover:text-red-700",children:e.jsx(W,{className:"size-4","aria-hidden":!0})})]})]}),e.jsx("p",{className:"text-cocoa",children:p(t.unitCents*t.quantity)})]},`${t.productId}-${t.variantId}`))}),e.jsxs("dl",{className:"mt-6 space-y-2 text-sm",children:[e.jsx(v,{label:"Subtotal",value:p(m)}),e.jsx(v,{label:"Shipping",value:c==null?"Calculated next":p(c)}),e.jsx(v,{label:"Tax",value:"Calculated at payment"}),e.jsxs("div",{className:"border-t border-cocoa/15 pt-3 flex justify-between font-display text-lg text-cocoa-deep",children:[e.jsx("dt",{children:"Total"}),e.jsx("dd",{children:c==null?p(m):p(m+c)})]})]}),e.jsx("button",{type:"button",className:"btn-primary mt-6 w-full justify-center",onClick:L,disabled:x||c==null,children:x?"One momentâ¦":"Continue to payment"}),c==null&&e.jsx("p",{className:"mt-3 text-xs text-cocoa/60",children:"Calculate shipping to continue."})]})]}):e.jsxs("div",{className:"py-16 text-center",children:[e.jsx("h2",{className:"font-display text-3xl text-cocoa-deep",children:"Your cart is empty"}
1),e.jsx(F,{to:"/shop",className:"btn-primary mt-8 inline-flex",children:"Browse the shop"})]})})})]})})}function l({label:i,value:o,onChange:y,type:b="text",autoComplete:m}){return e.jsxs("label",{className:"block",children:[e.jsx("span",{className:"text-[11px] uppercase tracking-[0.22em] text-sage-deep",children:i}),e.jsx("input",{type:b,value:o,onChange:y,autoComplete:m,className:"mt-2 w-full border border-cocoa/25 bg-white px-3 py-2 text-cocoa focus:outline-none focus:border-cocoa"})]})}function v({label:i,value:o}){return e.jsxs("div",{className:"flex justify-between text-cocoa/80",children:[e.jsx("dt",{children:i}),e.jsx("dd",{children:o})]})}export{le as component};
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.