1import{u as Y,c as K,r as l,s as C,j as e,L as O}from"./index-D9EFedw6.js";import{E as W}from"./events-Cx4EPfWW.js";import{f as X,a as Z}from"./social-proof-r2P3nUOD.js";function ae(){var q;const{regId:v=""}=Y();K();const[o,V]=l.useState(null),[S,E]=l.useState(null),[s,$]=l.useState(null),[B,L]=l.useState({}),[N,R]=l.useState([]),[p,_]=l.useState(null),[A,T]=l.useState({}),[x,z]=l.useState(null),[w,I]=l.useState({}),[f,Q]=l.useState(!1),[j,D]=l.useState(null),[b,J]=l.useState(!1),[y,U]=l.useState(null),[F,k]=l.useState(!1),[H,u]=l.useState(null);l.useEffect(()=>{v&&C.auth.getSession().then(({data:t})=>{if(!t.session){E("Please sign in first.");return}C.from("registrations").select("*, event:events(id, slug, event_date_start, extras_disabled)").eq("id",v).maybeSingle().then(({data:n,error:c})=>{if(c||!n){E("Registration not found.");return}V(n);const a=W[n.event.slug];$(a),document.documentElement.setAttribute("data-theme",(a==null?void 0:a.theme)??"gempen"),X(n.event.id).then(L),Z(n.event.id).then(R)})})},[v]);const g=l.useMemo(()=>{var n,c;if(!s)return{items:[],total:0};const t=[];
1p&&s.jersey&&t.push({label:`Jersey â ${p}`,price:s.jersey.price,quantity:1,type:"jersey",metadata:{size:p}});for(const[a,i]of Object.entries(A))if(i>0){const r=s.vouchers.find(m=>m.id===a);r&&t.push({label:r.label,price:r.price,quantity:i,type:"voucher"})}if(x&&s.camping){const a=s.camping.options.find(i=>i.id===x);a&&a.price>0&&t.push({label:`Camping â ${a.label}`,price:a.price,quantity:1,type:"camping",metadata:{camping_id:a.id}})}for(const[a,i]of Object.entries(w))if(i>0){const r=N.find(m=>m.id===a);r&&t.push({label:r.name,price:Number(r.price_chf),quantity:i,type:"voucher",metadata:{sku:r.sku,group_buy_item:r.id}})}if(f&&s.addon){const a=(n=s.addon.variants)==null?void 0:n.find(i=>i.id===j);t.push({label:s.addon.label+(a?` · ${a.label}`:""),price:s.addon.price,quantity:1,type:"addon",metadata:{addon_id:s.addon.id,variant:j??null}})}if(b&&s.addon){const a=(c=s.addon.variants)==null?void 0:c.find(i=>i.id===y);t.push({label:s.addon.label+" · +1 plate"+(a?` · ${a.label}`:""),price:s.addon.price,quantity:1,type:"addon",metadata:{addon_id:s.addon.id,variant:y??null,extra:!0}})}return{items:t,total:t.reduce((a,i)=>a+i.price*i.quantity,0)}},[p,A,w,N,s,f,j,b,y]);async function G(){var t,n,c,a,i;if(u(null),g.items.length===0){u("Add at least one item to your cart.");return}if(f&&((n=(t=s.addon)==null?void 0:t.variants)==null?void 0:n.length)>0&&!j){u("Pick a plate (meat or vegan) for your grill.");return}if(b&&((a=(c=s.addon)==null?void 0:c.variants)==null?void 0:a.length)>0&&!y){u("Pick a plate (meat or vegan) for the +1 grill.");return}k(!0);try{const{data:r,error:m}=await C.functions.invoke("extras-checkout",{body:{registration_id:v,cartItems:g.items}});if(m){const h=m==null?void 0:m.context;let d;if(h&&typeof h.json=="function")try{d=(i=await h.json())==null?void 0:i.error}catch{}const P=d??m.message??"Could not start checkout",M=/edge function|non-2xx|FunctionsHttpError|fetch|network|cors/i.test(P)?"Something went wrong on our side. Please try again. If it keeps failing, email [email protected] â we usually sort it within an hour.":P;u(M),k(!1);return}if(r!=null&&r.url){window.location.href=r.url;return}u("Checkout did not return a redirect URL â please try again."),k(!1)}catch(r){u(r.message||"Unexpected error"),k(!1)}}return S?e.jsx("div",{className:"min-h-screen grid place-items-center p-4",children:e.jsxs("div",{className:"gg-card max-w-md",children:[e.jsx("p",{className:"gg-hot",children:S}),e.jsx(O,{to:"/portal",className:"gg-btn inline-block mt-4",children:"Back to portal â"})]})}):!o||!s?e.jsx("div",{className:"min-h-screen grid place-items-center gg-muted",children:"Loadingâ¦"}):(o.event.slug.replace(/-\d{4}$/,""),e.jsxs("div",{className:"min-h-screen max-w-3xl mx-auto p-4 space-y-6",children:[e.jsxs("div",{children:[e.jsx(O,{to:"/portal",className:"text-xs gg-muted",children:"â Portal"}),e.jsx("h1",{className:"font-display text-3xl mt-1",children:"Add extras"}),e.jsxs("p",{className:"gg-muted text-sm",children:["Top up your registration for ",s.name,". Bib #",o.bib," · ",o.contest,"."]})]}),s.jersey&&e.jsxs("div",{className:"gg-card space-y-3",children:[e.jsxs("div",{className:"flex items-baseline justify-between",children:[e.jsx("h3",{className:"font-display text-xl",children:"Official jersey"}),e.jsx("div",{className:"text-right",children:e.jsxs("div",{className:"font-mono gg-accent text-lg",children:["CHF ",s.jersey.price]})})]}),s.jersey.image&&e.jsx("img",{src:s.jersey.image,alt:"jersey",className:"w-full object-contain bg-[var(--bg)] rounded",style:{maxHeight:240}}),s.jersey.description&&e.jsx("p",{className:"text-sm gg-muted whitespace-pre-line",children:s.jersey.description}),e.jsxs("div",{className:"flex gap-2 flex-wrap",children:[e.jsx("button",{onClick:()=>_(null),className:"gg-chip "+(p===null?"active":""),children:"No jersey"}),s.jersey.sizes.map(t=>{const n=B[t],c=n!==void 0&&n<=0,a=n!==void 0&&n>0&&n<=3;return e.jsxs("button",{onClick:()=>!c&&_(t),disabled:c,className:"gg-chip "+(p===t?"active":"")+(c?" opacity-40 cursor-not-allowed line-through":""),children:[t,a&&e.jsxs("span",{className:"ml-1 text-[10px] gg-hot",children:["· ",n," left"]})]},t)})]})]}),s.camping&&s.camping.options.some(t=>t.price>0)&&e.jsxs("div",{className:"gg-card space-y-3",children:[e.jsx("h3",{className:"font-display text-xl",children:s.camping.headline??"Camping"}),e.jsx("div",{className:"flex gap-2 flex-wrap",children:s.camping.options.filter(t=>t.price>0).map(t=>e.jsxs("button",{type:"button",onClick:()=>z(x===t.id?null:t.id),className:"gg-chip "+(x===t.id?"active":""),children:[t.label," · CHF ",t.price]},t.id))}),x&&(()=>{const t=s.camping.options.find(n=>n.id===x);return t!=null&&t.description?e.jsx("p",{className:"text-xs gg-muted",children:t.description}):null})()]}),s.addon&&(()=>{var i,r,m,h;const t=Number(s.addon.cutoffHoursBeforeEvent??0),n=(i=o==null?void 0:o.event)!=null&&i.event_date_start?new Date(o.event.event_date_start).getTime():null,c=n&&t>0?Date.now()>n-t*60*60*1e3:!1,a=Array.isArray((r=o==null?void 0:o.event)==null?void 0:r.extras_disabled)&&o.event.extras_disabled.includes(s.addon.id);return c||a?null:e.jsxs("div",{className:"gg-card space-y-3",children:[e.jsxs("div",{className:"flex items-baseline justify-between",children:[e.jsx("h3",{className:"font-display text-xl",children:s.addon.label.replace(/ â .*/,"")}),e.jsxs("div",{className:"font-mono gg-accent text-lg",children:["CHF ",s.addon.price]})]}),s.addon.note&&e.jsx("p",{className:"text-xs gg-muted",children:s.addon.note}),e.jsxs("label",{className:"flex items-center gap-2 text-sm cursor-pointer",children:[e.jsx("input",{type:"checkbox",checked:f,onChange:d=>Q(d.target.checked)}),e.jsx("span",{children:"Add for me"})]}),f&&((m=s.addon.variants)==null?void 0:m.length)>0&&e.jsx("div",{className:"flex gap-2 flex-wrap pl-6",children:s.addon.variants.map(d=>e.jsx("button",{type:"button",onClick:()=>D(d.id),className:"gg-chip "+(j===d.id?"active":""),children:d.label},d.id))}),e.jsxs("label",{className:"flex items-center gap-2 text-sm cursor-pointer pt-2 border-t",style:{borderColor:"color-mix(in srgb, var(--accent) 20%, transparent)"},children:[e.jsx("input",{type:"checkbox",checked:b,onChange:d=>J(d.target.checked)}),e.jsx("span",{children:"+1 plate for a friend (no separate ride)"})]}),b&&((h=s.addon.variants)==null?void 0:h.length)>0&&e.jsx("div",{className:"flex gap-2 flex-wrap pl-6",children:s.addon.variants.map(d=>e.jsx("button",{type:"button",onClick:()=>U(d.id),className:"gg-chip "+(y===d.id?"active":""),children:d.label},d.id))})]})})(),((q=s.vouchers)==null?void 0:q.length)>0&&e.jsxs("div",{className:"gg-card space-y-3",children:[e.jsx("h3",{className:"font-display text-xl",children:"Drink vouchers"}),s.vouchers.map(t=>e.jsxs("div",{className:"flex items-center justify-between gap-2",children:[e.jsxs("div",{children:[e.jsx("div",{className:"text-sm",children:t.label}),e.jsxs("div",{className:"text-xs gg-muted font-mono",children:["CHF ",t.price]})]}),e.jsx("input",{type:"number",min:0,max:10,className:"gg-input w-20",defaultValue:0,onChange:n=>T(c=>({...c,[t.id]:Number(n.target.value)}))})]},t.id))]}),N.length>0&&e.jsxs("div",{className:"gg-card space-y-3",children:[e.jsx("h3",{className:"font-display text-xl",children:"NeverSecond race nutrition"}),e.jsx("p",{className:"text-xs gg-muted",children:"Pre-order now, pickup at bib collection. â20% vs retail."}),N.map(t=>e.jsxs("label",{className:"flex items-start gap-3 p-2 rounded cursor-pointer border",style:{borderColor:"color-mix(in srgb, var(--accent) 20%, transparent)"},children:[e.jsx("input",{type:"checkbox",className:"mt-1",checked:(w[t.id]??0)>0,onChange:n=>I(c=>({...c,[t.id]:n.target.checked?1:0}))}),t.image_url&&e.jsx("img",{src:t.image_url,alt:"",className:"w-16 h-16 object-contain"}),e.jsxs("div",{className:"flex-1",children:[e.jsxs("div",{className:"flex items-baseline justify-between",children:[e.jsx("span",{className:"font-medium",children:t.name}),e.jsxs("span",{className:"font-mono gg-accent",children:["CHF ",Number(t.price_chf).toFixed(0)]})]}),e.jsx("p",{className:"text-xs gg-muted mt-1",children:t.description})]})]},t.id))]}),e.jsxs("div",{className:"gg-card sticky bottom-4 flex items-center justify-between gap-4",children:[e.jsxs("div",{children:[e.jsx("div",{className:"text-xs gg-muted uppercase tracking-wider",children:"Total"}),e.jsxs("div",{className:"font-mono gg-accent text-2xl",children:["CHF ",g.total.toFixed(2)]})]}),e.jsx("button",{onClick:G,disabled:F||g.items.length===0,className:"gg-btn",children:F?"Redirectingâ¦":g.items.length===0?"Pick something":`Pay CHF ${g.total.toFixed(2)}`})]}),H&&e.jsxs("div",{className:"rounded-md border p-3 text-sm leading-relaxed",style:{background:"color-mix(in srgb, var(--hot) 10%, transparent)",borderColor:"color-mix(in srgb, var(--hot) 50%, transparent)",color:"var(--text)"},role:"alert",children:[e.jsx("div",{className:"font-semibold mb-1",style:{color:"var(--hot)"},children:"Couldn't start your extras checkout"}),e.jsx("div",{children:H}),e.jsxs("div",{className:"text-xs gg-muted mt-2",children:["Your selections are still saved â just press the button again. Persistent issue? Email ",e.jsx("a",{href:"mailto:[email protected]",className:"underline",children:"[email protected]"}),"."]})]})]}))}export{ae as default};
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.