1import{j as a}from"./ui-vendor-ZmGZwY6t.js";import{j as G,r as l,L as K}from"./react-vendor-BM8Uq7ST.js";import{s as z,Z as Q,V as X,B as O,_ as ee}from"./index-CCDoor1O.js";import{m as B,a as Z,f as g,s as te,e as ne,b as ae,C as se}from"./calendar-DDg93OpW.js";import{C as N,a as b}from"./card-sUmwmBXQ.js";import{L as R}from"./loader-circle-B7i5somu.js";import{C as oe}from"./calendar-check-LJHjzap-.js";import"./animation-vendor-D_w1Qu3x.js";import"./chevron-left-BOHY8LBT.js";import"./chevron-right-DUfeaqZi.js";function re(n,e){const t=de(n);let o;if(t.date){const c=ue(t.date,2);o=me(c.restDateString,c.year)}if(!o||isNaN(o.getTime()))return new Date(NaN);const i=o.getTime();let u=0,m;if(t.time&&(u=fe(t.time),isNaN(u)))return new Date(NaN);if(t.timezone){if(m=pe(t.timezone),isNaN(m))return new Date(NaN)}else{const c=new Date(i+u),d=new Date(0);return d.setFullYear(c.getUTCFullYear(),c.getUTCMonth(),c.getUTCDate()),d.setHours(c.getUTCHours(),c.getUTCMinutes(),c.getUTCSeconds(),c.getUTCMilliseconds()),d}return new Date(i+u+m)}const j={dateTimeDelimiter:/[T ]/,timeZoneDelimiter:/[Z ]/i,timezone:/([Z+-].*)$/},ie=/^-?(?:(\d{3})|(\d{2})(?:-?(\d{2}))?|W(\d{2})(?:-?(\d{1}))?|)$/,ce=/^(\d{2}(?:[.,]\d*)?)(?::?(\d{2}(?:[.,]\d*)?))?(?::?(\d{2}(?:[.,]\d*)?))?$/,le=/^([+-])(\d{2})(?::?(\d{2}))?$/;function de(n){const e={},s=n.split(j.dateTimeDelimiter);let t;if(s.length>2)return e;if(/:/.test(s[0])?t=s[0]:(e.date=s[0],t=s[1],j.timeZoneDelimiter.test(e.date)&&(e.date=n.split(j.timeZoneDelimiter)[0],t=n.substr(e.date.length,n.length))),t){const o=j.timezone.exec(t);
1o?(e.time=t.replace(o[1],""),e.timezone=o[1]):e.time=t}return e}function ue(n,e){const s=new RegExp("^(?:(\\d{4}|[+-]\\d{"+(4+e)+"})|(\\d{2}|[+-]\\d{"+(2+e)+"})$)"),t=n.match(s);if(!t)return{year:NaN,restDateString:""};const o=t[1]?parseInt(t[1]):null,i=t[2]?parseInt(t[2]):null;return{year:i===null?o:i*100,restDateString:n.slice((t[1]||t[2]).length)}}function me(n,e){if(e===null)return new Date(NaN);const s=n.match(ie);if(!s)return new Date(NaN);const t=!!s[4],o=k(s[1]),i=k(s[2])-1,u=k(s[3]),m=k(s[4]),c=k(s[5])-1;if(t)return Ne(e,m,c)?he(e,m,c):new Date(NaN);{const d=new Date(0);return!xe(e,i,u)||!ye(e,o)?new Date(NaN):(d.setUTCFullYear(e,i,Math.max(o,u)),d)}}function k(n){return n?parseInt(n):1}function fe(n){const e=n.match(ce);if(!e)return NaN;const s=D(e[1]),t=D(e[2]),o=D(e[3]);return be(s,t,o)?s*B+t*Z+o*1e3:NaN}function D(n){return n&&parseFloat(n.replace(",","."))||0}function pe(n){if(n==="Z")return 0;const e=n.match(le);if(!e)return 0;const s=e[1]==="+"?-1:1,t=parseInt(e[2]),o=e[3]&&parseInt(e[3])||0;return ke(t,o)?s*(t*B+o*Z):NaN}function he(n,e,s){const t=new Date(0);t.setUTCFullYear(n,0,4);const o=t.getUTCDay()||7,i=(e-1)*7+s+1-o;return t.setUTCDate(t.getUTCDate()+i),t}const ge=[31,null,31,30,31,30,31,31,30,31,30,31];function W(n){return n%400===0||n%4===0&&n%100!==0}function xe(n,e,s){return e>=0&&e<=11&&s>=1&&s<=(ge[e]||(W(n)?29:28))}function ye(n,e){return e>=1&&e<=(W(n)?366:365)}function Ne(n,e,s){return e>=1&&e<=53&&s>=0&&s<=6}function be(n,e,s){return n===24?e===0&&s===0:s>=0&&s<60&&e>=0&&e<60&&n>=0&&n<25}function ke(n,e){return e>=0&&e<=59}const C={morning:"Half day â morning, 08:00â13:00",afternoon:"Half day â afternoon, 13:00â18:00",full_day:"Full day, 08:00â18:00"},L={secured:"Your booking has been approved or a deposit has been paid, so it's now secured.",too_close:"Your booking is 2 days away or less.",closed:"This booking has been cancelled, declined or completed.",not_changeable:"This booking can't be changed online."},F=async n=>{var t,o;const{data:e,error:s}=await z.functions.invoke("client-change-booking",{body:n});if(s){let i="Something went wrong.";try{i=((o=await((t=s.context)==null?void 0:t.json()))==null?void 0:o.error)??i}catch{}throw new Error(i)}return e};function Ue(){const{token:n=""}=G(),[e,s]=l.useState(!0),[t,o]=l.useState(null),[i,u]=l.useState(null),[m,c]=l.useState(!1),[d,A]=l.useState(new Date),[T,H]=l.useState({}),[p,P]=l.useState(),[x,S]=l.useState(null),[v,M]=l.useState(!1),[_,w]=l.useState(null),[$,V]=l.useState(!1);l.useEffect(()=>{document.title="Change your studio booking | Africa Podcast Network";const r=document.createElement("meta");return r.name="robots",r.content="noindex,nofollow",document.head.appendChild(r),()=>{r.remove()}},[]),l.useEffect(()=>{F({token:n,action:"get"}).then(r=>{o(r.booking),u(r.changeable?null:r.reason)}).catch(()=>c(!0)).finally(()=>s(!1))},[n]),l.useEffect(()=>{!t||i||z.rpc("get_month_availability",{p_start:g(te(d),"yyyy-MM-dd"),p_end:g(ne(d),"yyyy-MM-dd")}).then(({data:r})=>{const h={};(r??[]).forEach(y=>{let I=y.morning_taken,Y=y.afternoon_taken;y.the_date===t.booking_date&&(t.slot_type!=="afternoon"&&(I=!1),t.slot_type!=="morning"&&(Y=!1)),h[y.the_date]={morning:I,afternoon:Y,blocked:y.is_blocked}}),H(h)})},[d,t,i]);const J=ae(new Date,3),f=p?T[g(p,"yyyy-MM-dd")]:void 0,E=l.useMemo(()=>({morning:!!f&&!f.morning,afternoon:!!f&&!f.afternoon,full_day:!!f&&!f.morning&&!f.afternoon}),[f]),q=async()=>{if(!(!p||!x)){M(!0),w(null);try{const r=await F({token:n,action:"change",booking_date:g(p,"yyyy-MM-dd"),slot_type:x});o(r.booking),V(!0),window.scrollTo({top:0,behavior:"smooth"})}catch(r){w(r.message)}finally{M(!1)}}},U=a.jsxs("div",{className:"space-y-2 text-sm",children:[a.jsx("p",{children:"Please contact the studio directly to make changes:"}),a.jsx("p",{children:a.jsx("a",{className:"text-primary underline",href:"mailto:[email protected]",children:"[email protected]"})})]});return a.jsxs("div",{className:"min-h-screen bg-background text-foreground",children:[a.jsx(Q,{}),a.jsxs("main",{className:"container mx-auto max-w-2xl px-4 pt-32 pb-20",children:[a.jsx("h1",{className:"text-3xl font-bold mb-6",children:"Change your booking"}),e?a.jsx(R,{className:"h-6 w-6 animate-spin","aria-label":"Loading"}):m||!t?a.jsx(N,{children:a.jsxs(b,{className:"p-6 space-y-3",children:[a.jsx("p",{children:"This link isn't valid."}),U]})}):a.jsxs("div",{className:"space-y-6",children:[a.jsx(N,{children:a.jsxs(b,{className:"p-6 space-y-1",children:[a.jsxs("p",{className:"text-sm text-muted-foreground",children:["Booking ref ",t.reference]}),a.jsx("p",{className:"font-semibold",children:g(re(t.booking_date),"EEEE d MMMM yyyy")}),a.jsx("p",{children:C[t.slot_type]})]})}),$?a.jsx(N,{className:"border-primary",children:a.jsxs(b,{className:"p-6 space-y-2",children:[a.jsxs("p",{className:"flex items-center gap-2 font-semibold",children:[a.jsx(oe,{className:"h-5 w-5 text-primary"}),"Your booking has been updated."]}),a.jsx("p",{className:"text-sm",children:"It's still a pencil booking and is only secured once we receive a 50% deposit. Our team has been notified."})]})}):i?a.jsx(N,{children:a.jsxs(b,{className:"p-6 space-y-3",children:[a.jsxs("p",{className:"flex items-center gap-2 font-semibold",children:[a.jsx(X,{className:"h-5 w-5"}),"This booking can't be changed online"]}),a.jsx("p",{className:"text-sm",children:L[i]??L.not_changeable}),U]})}):a.jsx(N,{children:a.jsxs(b,{className:"p-6 space-y-4",children:[a.jsx("p",{className:"text-sm text-muted-foreground",children:"Pick a new date (at least 3 days away) and session. Your details and extras stay the same."}),a.jsx(se,{mode:"single",selected:p,month:d,onMonthChange:A,onSelect:r=>{P(r),S(null),w(null)},disabled:r=>{const h=T[g(r,"yyyy-MM-dd")];return r<J||!h||h.blocked||h.morning&&h.afternoon},className:"rounded-md border mx-auto"}),p&&a.jsx("div",{className:"grid gap-2",role:"radiogroup","aria-label":"Session",children:Object.keys(C).map(r=>a.jsxs(O,{type:"button",variant:x===r?"default":"outline",disabled:!E[r],role:"radio","aria-checked":x===r,onClick:()=>S(r),className:"justify-start",children:[C[r],!E[r]&&" (unavailable)"]},r))}),_&&a.jsx("p",{className:"text-sm text-destructive",role:"alert",children:_}),a.jsxs(O,{onClick:q,disabled:!p||!x||v,className:"w-full",children:[v&&a.jsx(R,{className:"h-4 w-4 animate-spin mr-2"}),"Confirm new date"]}),a.jsx("p",{className:"text-xs text-muted-foreground",children:"Changing to a different session length updates the studio price (half day R4,000, full day R5,500 excl. VAT). Weekend dates add the R450 weekend surcharge."})]})}),a.jsx(K,{to:"/studio",className:"text-sm text-primary underline",children:"Back to the studio page"})]})]}),a.jsx(ee,{})]})}
1export{Ue 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.