1import{j as e}from"./ui-wHuRdSZa.js";import{i as je,j as ye,r as a,L as we}from"./vendor-DF7Vsqu4.js";import{a5 as re,aq as q,C,d as S,as as Ne,at as ke,au as ve,B as R,x as _e,ap as ae,av as D,aw as B,e as oe,a4 as Ce,U as Se,ax as $e,$ as ie,K as Te,bs as Pe}from"./index-DIDqu_8B.js";import{I as Z}from"./input-xAyDpLjP.js";import{L as M}from"./label-CmZbH-a6.js";import{T as Re}from"./textarea-D6KwOzMA.js";import{D as Le}from"./DietarySelect-DhRONx9t.js";import{A as Ie,a as Ae,b as qe}from"./alert-CG6WgwOe.js";import{S as z}from"./separator-DhUOoaLj.js";import{P as De}from"./PaymentStep-BfkLtvay.js";import{C as K}from"./circle-alert-eMuiKcM9.js";import{L as A}from"./loader-circle-5BmXH3wq.js";import{L as Q}from"./lock-BvMxunKS.js";import{D as le}from"./download-DTr3GcXr.js";import{W as ee}from"./wallet-sqdHngI8.js";import{H as Be}from"./handshake-EMumdZDn.js";import{C as G}from"./circle-check-CaqY3AFc.js";import{E as Me}from"./external-link-CrhNktlr.js";import"./charts-BAVYBguD.js";import"./query-DKV4sgHL.js";import"./supabase-Cgbt6YLr.js";import"./motion-Clpufeat.js";import"./select-DJ5rNCZ_.js";import"./chevron-up-CKkK2w9o.js";/** 2 * @license lucide-react v0.462.0 - ISC 3 * 4 * This source code is licensed under the ISC license. 5 * See the LICENSE file in the root directory of this source tree. 6 */const Ue=re("Baby",[["path",{d:"M9 12h.01",key:"157uk2"}],["path",{d:"M15 12h.01",key:"1k8ypt"}],["path",{d:"M10 16c.5.3 1.2.5 2 .5s1.5-.2 2-.5",key:"1u7htd"}],["path",{d:"M19 6.3a9 9 0 0 1 1.8 3.9 2 2 0 0 1 0 3.6 9 9 0 0 1-17.6 0 2 2 0 0 1 0-3.6A9 9 0 0 1 12 3c2 0 3.5 1.1 3.5 2.5s-.9 2.5-2 2.5c-.8 0-1.5-.4-1.5-1",key:"5yv0yz"}]]);/** 7 * @license lucide-react v0.462.0 - ISC 8 * 9 * This source code is licensed under the ISC license. 10 * See the LICENSE file in the root directory of this source tree. 11 */const Ee=re("Printer",[["path",{d:"M6 18H4a2 2 0 0 1-2-2v-5a2 2 0 0 1 2-2h16a2 2 0 0 1 2 2v5a2 2 0 0 1-2 2h-2",key:"143wyd"}],["path",{d:"M6 9V3a1 1 0 0 1 1-1h10a1 1 0 0 1 1 1v6",key:"1itne7"}],["rect",{x:"6",y:"14",width:"12",height:"8",rx:"1",key:"1ue0tg"}]]),Fe=new URL("/functions/v1","https://btaoeyoaepbtgwlsgjfa.supabase.co").toString(),se="eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZSIsInJlZiI6ImJ0YW9leW9hZXBidGd3bHNnamZhIiwicm9sZSI6ImFub24iLCJpYXQiOjE3NzI5OTY5NjMsImV4cCI6MjA4ODU3Mjk2M30.IVc381eAW_eifLZyu1RpLRcF1euJGfei4_7n_MXftLY";async function F(s,n){const t=await fetch(`${Fe}/${s}`,{method:"POST",headers:{"Content-Type":"application/json",apikey:se,Authorization:`Bearer ${se}`},body:JSON.stringify(n)}),r=await t.json().catch(()=>({}));if(!t.ok)throw new Error(r?.error||`Request failed (${t.status})`);return r}function ce(s,n,t=1500){const[r,c]=a.useState("idle"),b=a.useRef(!0),i=a.useRef(null),u=a.useRef(!1),f=a.useRef(!1),N=a.useRef(n);a.useEffect(()=>{N.current=n});const m=a.useCallback(async()=>{if(u.current){f.current=!0;return}u.current=!0,c("saving");try{if(await N.current(),f.current){f.current=!1,u.current=!1,await m();return}c("idle")}catch(y){c("error"),q.error(y?.message||"Couldn't save changes")}finally{u.current=!1}},[]),k=a.useMemo(()=>JSON.stringify(s),[s]);a.useEffect(()=>{if(b.current){b.current=!1;return}return c(y=>y==="saving"?y:"dirty"),i.current&&window.clearTimeout(i.current),i.current=window.setTimeout(()=>{m()},t),()=>{i.current&&window.clearTimeout(i.current)}},[k,t,m]);const h=a.useCallback(async()=>{if(i.current&&(window.clearTimeout(i.current),i.current=null),u.current||f.current)for(;u.current;)await new Promise(y=>setTimeout(y,50));else(r==="dirty"||r==="error")&&await m()},[m,r]);return{status:r,flush:h,runNow:m}}function w(s){return`R ${Math.round(s/100).toLocaleString("en-ZA")}`}function de(s){return s?new Date(s).toLocaleDateString("en-ZA",{weekday:"long",day:"numeric",month:"long",year:"numeric",timeZone:"Africa/Johannesburg"}):"TBC"}function me(s){return s?new Date(s).toLocaleTimeString("en-ZA",{hour:"numeric",minute:"2-digit",hour12:!0,timeZone:"Africa/Johannesburg"}):""}function J({children:s}){return e.jsxs("div",{className:"min-h-screen overflow-x-hidden bg-cream font-body",children:[e.jsx("header",{className:"bg-primary text-primary-foreground border-b-2 border-gold",children:e.jsxs("div",{className:"mx-auto flex min-w-0 max-w-5xl items-center justify-between gap-3 px-4 py-2 sm:py-3 lg:py-4",children:[e.jsx(we,{to:"/",className:"flex min-w-0 items-center gap-3",children:e.jsx("img",{src:Te,alt:"Cape Town Culinary Tours",className:"h-7 sm:h-9 lg:h-10"})}),e.jsx("p",{className:"hidden text-[10px] font-semibold uppercase tracking-[0.28em] text-gold sm:block",children:"Booking portal"})]})}),e.jsx("main",{className:"pb-8 sm:pb-12",children:s})]})}function O({children:s}){return e.jsx("div",{className:"mx-auto min-w-0 max-w-5xl space-y-6 px-4 pt-6 sm:pt-8",children:s})}function E({icon:s,title:n,children:t}){return e.jsx(J,{children:e.jsx(O,{children:e.jsx(C,{children:e.jsxs(S,{className:"flex min-w-0 flex-col items-center gap-4 px-4 py-10 text-center sm:px-8 sm:py-16",children:[s,e.jsx("h1",{className:"max-w-full break-words text-xl font-semibold sm:text-2xl",children:n}),e.jsx("div",{className:"w-full max-w-md break-words px-2 text-muted-foreground",children:t})]})})})})}function ys(){je();const[s]=ye(),n=s.get("t")||s.get("token"),t=s.get("payment_intent")||s.get("paid"),[r,c]=a.useState(null),[b,i]=a.useState(!0),[u,f]=a.useState(!!t),[N,m]=a.useState(null),k=a.useRef(!1),h=async(o=!1)=>
11{if(!n)return m("missing_token"),i(!1),null;try{const x=await F("booking-portal-load",{token:n,logOpen:o});return c(x),m(null),x}catch(x){return m(x?.message||"load_failed"),null}finally{i(!1)}};if(a.useEffect(()=>{const o=!k.current;k.current=!0,h(o)},[n]),a.useEffect(()=>{if(!t||!n)return;q.success("Payment received â thank you!");let o=!1,x=0;const T=15,l=async()=>{if(o)return;x+=1;const d=await h(!1);if(!o){if(d&&d.mode==="manage"&&d.totals.balanceCents===0){f(!1);try{const j=d.booking?.products||{};Ne({bookingRef:d.booking.booking_ref,tourName:j.name||"",tourSlug:j.slug||"",value:Math.round((d.totals.ticketTotalCents+d.totals.transferTotalCents-d.totals.discountsTotalCents)/100),adults:d.booking.adults||0,children:d.booking.children||0,transferValue:Math.round(d.totals.transferTotalCents/100),promoCode:d.discounts?.[0]?.promo_codes?.code||null,paymentId:s.get("payment_intent")})}catch{}const p=new URL(window.location.href);p.searchParams.delete("payment_intent"),p.searchParams.delete("payment_intent_client_secret"),p.searchParams.delete("redirect_status"),p.searchParams.delete("paid"),window.history.replaceState({},"",p.toString());return}if(x>=T){f(!1);return}setTimeout(l,2e3)}};return l(),()=>{o=!0}},[t,n]),!n)return e.jsx(E,{icon:e.jsx(K,{className:"h-12 w-12 text-amber-500"}),title:"Link is missing a token",children:"This booking link is incomplete. Please use the link from your email, or contact us at [email protected]."});if(b)return e.jsx(E,{icon:e.jsx(A,{className:"h-10 w-10 animate-spin text-primary"}),title:"Loading your bookingâ¦",children:"One moment while we prepare your booking details."});if(u)return e.jsx(E,{icon:e.jsx(A,{className:"h-10 w-10 animate-spin text-primary"}),title:"Finalising your paymentâ¦",children:"Just a moment â we're confirming your payment with the bank."});if(N==="invalid_token"||N==="load_failed")return e.jsx(E,{icon:e.jsx(K,{className:"h-12 w-12 text-destructive"}),title:"Booking not found",children:"This link is no longer valid. If you believe this is an error, please reply to your booking email."});if(!r)return null;const y=(r.payments||[]).filter(o=>["paid","confirmed","succeeded","complete","completed"].includes(o.status)),$=r.mode==="manage"&&r.booking.status!=="cancelled"&&r.totals.balanceCents===0&&y.length>0;return r.mode==="payment_due"?e.jsx(Ge,{data:r,onReload:()=>{h(!1)}}):$?e.jsx(Ye,{data:r}):e.jsx(Je,{data:r,onReload:()=>{h(!1)}})}function Y({data:s,mode:n}){const t=s.booking.products,r=Pe(t?.slug||"",t?.hero_image_url);return e.jsxs("section",{className:"relative w-full overflow-hidden border-b-2 border-gold shadow-[0_30px_60px_-30px_rgba(0,0,0,0.35)]",children:[e.jsx("div",{className:"absolute inset-0",children:e.jsx("img",{src:r,alt:t?.name||"Tour",className:"h-full w-full scale-105 object-cover transition-transform duration-[8000ms] ease-out"})}),e.jsx("div",{className:"absolute inset-0 bg-gradient-to-t from-primary via-primary/75 to-primary/20"}),e.jsx("div",{className:"absolute inset-0 bg-gradient-to-r from-primary/85 via-primary/40 to-transparent"}),e.jsx("div",{"aria-hidden":!0,className:"pointer-events-none absolute -left-24 bottom-0 h-96 w-96 rounded-full bg-gold/25 blur-3xl"}),e.jsxs("div",{"aria-hidden":!0,className:"pointer-events-none absolute right-8 top-8 hidden gap-2 lg:flex",children:[e.jsx("span",{className:"h-24 w-px bg-gold/60"}),e.jsx("span",{className:"h-16 w-px bg-gold/40"}),e.jsx("span",{className:"h-10 w-px bg-gold/25"})]}),e.jsxs("div",{className:"relative mx-auto flex min-h-0 max-w-5xl flex-col justify-end px-4 py-5 text-primary-foreground sm:min-h-[16rem] sm:py-8 lg:min-h-[25rem] lg:pb-14 lg:pt-28",children:[e.jsxs("div",{className:"mb-3 flex min-w-0 max-w-full flex-wrap items-center gap-1.5 sm:mb-6 sm:gap-2",children:[e.jsxs("span",{className:"rounded-full border border-gold/40 bg-white/10 px-2 py-0.5 text-[9px] font-semibold uppercase tracking-[0.16em] backdrop-blur-md sm:px-3 sm:py-1 sm:text-[11px] sm:tracking-[0.2em]",children:["Booking ",s.booking.booking_ref]}),n==="payment_due"?e.jsxs("span",{className:"rounded-full bg-gold px-2 py-0.5 text-[9px] font-semibold uppercase tracking-[0.14em] text-primary shadow-md shadow-gold/30 sm:px-3 sm:py-1 sm:text-[11px] sm:tracking-[0.16em]",children:["Balance due ",w(s.totals.balanceCents)]}):e.jsxs("span",{className:"inline-flex items-center gap-1 rounded-full bg-teal-light px-2 py-0.5 text-[9px] font-semibold uppercase tracking-[0.14em] text-primary sm:px-3 sm:py-1 sm:text-[11px] sm:tracking-[0.16em]",children:[e.jsx(G,{className:"h-3 w-3 sm:h-3.5 sm:w-3.5"})," Paid in full"]}),s.booking.is_private&&e.jsx("span",{className:"rounded-full border border-gold/60 bg-transparent px-2 py-0.5 text-[9px] font-semibold uppercase tracking-[0.14em] text-gold backdrop-blur-sm sm:px-3 sm:py-1 sm:text-[11px] sm:tracking-[0.16em]",children:"Private tour"})]}),e.jsxs("div",{className:"mb-2 flex items-center gap-2 sm:mb-3 sm:gap-3",children:[e.jsx("span",{"aria-hidden":!0,
11className:"h-px w-6 bg-gold sm:w-16"}),e.jsx("p",{className:"text-[9px] font-semibold uppercase tracking-[0.22em] text-gold sm:text-[11px] sm:tracking-[0.32em]",children:n==="payment_due"?"Your booking":"You're all set"})]}),e.jsx("h1",{className:"font-display text-3xl font-normal leading-[0.95] break-words sm:text-5xl sm:leading-[0.9] md:text-6xl lg:text-8xl",children:n==="payment_due"?e.jsxs(e.Fragment,{children:["Review & ",e.jsx("span",{className:"text-gold",children:"complete"})," your booking"]}):e.jsxs(e.Fragment,{children:["See you ",e.jsx("span",{className:"text-gold",children:"soon"})]})}),e.jsx("p",{className:"mt-2 font-heading text-base italic text-primary-foreground/95 sm:mt-4 sm:text-2xl md:text-4xl",children:t?.name||"Your tour"})]})]})}function U(s){return[...s].sort((n,t)=>{if(n.is_lead_guest&&!t.is_lead_guest)return-1;if(!n.is_lead_guest&&t.is_lead_guest)return 1;const r=n.ticket_category==="infant"?1:0,c=t.ticket_category==="infant"?1:0;return r-c})}function ue(s){return s.ticket_category==="infant"?"Infant":s.ticket_option_name?s.ticket_option_name:"Guest"}function te(s,n){if(!s)return"";const t=s.split(";")[0]?.split(",")[0]?.trim().toLowerCase();return t&&n.find(c=>c.name.toLowerCase()===t)?.id||""}function xe({guests:s,setGuests:n,dietaryOptions:t,specialRequests:r,setSpecialRequests:c,onSave:b,saving:i,saveLabel:u="Save details",title:f="Tell us about your guests",subtitle:N,autosaveStatus:m}){const[k,h]=a.useState(()=>Object.fromEntries(s.map(l=>[l.id,te(l.dietary_requirements,t)]))),[y,$]=a.useState(()=>Object.fromEntries(s.map(l=>{const d=t.find(v=>v.id===te(l.dietary_requirements,t))?.name,p=l.dietary_requirements||"",j=d&&p.toLowerCase().startsWith(d.toLowerCase())?p.slice(d.length).replace(/^[,;\s]+/,""):d?"":p;return[l.id,j]}))),o=(l,d,p)=>{const _=[t.find(L=>L.id===d)?.name,p].filter(Boolean).join(", ");n(L=>L.map(I=>I.id===l?{...I,dietary_requirements:_||null}:I))},x=(l,d)=>{h(p=>({...p,[l]:d})),o(l,d,y[l]||"")},T=(l,d)=>{$(p=>({...p,[l]:d})),o(l,k[l]||"",d)};return e.jsxs(C,{className:"border-gold/30 shadow-sm",children:[e.jsxs(D,{children:[e.jsx("p",{className:"mb-1 text-[10px] font-semibold uppercase tracking-[0.28em] text-gold",children:"Guest information"}),e.jsx(B,{className:"font-display text-2xl font-normal sm:text-3xl md:text-4xl",children:f}),N&&e.jsx("p",{className:"text-sm text-muted-foreground",children:N})]}),e.jsxs(S,{className:"space-y-4",children:[s.map((l,d)=>{const p=l.ticket_category==="infant";return e.jsxs("div",{className:"relative rounded-xl border-2 border-gold bg-card p-4 pt-5 space-y-3",children:[e.jsxs("div",{className:"absolute -top-2.5 left-3 flex max-w-[calc(100%-1.5rem)] flex-wrap items-center gap-1.5 bg-background px-2 text-[10px] font-semibold uppercase tracking-wider text-muted-foreground",children:[p&&e.jsx(Ue,{className:"h-3 w-3"}),e.jsxs("span",{children:["Guest ",d+1," · ",ue(l),l.is_lead_guest?" · Lead":""]})]}),e.jsxs("div",{className:"grid gap-3 sm:grid-cols-2",children:[e.jsxs("div",{children:[e.jsx(M,{className:"text-xs",children:"First name"}),e.jsx(Z,{value:l.first_name||"",onChange:j=>n(v=>v.map(_=>_.id===l.id?{..._,first_name:j.target.value}:_))})]}),e.jsxs("div",{children:[e.jsx(M,{className:"text-xs",children:"Last name"}),e.jsx(Z,{value:l.last_name||"",onChange:j=>n(v=>v.map(_=>_.id===l.id?{..._,last_name:j.target.value}:_))})]})]}),!p&&e.jsxs("div",{className:"grid gap-3 sm:grid-cols-2",children:[t.length>0&&e.jsxs("div",{children:[e.jsx(M,{className:"text-xs",children:"Dietary requirements"}),e.jsx(Le,{className:"mt-1",options:t,value:k[l.id]||"",onChange:j=>x(l.id,j)})]}),e.jsxs("div",{children:[e.jsx(M,{className:"text-xs",children:"Allergies or notes for this guest"}),e.jsx(Z,{className:"mt-1",placeholder:"Any additional notes",value:y[l.id]||"",onChange:j=>T(l.id,j.target.value),maxLength:500})]})]})]},l.id)}),e.jsxs("div",{children:[e.jsx(M,{children:"Special requests"}),e.jsx(Re,{rows:3,value:r,onChange:l=>c(l.target.value),placeholder:"Anything else we should know?"})]}),e.jsx("div",{className:"flex justify-center",children:m&&e.jsxs("button",{type:"button",onClick:m==="error"?b:void 0,disabled:m!=="error",className:`inline-flex items-center gap-1.5 text-xs ${m==="error"?"cursor-pointer text-destructive hover:underline":"cursor-default text-muted-foreground"}`,children:[m==="saving"&&e.jsx(A,{className:"h-3 w-3 animate-spin"}),m==="idle"&&e.jsx(G,{className:"h-3 w-3 text-teal"}),m==="idle"&&"All changes saved automatically",m==="dirty"&&"Saving shortlyâ¦",m==="saving"&&"Savingâ¦",m==="error"&&"Couldn't save â click to retry"]})})]})]})}function Ge({data:s,onReload:n}){const[t,r]=a.useState(()=>U(s.guests)),[c,b]=a.useState(s.booking.special_requests||""),[i,u]=a.useState(!1),[f,N]=a.useState(null),[m,k]=a.useState(!1),[h,y]=a.useState(null),[$,o]=a.use
11State(!1),x=a.useRef(null),T=a.useRef(null),l=a.useRef(null),d=a.useRef([]),p=m||!!f,j=a.useCallback(()=>{d.current.forEach(g=>window.clearTimeout(g)),d.current=[]},[]),v=a.useCallback((g="smooth")=>{const X=T.current||l.current;if(!X)return;const ge=Math.max(0,X.getBoundingClientRect().top+window.scrollY-16),be=window.matchMedia("(prefers-reduced-motion: reduce)").matches;window.scrollTo({top:ge,behavior:be?"auto":g})},[]),_=a.useCallback((g="smooth")=>{j(),v(g),requestAnimationFrame(()=>v(g)),d.current=[window.setTimeout(()=>v(g),80),window.setTimeout(()=>v("auto"),220),window.setTimeout(()=>v("auto"),520),window.setTimeout(()=>v("auto"),900)]},[j,v]);a.useEffect(()=>j,[j]),a.useLayoutEffect(()=>{if(!p)return;const g=requestAnimationFrame(()=>_(f?"auto":"smooth"));return()=>cancelAnimationFrame(g)},[f,p,_]),a.useEffect(()=>{r(U(s.guests))},[s.guests]);const L=a.useCallback(async()=>{await F("booking-portal-update",{token:s.token,special_requests:c,guests:t.map(g=>({id:g.id,first_name:g.first_name,last_name:g.last_name,dietary_requirements:g.dietary_requirements}))})},[s.token,c,t]),I=ce({specialRequests:c,guests:t},L),pe=async()=>{u(!0);try{await L(),q.success("Details saved"),n()}catch(g){q.error(g?.message||"Failed to save")}finally{u(!1)}},he=async()=>{k(!0),y(null),_();try{await I.flush(),await L();const g=await F("booking-portal-create-intent",{token:s.token});N(g.clientSecret)}catch(g){y(g?.message||"Could not start payment")}finally{k(!1)}},fe=a.useMemo(()=>typeof window>"u"?"":`${ke.isNativePlatform()?ve:window.location.origin}/booking/${encodeURIComponent(s.booking.booking_ref)}?t=${encodeURIComponent(s.token)}&paid=1`,[s.booking.booking_ref,s.token]);return e.jsxs(J,{children:[e.jsx(Y,{data:s,mode:"payment_due"}),e.jsxs(O,{children:[e.jsx(W,{data:s}),e.jsx(H,{data:s}),e.jsx(V,{data:s}),e.jsx(xe,{guests:t,setGuests:r,dietaryOptions:s.dietaryOptions||[],specialRequests:c,setSpecialRequests:b,onSave:pe,saving:i,autosaveStatus:I.status,title:"Tell us about your guests",subtitle:"Confirm names and dietary needs so we can prep the perfect tasting."}),e.jsx("div",{ref:T,"aria-hidden":!0,className:"scroll-mt-0"}),e.jsx(C,{ref:l,className:`border-gold/30 border-t-4 border-t-gold shadow-sm scroll-mt-0 ${p?"min-h-[100svh]":""}`,children:e.jsxs(S,{className:"space-y-4 pt-6",children:[h&&e.jsxs(Ie,{variant:"destructive",children:[e.jsx(Ae,{children:"Payment unavailable"}),e.jsx(qe,{children:h})]}),f?e.jsxs(e.Fragment,{children:[e.jsxs("div",{children:[e.jsx("p",{className:"mb-1 text-[10px] font-semibold uppercase tracking-[0.28em] text-gold",children:"Payment"}),e.jsxs("h3",{className:"font-display text-2xl font-normal sm:text-3xl md:text-4xl",children:["Pay balance ",w(s.totals.balanceCents)]}),e.jsxs("p",{className:"mt-1 inline-flex flex-wrap items-center gap-1.5 text-xs text-muted-foreground",children:[e.jsx(Q,{className:"h-3 w-3"})," Secured by Stripe · your card is never stored on our servers"]})]}),e.jsx(De,{ref:x,clientSecret:f,bookingRef:s.booking.booking_ref,amountCents:s.totals.balanceCents,returnUrl:fe,onProcessingChange:o,onReady:()=>_("auto"),compact:!0}),e.jsxs(R,{size:"lg",className:"w-full rounded-full bg-gold text-white hover:bg-gold-light hover:text-white",disabled:$,onClick:()=>x.current?.submit(),children:[$?e.jsx(A,{className:"mr-2 h-4 w-4 animate-spin"}):null,"Pay ",w(s.totals.balanceCents),e.jsx(ae,{className:"ml-1 h-4 w-4"})]})]}):e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex flex-col gap-6 sm:flex-row sm:items-center sm:justify-between",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:"mb-1 text-[10px] font-semibold uppercase tracking-[0.28em] text-gold",children:"Payment"}),e.jsxs("h3",{className:"font-display text-2xl font-normal sm:text-3xl md:text-4xl",children:["Pay balance ",w(s.totals.balanceCents)]}),e.jsxs("p",{className:"mt-1 inline-flex flex-wrap items-center gap-1.5 text-xs text-muted-foreground",children:[e.jsx(Q,{className:"h-3 w-3"})," Secured by Stripe · your card is never stored on our servers"]})]}),e.jsxs(R,{type:"button",size:"lg",onClick:he,disabled:m,className:"w-full shrink-0 rounded-full bg-gold px-8 text-white hover:bg-gold-light hover:text-white sm:w-auto",children:[m?e.jsx(A,{className:"mr-2 h-4 w-4 animate-spin"}):null,"Continue to secure payment",e.jsx(_e,{className:"ml-1 h-4 w-4"})]})]}),m&&e.jsxs("div",{className:"flex min-h-[26rem] flex-col items-center justify-center rounded-lg border border-dashed border-gold/50 bg-cream/70 px-4 text-center",children:[e.jsx(A,{className:"mb-3 h-8 w-8 animate-spin text-gold"}),e.jsx("p",{className:"font-heading text-xl italic text-primary",children:"Preparing secure payment formâ¦"}),e.jsx("p",{className:"mt-1 text-sm text-muted-foreground",children:"This will appear here in a moment."})]})]})]})}),e.jsx("p",{className:"text-center text-xs text-muted-foreground",children:"Sold by Taste of Africa Travel LLC for Cape Town Culinary Tours Pty Ltd. All rights reserved."}
11),p?e.jsx("div",{"aria-hidden":!0,className:"h-[100svh]"}):null]})]})}function Je({data:s,onReload:n}){const[t,r]=a.useState(()=>U(s.guests)),[c,b]=a.useState(s.booking.special_requests||""),[i,u]=a.useState(!1);a.useEffect(()=>{r(U(s.guests))},[s.guests]);const f=a.useCallback(async()=>{await F("booking-portal-update",{token:s.token,special_requests:c,guests:t.map(h=>({id:h.id,first_name:h.first_name,last_name:h.last_name,dietary_requirements:h.dietary_requirements}))})},[s.token,c,t]),N=ce({specialRequests:c,guests:t},f),m=async()=>{u(!0);try{await f(),q.success("Updated"),n()}catch(h){q.error(h?.message||"Failed to save")}finally{u(!1)}},k=`https://btaoeyoaepbtgwlsgjfa.supabase.co/functions/v1/generate-booking-pdf?ref=${encodeURIComponent(s.booking.booking_ref)}&token=${encodeURIComponent(s.token)}`;return e.jsxs(J,{children:[e.jsx(Y,{data:s,mode:"manage"}),e.jsxs(O,{children:[e.jsx(W,{data:s}),e.jsx(H,{data:s}),e.jsxs(C,{className:"border-gold/30 shadow-sm",children:[e.jsxs(D,{children:[e.jsx("p",{className:"mb-1 text-[10px] font-semibold uppercase tracking-[0.28em] text-gold",children:"Tickets"}),e.jsx(B,{className:"font-display text-2xl font-normal sm:text-3xl md:text-4xl",children:"Your tickets"})]}),e.jsxs(S,{className:"space-y-2",children:[e.jsx(R,{asChild:!0,className:"w-full rounded-full bg-gold px-6 text-primary hover:bg-gold-light sm:w-auto",children:e.jsxs("a",{href:k,target:"_blank",rel:"noreferrer",children:[e.jsx(le,{className:"mr-2 h-4 w-4"})," Download tickets (PDF)"]})}),e.jsxs("p",{className:"text-xs text-muted-foreground",children:[s.tickets.length," ticket",s.tickets.length===1?"":"s"," on this booking."]})]})]}),e.jsx(V,{data:s}),e.jsx(xe,{guests:t,setGuests:r,dietaryOptions:s.dietaryOptions||[],specialRequests:c,setSpecialRequests:b,onSave:m,saving:i,autosaveStatus:N.status,saveLabel:"Save changes",title:"Guest details & requests",subtitle:"Update any details before your tour."})]})]})}function Oe(s){return s.place_id?`https://www.google.com/maps/search/?api=1&query=${s.lat!=null&&s.lng!=null?`${s.lat},${s.lng}`:encodeURIComponent(`${s.name}, ${s.address}`)}&query_place_id=${encodeURIComponent(s.place_id)}`:s.lat!=null&&s.lng!=null?`https://www.google.com/maps/search/?api=1&query=${s.lat},${s.lng}`:`https://www.google.com/maps/search/?api=1&query=${encodeURIComponent(`${s.name}, ${s.address}`)}`}function ne({mp:s,label:n,showMap:t=!0}){const r=Oe(s),c=void 0,i=s.lat!=null&&s.lng!=null&&c?`https://maps.googleapis.com/maps/api/staticmap?center=${s.lat},${s.lng}&zoom=15&size=800x360&scale=2&markers=color:0xB78D3C%7C${s.lat},${s.lng}&key=${c}`:null;return e.jsxs("div",{className:"space-y-4",children:[e.jsx("p",{className:"text-[10px] font-semibold uppercase tracking-[0.22em] text-gold",children:n}),e.jsx("div",{children:e.jsxs("div",{className:"flex items-start gap-2",children:[e.jsx(ie,{className:"mt-0.5 h-4 w-4 shrink-0 text-gold"}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("div",{className:"font-semibold text-foreground",children:s.name}),e.jsxs("div",{className:"text-sm text-muted-foreground",children:[s.address,s.city?`, ${s.city}`:""]}),s.notes&&e.jsx("div",{className:"mt-2 rounded-md border border-border/60 bg-muted/40 p-2 text-xs text-muted-foreground",children:s.notes}),n==="Start"&&e.jsxs("p",{className:"mt-2 text-xs text-muted-foreground",children:[e.jsx(oe,{className:"mr-1 inline h-3 w-3"})," Please arrive 10 minutes before your tour begins."]})]})]})}),t&&i?e.jsxs("a",{href:r,target:"_blank",rel:"noreferrer",className:"group relative block overflow-hidden rounded-lg border border-gold/40 shadow-sm",children:[e.jsx("img",{src:i,alt:`Map showing ${s.name}`,className:"h-auto w-full",loading:"lazy"}),e.jsx("div",{className:"pointer-events-none absolute inset-0 bg-primary/0 transition-colors group-hover:bg-primary/10"})]}):null,e.jsx(R,{asChild:!0,variant:"outline",className:"w-full rounded-full border-gold/60 sm:w-auto print:hidden",children:e.jsxs("a",{href:r,target:"_blank",rel:"noreferrer",children:[e.jsx(Me,{className:"mr-2 h-4 w-4"})," Open in Google Maps"]})})]})}function Ze({meetingPoint:s,endMeetingPoint:n}){return!s&&!n?null:e.jsxs(C,{className:"border-gold/30 shadow-sm print:break-inside-avoid",children:[e.jsxs(D,{children:[e.jsx("p",{className:"mb-1 text-[10px] font-semibold uppercase tracking-[0.28em] text-gold",children:"Meeting point"}),e.jsx(B,{className:"font-display text-2xl font-normal sm:text-3xl md:text-4xl",children:"Where to meet us"})]}),e.jsxs(S,{className:"space-y-6",children:[s?e.jsx(ne,{mp:s,label:"Start"}):null,s&&n?e.jsx(z,{className:"bg-gold/20"}):null,n?e.jsx(ne,{mp:n,label:"End"}):null]})]})}function ze({data:s}){const t=(s.payments||[]).filter(r=>["paid","confirmed","succeeded","complete","completed"].includes(r.status)).map(r=>
11r.paid_at).filter(Boolean).sort().slice(-1)[0];return e.jsx(C,{className:"border-0 bg-success text-success-foreground shadow-md print:hidden",children:e.jsxs(S,{className:"flex items-center gap-4 p-5 sm:p-6",children:[e.jsx("div",{className:"flex h-12 w-12 shrink-0 items-center justify-center rounded-full bg-white/20 sm:h-14 sm:w-14",children:e.jsx(G,{className:"h-7 w-7 text-white sm:h-8 sm:w-8"})}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("h2",{className:"font-display text-2xl font-normal leading-tight sm:text-3xl",children:"Paid in full"}),e.jsxs("p",{className:"mt-0.5 text-sm text-success-foreground/90",children:["Booking ",s.booking.booking_ref,t?` · Payment received on ${new Date(t).toLocaleDateString("en-ZA",{day:"numeric",month:"long",year:"numeric"})}`:""]})]})]})})}function Ye({data:s}){const n=s.booking.products,t=s.booking.departures,r=U(s.guests),c=`https://btaoeyoaepbtgwlsgjfa.supabase.co/functions/v1/generate-booking-pdf?ref=${encodeURIComponent(s.booking.booking_ref)}&token=${encodeURIComponent(s.token)}`,b=`https://btaoeyoaepbtgwlsgjfa.supabase.co/functions/v1/generate-wallet-pass?ref=${encodeURIComponent(s.booking.booking_ref)}`;return e.jsxs(J,{children:[e.jsx("style",{children:` 12 @media print { 13 header, nav, footer { display: none !important; } 14 .print\\:hidden { display: none !important; } 15 section.relative.w-full.overflow-hidden { display: none !important; } 16 body { background: white !important; } 17 } 18 `}),e.jsx(Y,{data:s,mode:"manage"}),e.jsxs(O,{children:[e.jsx(ze,{data:s}),e.jsx(W,{data:s}),e.jsx(H,{data:s}),e.jsx(Ze,{meetingPoint:s.meetingPoint,endMeetingPoint:s.endMeetingPoint}),e.jsxs(C,{className:"border-gold/30 shadow-sm print:break-inside-avoid",children:[e.jsxs(D,{children:[e.jsx("p",{className:"mb-1 text-[10px] font-semibold uppercase tracking-[0.28em] text-gold",children:"Your tickets"}),e.jsx(B,{className:"font-display text-2xl font-normal sm:text-3xl md:text-4xl",children:"Ticket details"})]}),e.jsxs(S,{className:"space-y-3",children:[e.jsxs("div",{className:"rounded-lg border border-border/60 bg-muted/30 p-3 text-sm",children:[e.jsx("div",{className:"font-semibold text-foreground",children:n?.name||"Tour"}),e.jsxs("div",{className:"text-xs text-muted-foreground",children:[de(t?.start_time),t?.start_time?` · ${me(t.start_time)}`:""]}),e.jsxs("div",{className:"mt-1 text-xs text-muted-foreground",children:["Booking reference: ",e.jsx("span",{className:"font-mono",children:s.booking.booking_ref})]})]}),e.jsx("div",{className:"space-y-1.5",children:r.map((i,u)=>e.jsx("div",{className:"flex flex-wrap items-center justify-between gap-2 rounded-md border border-border/60 px-3 py-2 text-sm print:break-inside-avoid",children:e.jsxs("div",{className:"min-w-0",children:[e.jsx("div",{className:"truncate font-medium text-foreground",children:i.first_name||i.last_name?`${i.first_name||""} ${i.last_name||""}`.trim():`Guest ${u+1}`}),e.jsxs("div",{className:"text-xs text-muted-foreground",children:[ue(i),i.is_lead_guest?" · Lead":"",i.dietary_requirements?` · ${i.dietary_requirements}`:""]})]})},i.id))}),e.jsxs("div",{className:"flex flex-wrap gap-2 pt-2 print:hidden",children:[e.jsx(R,{asChild:!0,className:"rounded-full bg-gold text-primary hover:bg-gold-light",children:e.jsxs("a",{href:c,target:"_blank",rel:"noreferrer",children:[e.jsx(le,{className:"mr-2 h-4 w-4"})," Download PDF"]})}),e.jsxs(R,{variant:"outline",className:"rounded-full border-gold/60",onClick:()=>window.print(),children:[e.jsx(Ee,{className:"mr-2 h-4 w-4"})," Print"]}),e.jsx(R,{asChild:!0,variant:"outline",className:"rounded-full border-gold/60",children:e.jsxs("a",{href:`${b}&type=apple`,target:"_blank",rel:"noreferrer",children:[e.jsx(ee,{className:"mr-2 h-4 w-4"})," Add to Apple Wallet"]})}),e.jsx(R,{asChild:!0,variant:"outline",className:"rounded-full border-gold/60",children:e.jsxs("a",{href:`${b}&type=google`,target:"_blank",rel:"noreferrer",children:[e.jsx(ee,{className:"mr-2 h-4 w-4"})," Add to Google Wallet"]})})]})]})]}),s.booking.special_requests?e.jsxs(C,{className:"border-gold/30 shadow-sm print:break-inside-avoid",children:[e.jsxs(D,{children:[e.jsx("p",{className:"mb-1 text-[10px] font-semibold uppercase tracking-[0.28em] text-gold",children:"Special requests"}),e.jsx(B,{className:"font-display text-2xl font-normal sm:text-3xl",children:"Notes for our team"})]}),e.jsxs(S,{children:[e.jsx("p",{className:"whitespace-pre-wrap text-sm text-muted-foreground",children:s.booking.special_requests}),e.jsxs("p",{className:"mt-3 text-xs text-muted-foreground print:hidden",children:["Need to update anything? Email ",e.jsx("a",{href:"mailto:[email protected]",className:"text-gold underline",children:"[email protected]"}),"."]})]})]}):null,e.jsx(V,{data:s})]})]})}function We(s){let n=0,t=0;for(const r of s)(r.product_options?.ticket_category||"guest")==="infant"?t+=1:n+=1;return{guestCount:n,infantCount:t}}function W({data:s}){const n=s.agencyContext;if(!n?.isAgencyBilled)return null;const t=n.agentFirstName?.trim()||"there",r=n.agencyName?.trim();return e.jsx(C,{className:"border-teal/30 border-l-4 border-l-teal bg-cream/60 shadow-sm",children:e.jsxs(S,{className:"flex flex-col gap-3 py-5 sm:flex-row sm:items-start sm:gap-4",children:[e.jsx("div",{className:"flex h-10 w-10 shrink-0 items-center justify-center rounded-full bg-teal/10 text-teal",children:e.jsx(Be,{className:"h-5 w-5"})}),e.jsxs("div",{className:"min-w-0 space-y-2",children:[e.jsxs("p",{className:"text-[10px] font-semibold uppercase tracking-[0.28em] text-teal",children:["Agency booking",r?` · ${r}`:""]}),e.jsxs("h3",{className:"font-heading text-2xl italic text-primary sm:text-3xl",children:["Dear ",t,","]}
18),e.jsx("p",{className:"text-sm leading-relaxed text-foreground/80 sm:text-base",children:"Please find the details of your client's booking below. Should any changes be required, don't hesitate to let us know â otherwise payment can be applied using the button at the bottom of the screen."}),e.jsxs("p",{className:"text-sm leading-relaxed text-foreground/80 sm:text-base",children:["Thank you for your support",t?`, ${t}`:"",". We look forward to taking wonderful care of your clients."]})]})]})})}function H({data:s}){const n=s.booking.departures,t=s.booking.products,{guestCount:r,infantCount:c}=We(s.tickets),b=[];r>0&&b.push(`${r} ${r===1?"Guest":"Guests"}`),c>0&&b.push(`${c} ${c===1?"Infant":"Infants"}`);const i=s.tickets.filter(o=>(o.product_options?.ticket_category||"guest")!=="infant"),u=s.tickets.filter(o=>(o.product_options?.ticket_category||"guest")==="infant"),f=i.reduce((o,x)=>o+(x.unit_price_cents??x.product_options?.price_cents??0),0),N=u.reduce((o,x)=>o+(x.unit_price_cents??x.product_options?.price_cents??0),0),m=i.length?Math.round(f/i.length):0,k=u.length?Math.round(N/u.length):0,h=i.length?i[0].product_options?.ticket_category:null,y=i.every(o=>(o.product_options?.ticket_category||"guest")===h),$=y&&h==="adult"?"Adult":y&&h==="child"?"Child":"Guest";return e.jsx(C,{className:"border-gold/30 shadow-sm",children:e.jsx(S,{className:"p-4 sm:p-6",children:e.jsxs("div",{className:"space-y-3 text-sm",children:[e.jsxs("div",{children:[e.jsx("p",{className:"mb-1 text-[10px] font-semibold uppercase tracking-[0.28em] text-gold",children:"Summary"}),e.jsx("h2",{className:"font-display text-2xl font-normal leading-tight text-foreground sm:text-3xl md:text-4xl",children:t?.name||"Tour"}),t?.duration_minutes?e.jsxs("p",{className:"mt-1 text-xs text-muted-foreground",children:[e.jsx(oe,{className:"mr-1 inline h-3 w-3"}),"Duration approx. ",Math.round(t.duration_minutes/60)," hours"]}):null]}),e.jsxs("div",{className:"flex flex-wrap items-center gap-x-5 gap-y-1 text-muted-foreground",children:[e.jsxs("span",{className:"inline-flex items-center gap-2",children:[e.jsx(Ce,{className:"h-4 w-4"})," ",de(n?.start_time),n?.start_time?` · ${me(n.start_time)}`:""]}),e.jsxs("span",{className:"inline-flex items-center gap-2",children:[e.jsx(Se,{className:"h-4 w-4"})," ",b.join(" + ")||"â"]})]}),s.booking.dietary_requirements&&e.jsxs("div",{className:"flex items-start gap-2 text-muted-foreground",children:[e.jsx($e,{className:"mt-0.5 h-4 w-4"})," ",s.booking.dietary_requirements]}),e.jsx(z,{}),e.jsxs("div",{className:"space-y-3",children:[i.length>0&&e.jsx(P,{label:`${i.length} ${$}${i.length===1?"":"s"} à ${w(m)}`,value:w(f)}),u.length>0&&e.jsx(P,{label:`${u.length} Infant${u.length===1?"":"s"} à ${w(k)}`,value:w(N)}),i.length===0&&u.length===0&&e.jsx(P,{label:"Tickets",value:w(s.totals.ticketTotalCents)}),s.transfers.map(o=>{const x=(o.transfer_type||"transfer").replace(/_/g," "),T=x.charAt(0).toUpperCase()+x.slice(1),l=o.pickup_address||o.dropoff_address;return e.jsxs("div",{className:"space-y-2",children:[e.jsx(P,{label:T,value:o.calculated_price_cents?w(o.calculated_price_cents):"Included"}),l&&e.jsxs("div",{className:"rounded-lg border border-border bg-muted/30 p-2.5 text-xs text-muted-foreground",children:[o.pickup_address&&e.jsxs("div",{className:"flex items-start gap-1.5",children:[e.jsx(ie,{className:"mt-0.5 h-3 w-3 shrink-0"}),e.jsxs("div",{children:[e.jsx("span",{className:"font-semibold uppercase tracking-wider text-secondary",children:"Pickup"}),e.jsx("div",{children:o.pickup_address})]})]}),o.dropoff_address&&e.jsxs("div",{className:`flex items-start gap-1.5 ${o.pickup_address?"mt-2":""}`,children:[e.jsx(ae,{className:"mt-0.5 h-3 w-3 shrink-0"}),e.jsxs("div",{children:[e.jsx("span",{className:"font-semibold uppercase tracking-wider text-secondary",children:"Drop-off"}),e.jsx("div",{children:o.dropoff_address})]})]})]})]},o.id)}),(()=>{const o=s.agencyContext;if(!o?.isAgencyBilled||!o.commissionCents)return null;const x=o.billingModel==="bill_agency_net";return e.jsx(P,{label:e.jsxs("span",{children:[x?"Agency commission":"Included commission",e.jsx("span",{className:"ml-2 text-[10px] uppercase tracking-wider text-muted-foreground
18/70",children:x?"Deducted on agency invoice":"Included in retail price"})]}),value:x?`â ${w(o.commissionCents)}`:w(o.commissionCents)})})(),s.totals.discountsTotalCents>0&&e.jsx(P,{label:"Discounts",value:`â ${w(s.totals.discountsTotalCents)}`}),s.totals.paidCents>0&&e.jsx(P,{label:"Paid",value:`â ${w(s.totals.paidCents)}`}),e.jsx(z,{}),e.jsx(P,{label:e.jsx("span",{className:"font-semibold",children:"Balance"}),value:e.jsx("span",{className:"font-display text-xl text-gold-dark sm:text-2xl",children:w(s.totals.balanceCents)})})]})]})})})}function P({label:s,value:n}){return e.jsxs("div",{className:"flex items-start justify-between gap-3 text-sm",children:[e.jsx("span",{className:"min-w-0 text-muted-foreground",children:s}),e.jsx("span",{className:"shrink-0 text-right",children:n})]})}function V({data:s}){const n=s.payments.filter(t=>["paid","confirmed","succeeded","complete","completed"].includes(t.status));return n.length?e.jsxs(C,{className:"border-gold/30 shadow-sm",children:[e.jsxs(D,{children:[e.jsx("p",{className:"mb-1 text-[10px] font-semibold uppercase tracking-[0.28em] text-gold",children:"History"}),e.jsx(B,{className:"font-display text-3xl font-normal sm:text-4xl",children:"Payment history"})]}),e.jsx(S,{className:"space-y-2",children:n.map((t,r)=>e.jsxs("div",{className:"flex items-center justify-between border-b pb-2 text-sm last:border-b-0",children:[e.jsxs("div",{children:[e.jsx("div",{className:"font-medium",children:w((t.amount_cents||0)-(t.refund_amount_cents||0))}),e.jsxs("div",{className:"text-xs text-muted-foreground",children:[t.paid_at?new Date(t.paid_at).toLocaleDateString("en-ZA",{day:"numeric",month:"short",year:"numeric"}):"â"," · ",t.payment_method||"card"]})]}),e.jsx(G,{className:"h-4 w-4 text-green-600"})]},r))})]}):null}export{ys 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.