1import{j as e}from"./motion-vendor-BK1YeJSN.js";import{r as n}from"./react-vendor-Di5V7eSe.js";import{u as _,B as g,C as P,s as b}from"./index-C8Zzhyxj.js";import{I as x}from"./input-B-Q1QX_s.js";import{L as c}from"./label-DQlN6lx4.js";import{T as E}from"./textarea-fc5EKxSr.js";import{C as u,a as h,b as B,c as D,d as F}from"./card-CFvxz2GG.js";import{H as M,F as L}from"./Footer-BZ11XtbB.js";import{C as T}from"./circle-check-BT_ILNSe.js";import{C as q}from"./calendar-CK2kSx94.js";import{M as A}from"./map-pin-Bsyb4bjh.js";import{f as l}from"./format-DRPn-UkS.js";import"./query-vendor-4LOGfLr1.js";import"./supabase-vendor-CXidNrjy.js";import"./index-Bsbc68eS.js";import"./Combination-D1C0ZRSG.js";import"./index-88a6dvrI.js";import"./check-BcDhTBg4.js";import"./chevron-down-CR5wZ-Lh.js";import"./heart-pris4dcl.js";function oe(){const[m,v]=n.useState([]),[y,N]=n.useState(!0),[r,d]=n.useState(null),[f,j]=n.useState(!1),[p,k]=n.useState(null),[o,i]=n.useState({name:"",email:"",phone:"",notes:""}),{toast:C}=_();n.useEffect(()=>{(async()=>{const{data:a}=await b.from("appointment_slots").select("*").eq("is_active",!0).gte("starts_at",new Date().toISOString()).order("starts_at");v((a??[]).filter(t=>t.booked_count<t.capacity)),N(!1)})()},[]);const w=n.useMemo(()=>{const s=new Map;
1for(const a of m){const t=l(new Date(a.starts_at),"EEEE, MMMM d, yyyy");s.has(t)||s.set(t,[]),s.get(t).push(a)}return Array.from(s.entries())},[m]),S=async s=>{if(s.preventDefault(),!!r){j(!0);try{const{data:a,error:t}=await b.functions.invoke("book-appointment",{body:{slot_id:r.id,...o,phone:o.phone||null,notes:o.notes||null}});if(t||a!=null&&a.error)throw new Error((a==null?void 0:a.error)||(t==null?void 0:t.message));k(r),d(null),i({name:"",email:"",phone:"",notes:""})}catch(a){C({title:"Booking failed",description:a.message??"Please try again.",variant:"destructive"})}finally{j(!1)}}};return e.jsxs("div",{className:"min-h-screen flex flex-col bg-background",children:[e.jsx(M,{}),e.jsx("main",{id:"main-content",className:"flex-1 container mx-auto px-4 md:px-6 py-12",children:e.jsxs("div",{className:"max-w-3xl mx-auto",children:[e.jsx("h1",{className:"font-display text-4xl font-bold text-primary mb-3",children:"Book an Appointment"}),e.jsx("p",{className:"text-muted-foreground mb-10",children:"Pick a time that works for you. We'll send a confirmation and reminders by email."}),p&&e.jsx(u,{className:"border-accent mb-8",children:e.jsxs(h,{className:"p-6 flex items-start gap-3",children:[e.jsx(T,{className:"w-6 h-6 text-accent shrink-0 mt-0.5"}),e.jsxs("div",{children:[e.jsx("p",{className:"font-semibold text-primary",children:"You're booked!"}),e.jsxs("p",{className:"text-sm text-muted-foreground",children:[p.title," â ",l(new Date(p.starts_at),"PPpp"),". Check your email for confirmation."]})]})]})}),y?e.jsx("p",{className:"text-muted-foreground",children:"Loading available timesâ¦"}):m.length===0?e.jsx(u,{children:e.jsx(h,{className:"p-8 text-center text-muted-foreground",children:"No appointment slots are currently available. Please check back soon."})}):r?e.jsxs(u,{children:[e.jsxs(B,{children:[e.jsx(D,{children:r.title}),e.jsxs(F,{children:[l(new Date(r.starts_at),"PPpp"),r.location?` · ${r.location}`:""]})]}),e.jsx(h,{children:e.jsxs("form",{onSubmit:S,className:"space-y-4",children:[e.jsxs("div",{className:"grid sm:grid-cols-2 gap-4",children:[e.jsxs("div",{children:[e.jsx(c,{htmlFor:"name",children:"Full Name *"}),e.jsx(x,{id:"name",required:!0,value:o.name,onChange:s=>i({...o,name:s.target.value})})]}),e.jsxs("div",{children:[e.jsx(c,{htmlFor:"email",children:"Email *"}),e.jsx(x,{id:"email",type:"email",required:!0,value:o.email,onChange:s=>i({...o,email:s.target.value})})]})]}),e.jsxs("div",{children:[e.jsx(c,{htmlFor:"phone",children:"Phone"}),e.jsx(x,{id:"phone",type:"tel",value:o.phone,onChange:s=>i({...o,phone:s.target.value})})]}),e.jsxs("div",{children:[e.jsx(c,{htmlFor:"notes",children:"Notes"}),e.jsx(E,{id:"notes",value:o.notes,onChange:s=>i({...o,notes:s.target.value}),maxLength:1e3})]}),e.jsxs("div",{className:"flex gap-3",children:[e.jsx(g,{type:"button",variant:"outline",onClick:()=>d(null),children:"Back"}),e.jsx(g,{type:"submit",disabled:f,className:"bg-accent hover:bg-accent/90 text-accent-foreground",children:f?"Bookingâ¦":"Confirm Booking"})]})]})})]}):e.jsx("div",{className:"space-y-8",children:w.map(([s,a])=>e.jsxs("div",{children:[e.jsxs("h2",{className:"font-display text-xl font-semibold text-primary mb-3 flex items-center gap-2",children:[e.jsx(q,{className:"w-5 h-5"})," ",s]}),e.jsx("div",{className:"grid sm:grid-cols-2 gap-3",children:a.map(t=>e.jsxs("button",{onClick:()=>d(t),className:"text-left p-4 rounded-lg border border-border hover:border-accent hover:bg-accent/5 transition",children:[e.jsx("p",{className:"font-semibold text-primary",children:t.title}),e.jsxs("p",{className:"text-sm text-muted-foreground flex items-center gap-1 mt-1",children:[e.jsx(P,{className:"w-3.5 h-3.5"}),l(new Date(t.starts_at),"p")," â ",l(new Date(t.ends_at),"p")]}),t.location&&e.jsxs("p",{className:"text-sm text-muted-foreground flex items-center gap-1",children:[e.jsx(A,{className:"w-3.5 h-3.5"})," ",t.location]}),e.jsxs("p",{className:"text-xs text-muted-foreground mt-2",children:[t.capacity-t.booked_count," spot",t.capacity-t.booked_count===1?"":"s"," left"]})]},t.id))})]},s))})]})}),e.jsx(L,{})]})}
1export{oe 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.