1import{aA as F,u as R,K as $,r as j,c as v,d as N,j as e,a2 as u,E as w,F as C,$ as k,B as i,ac as D,a8 as q,a9 as I,J as L,a1 as K,T as M,h as Q,e as y}from"./index-BBYsJQph.js";import{S as O,a as Y,b as V,c as G,d as H}from"./select-BwyxcVK2.js";import{C as A}from"./circle-x-Cqd-d9TQ.js";import"./index-BdQq_4o_.js";function B(x){return new Date(x).toLocaleString("en-GB",{weekday:"long",day:"numeric",month:"long",year:"numeric",hour:"2-digit",minute:"2-digit",timeZone:"Europe/London"})}function W(){const n=F().token,{toast:r}=R(),h=$(),[l,c]=j.useState("view"),[d,E]=j.useState(""),{data:p,isLoading:S,error:T}=v({queryKey:[`/api/events/bookings/by-token/${n}`],enabled:!!n}),{data:P}=v({queryKey:["/api/events"],enabled:l==="reschedule"}),o=N({mutationFn:async()=>(await y("POST",`/api/events/bookings/by-token/${n}/cancel`,{})).json(),onSuccess:s=>{r({title:"Booking cancelled",description:s.refunded?`£${s.refundAmount.toFixed(2)} refund issued.`:"No refund applicable per policy."}),h.invalidateQueries({queryKey:[`/api/events/bookings/by-token/${n}`]})},onError:s=>r({title:"Cancellation failed",description:s.message,variant:"destructive"})}),m=N({mutationFn:async()=>(await y("POST",`/api/events/bookings/by-token/${n}/reschedule`,{newEventId:parseInt(d,10)})).json(),onSuccess:()=>{r({title:"Rescheduled",description:"Your booking has been moved."}),h.invalidateQueries({queryKey:[`/api/events/bookings/by-token/${n}`]}),c("view")},onError:s=>r({title:"Reschedule failed",description:s.message,variant:"destructive"})});if(S)return e.jsx("div",{className:"min-h-screen flex items-center justify-center bg-[#f6f1e7]",children:e.jsx(u,{className:"h-10 w-10 animate-spin text-[#B7A8CC]"})});if(T||!p)return e.jsx("div",{className:"min-h-screen flex items-center justify-center bg-[#f6f1e7] p-4",children:e.jsx(w,{className:"max-w-md w-full bg-white border-[#ece2d2]",children:e.jsxs(C,{className:"p-6 text-center",children:[e.jsx(A,{className:"h-12 w-12 text-[#a05a3f] mx-auto mb-4"}),e.jsx("p",{className:"text-[#4A3C3A] mb-4",children:"Booking link not found or expired."}),e.jsx(k,{href:"/events",children:e.jsx(i,{className:"bg-[#cd8161] hover:bg-[#b5694d] text-white",children:"Browse events"})})]})})});const{booking:a,event:t}=p,f=a.status==="cancelled"||a.status==="refunded",g=(t?(new Date(t.eventDateTime).getTime()-Date.now())/(1e3*60*60):0)>=48,b=(P||[]).filter(s=>s.id!==a.eventId&&t&&s.name===t.name&&parseFloat(s.pricePerPerson)===parseFloat(t.pricePerPerson)&&s.capacity-s.attendeesBooked>=a.numberOfAttendees);return e.jsx("div",{className:"min-h-screen bg-[#f6f1e7]",children:e.jsxs("div",{className:"container mx-auto px-4 py-6 max-w-2xl",children:[e.jsx("div",{className:"mb-4 -ml-2",children:e.jsxs(k,{href:"/events",className:"inline-flex items-center gap-2 px-3 py-2 text-sm font-medium text-[#4A3C3A] hover:bg-white/60 rounded-lg transition-colors",children:[e.jsx(D,{className:"h-4 w-4"}),"Browse events"]})}),e.jsxs(w,{className:"bg-white border-[#ece2d2] mb-4",children:[e.jsx(q,{children:e.jsx(I,{className:"font-lulo-clean uppercase text-xl tracking-tight text-[#4A3C3A]",children:"Manage Your Booking"})}),e.jsxs(C,{className:"space-y-3",children:[e.jsxs("div",{className:"bg-[#f6f1e7] rounded-lg p-4",children:[e.jsx("p",{className:"font-medium text-[#4A3C3A] mb-1",children:(t==null?void 0:t.name)||"Event"}),e.jsxs("div",{className:"text-sm text-[#756661] space-y-1",children:[t&&e.jsxs("p",{className:"flex items-center gap-2",children:[e.jsx(L,{className:"h-4 w-4 text-[#B7A8CC]"}),B(t.eventDateTime)]}),e.jsxs("p",{children:["Booked by: ",a.firstName," ",a.lastName," · ",a.customerEmail]}),e.jsxs("p",{children:["Attendees: ",a.numberOfAttendees]}),e.jsxs("p",{children:["Total paid: £",parseFloat(a.totalAmount).toFixed(2)]}),e.jsxs("p",{children:["Reference: #",a.id]}),e.jsxs("p",{className:"pt-1",children:["Status: ",e.jsx("span",{className:`font-medium ${f?"text-[#a05a3f]":"text-[#5f8a55]"}`,"data-testid":"text-status",children:a.status})]})]})]}),f?e.jsxs("div",{className:"bg-[#faf7f2] border border-[#ece2d2] rounded-lg p-4 text-center",children:[e.jsx(K,{className:"h-8 w-8 text-[#8BB381] mx-auto mb-2"}),e.jsx("p",{className:"text-[#4A3C3A] font-medium",children:"This booking has been cancelled."}),a.refundAmount&&e.jsxs("p",{className:"text-sm text-[#756661] mt-1",children:["Refund issued: £",parseFloat(a.refundAmount).toFixed(2)]})]}):e.jsxs(e.Fragment,{children:[t&&e.jsx("div",{className:`rounded-lg p-3 text-sm ${g?"bg-[#8BB381]/10 border border-[#8BB381]/40 text-[#4d6b45]":"bg-[#e1a95f]/10 border border-[#e1a95f]/40 text-[#8a5a1f]"}`,children:e.jsxs("div",{className:"flex items-start gap-2",children:[e.jsx(M,{className:"h-4 w-4 flex-shrink-0 mt-0.5"}),e.jsx("p",{children:g?"You are within the refund window â cancelling now will issue a full refund.":"This event is less than 48 hours away â cancellations after this point are not refundable per our policy."})]})}),l==="view"&&e.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-3 pt-2",children:[e.jsxs(i,{onClick:()=>c("reschedule"),variant:"outline",className:"border-[#B7A8CC] text-[#8B7BAE] hover:bg-[#B7A8CC]/10","data-testid":"button-show-reschedule",children:[e.jsx(Q,{className:"h-4 w-4 mr-2"}),"Reschedule"]}),e.jsxs(i,{onClick:()=>{confirm("Cancel this booking?")&&o.mutate()},disabled:o.isPending,variant:"destructive","data-testid":"button-cancel",children:[o.isPending?e.jsx(u,{className:"h-4 w-4 mr-2 animate-spin"}):e.jsx(A,{className:"h-4 w-4 mr-2"}),"Cancel Booking"]})]}),l==="reschedule"&&e.jsxs("div",{className:"space-y-3 pt-2",children:[e.jsxs("p",{className:"text-sm text-[#4A3C3A]",children:["Pick a future ",t==null?void 0:t.name," session at the same price:"]}),b.length===0?e.jsx("p",{className:"text-sm text-[#756661] italic",children:"No alternative dates available."}):e.jsxs(O,{value:d,onValueChange:E,children:[e.jsx(Y,{"data-testid":"select-new-event",children:e.jsx(V,{placeholder:"Select a date"})}),e.jsx(G,{children:b.map(s=>e.jsxs(H,{value:String(s.id),children:[B(s.eventDateTime)," (",s.capacity-s.attendeesBooked," spots)"]},s.id))})]}),e.jsxs("div",{className:"flex gap-3",children:[e.jsx(i,{onClick:()=>c("view"),variant:"outline",className:"flex-1",children:"Back"}),e.jsxs(i,{onClick:()=>m.mutate(),disabled:!d||m.isPending,className:"flex-1 bg-[#cd8161] hover:bg-[#b5694d] text-white","data-testid":"button-confirm-reschedule",children:[m.isPending?e.jsx(u,{className:"h-4 w-4 mr-2 animate-spin"}):null,"Confirm Reschedule"]})]})]})]})]})]}),e.jsx("p",{className:"text-center text-sm text-[#756661]",children:"Questions? Email [email protected]"})]})})}export{W 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.