1import{r as d,j as e}from"./react-vendor-C-_weJGF.js";import{u as S,c as O}from"./query-DA-B5yju.js";import{s as N,P as Z,S as G,h as R,B as x,a as U}from"./index-DiEum5Ju.js";import{C as W}from"./calendar-X-rd7Six.js";import{I as v}from"./input-TSEJWV9X.js";import{T as Y}from"./textarea-7KtP0QKs.js";import{L as j}from"./label-Dam5lWpQ.js";import{C as p}from"./card-D9fxEFKG.js";import{S as q}from"./skeleton-CSiVJos9.js";import{j as $,r as H,q as E,O as Q,d as V,E as J}from"./icons-BZJMmL1V.js";import{o as X,s as y}from"./types-4og3oiYD.js";import"./radix-CMA3xQgM.js";import"./supabase-BppBjPB2.js";import"./motion-CfmjrLVm.js";import"./format-Cpjm9erV.js";const ee=X({name:y().trim().min(1,"Name is required").max(120),email:y().trim().email("Valid email required").max(255),phone:y().trim().max(40).optional(),company:y().trim().max(160).optional(),notes:y().trim().max(2e3).optional()});function _(l,c){return new Intl.DateTimeFormat("en-US",{hour:"numeric",minute:"2-digit",timeZone:c}).format(new Date(l))}function L(l,c){return new Intl.DateTimeFormat("en-US",{weekday:"long",month:"long",day:"numeric",year:"numeric",timeZone:c}).format(new Date(l))}function ge(){const[l,c]=d.useState(1),[s,M]=d.useState(null),[u,I]=d.useState(),[m,C]=d.useState(null),[r,g]=d.useState({name:"",email:"",phone:"",company:"",notes:""}),[b,B]=d.useState(null),{data:a}=S({queryKey:["scheduling-settings"],queryFn:async()=>{const{data:t}=await N.from("scheduling_settings_public").select("*").limit(1).single();return t}}),{data:T=[]}=S({queryKey:["meeting-types-public"],queryFn:async()=>{const{data:t}=await N.from("meeting_types").select("*").eq("enabled",!0).order("sort_order");return t||[]}}),n=(a==null?void 0:a.timezone)||"America/Chicago",{earliest:D,latest:F}=d.useMemo(()=>{const t=new Date,o=new Date(t.getTime()+((a==null?void 0:a.min_notice_hours)??2)*36e5),h=new Date(t.getTime()+((a==null?void 0:a.max_advance_days)??30)*864e5);return{earliest:o,latest:h}},[a]),{data:f,isFetching:z}=S({queryKey:["availability-range",s==null?void 0:s.id,a==null?void 0:a.min_notice_hours,a==null?void 0:a.max_advance_days],enabled:!!s&&!!a,staleTime:6e4,gcTime:5*6e4,queryFn:async()=>{if(!s)return{slots:[],timezone:n};const{data:t,error:o}=await N.functions.invoke("booking-availability",{body:{meeting_type_id:s.id,from:D.toISOString(),to:F.toISOString()}});if(o)throw o;return t}}),w=d.useMemo(()=>{if(!f||!u)return;const t=new Intl.DateTimeFormat("en-CA",{timeZone:n,year:"numeric",month:"2-digit",day:"2-digit"}).format(u);return{slots:f.slots.filter(h=>new Intl.DateTimeFormat("en-CA",{timeZone:n,year:"numeric",month:"2-digit",day:"2-digit"}).format(new Date(h))===t),timezone:f.timezone}},[f,u,n]),A=z&&!f,k=O({mutationFn:async()=>{var P;const t=ee.safeParse(r);if(!t.success)throw new Error(((P=t.error.errors[0])==null?void 0:P.message)||"Please check your information");if(!s||!m)throw new Error("Pick a time first");const{data:o,error:h}=await N.functions.invoke("booking-create",{body:{meeting_type_id:s.id,starts_at:m,name:t.data.name,email:t.data.email,phone:t.data.phone,company:t.data.company,notes:t.data.notes,source:"streamline-factory"}});if(h)throw h;const i=o;if(!(i!=null&&i.ok))throw(i==null?void 0:i.error)==="slot_taken"?new Error("That time was just taken. Please pick another."):(i==null?void 0:i.error)==="rate_limited"?new Error("Too many requests. Try again in an hour."):new Error("Could not create booking. Please try again.");return i},onSuccess:t=>{B({meet_url:t.meet_url,when:m?`${L(m,n)} at ${_(m,n)}`:""}),c(4)},onError:t=>U.error(t.message)});d.useEffect(()=>{const t=document.getElementById("booking-flow");if(t){const o=t.getBoundingClientRect().top+window.scrollY-96;window.scrollTo({top:Math.max(0,o),behavior:"smooth"})}},[l]);const K=t=>t<new Date(D.toDateString())||t>F;return e.jsxs(Z,{children:[e.jsx(G,{title:"Schedule a Meeting | Streamline Factory",description:"Book a 15, 30, or 60 minute meeting. We'll send a Google Meet link."}),e.jsxs("section",{id:"booking-flow",className:"container mx-auto px-4 py-16 max-w-3xl scroll-mt-24",children:[e.jsxs("header",{className:"text-center mb-10",children:[e.jsx("h1",{className:"text-3xl md:text-4xl font-display font-bold text-foreground mb-3",children:(a==null?void 0:a.intro_heading)||"Schedule a Meeting"}),e.jsx("p",{className:"text-muted-foreground max-w-xl mx-auto",children:(a==null?void 0:a.intro_subtext)||"Pick a time that works for you. We'll send a Google Meet link."})]}),a&&!a.enabled?e.jsx(p,{className:"p-8 text-center",children:e.jsx("p",{className:"text-muted-foreground",children:"Online booking is temporarily unavailable. Please contact us directly."})}):e.jsxs("div",{className:"space-y-6",children:[e.jsx("div",{className:"flex items-center justify-center gap-2 text-xs text-muted-foreground",children:[1,2,3].map(t=>e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:R("w-7 h-7 rounded-full flex items-center justify-center border",l>=t?"bg-primary text-primary-foreground border-primary":"border-border"),children:t}),t<3&&e.jsx("span",{className:"w-8 h-px bg-border"})]},t))}),l===1&&e.jsx("div",{className:"grid gap-3",children:T.length===0?e.jsx(q,{className:"h-24"}):T.map(t=>
1e.jsx(p,{className:"p-5 hover:border-primary cursor-pointer transition-colors",onClick:()=>{M(t),c(2)},children:e.jsxs("div",{className:"flex items-start justify-between gap-4",children:[e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center gap-2 mb-1",children:[e.jsx($,{className:"w-4 h-4 text-primary"}),e.jsx("h3",{className:"font-display font-semibold text-foreground",children:t.label}),e.jsxs("span",{className:"text-xs text-muted-foreground",children:["· ",t.duration_minutes," min"]})]}),t.description&&e.jsx("p",{className:"text-sm text-muted-foreground",children:t.description})]}),e.jsx(x,{size:"sm",variant:"outline",children:"Select"})]})},t.id))}),l===2&&s&&e.jsxs("div",{className:"grid md:grid-cols-[auto,1fr] gap-6",children:[e.jsx(p,{className:"p-3 pointer-events-auto",children:e.jsx(W,{mode:"single",selected:u,onSelect:t=>{I(t),C(null)},disabled:K,initialFocus:!0,className:"pointer-events-auto"})}),e.jsxs(p,{className:"p-5",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-3",children:[e.jsx(H,{className:"w-4 h-4 text-primary"}),e.jsx("h3",{className:"font-display font-semibold text-foreground",children:u?new Intl.DateTimeFormat("en-US",{weekday:"long",month:"long",day:"numeric"}).format(u):"Pick a date"})]}),u?A?e.jsx("div",{className:"grid grid-cols-3 gap-2",children:Array.from({length:6}).map((t,o)=>e.jsx(q,{className:"h-9"},o))}):((w==null?void 0:w.slots)??[]).length===0?e.jsx("p",{className:"text-sm text-muted-foreground",children:"No times available on this day. Try another date."}):e.jsx("div",{className:"grid grid-cols-3 gap-2 max-h-72 overflow-y-auto pr-1",children:w.slots.map(t=>e.jsx(x,{type:"button",variant:m===t?"default":"outline",size:"sm",onClick:()=>C(t),children:_(t,n)},t))}):e.jsx("p",{className:"text-sm text-muted-foreground",children:"Select a date to see available times."}),e.jsxs("p",{className:"text-xs text-muted-foreground mt-3",children:["Times shown in ",n]}),e.jsxs("div",{className:"flex justify-between mt-5",children:[e.jsxs(x,{variant:"ghost",size:"sm",onClick:()=>c(1),children:[e.jsx(E,{className:"w-4 h-4 mr-1"})," Back"]}),e.jsx(x,{disabled:!m,onClick:()=>c(3),children:"Continue"})]})]})]}),l===3&&s&&m&&e.jsxs(p,{className:"p-6",children:[e.jsxs("div",{className:"mb-5 p-3 rounded-md bg-muted/40 text-sm",children:[e.jsx("strong",{children:s.label})," · ",s.duration_minutes," min",e.jsx("br",{}),L(m,n)," at ",_(m,n)," (",n,")"]}),e.jsxs("form",{className:"space-y-4",onSubmit:t=>{t.preventDefault(),k.mutate()},children:[e.jsxs("div",{className:"grid md:grid-cols-2 gap-4",children:[e.jsxs("div",{children:[e.jsx(j,{htmlFor:"name",children:"Name *"}),e.jsx(v,{id:"name",value:r.name,onChange:t=>g({...r,name:t.target.value}),required:!0,maxLength:120})]}),e.jsxs("div",{children:[e.jsx(j,{htmlFor:"email",children:"Email *"}),e.jsx(v,{id:"email",type:"email",value:r.email,onChange:t=>g({...r,email:t.target.value}),required:!0,maxLength:255})]}),e.jsxs("div",{children:[e.jsx(j,{htmlFor:"phone",children:"Phone"}),e.jsx(v,{id:"phone",value:r.phone,onChange:t=>g({...r,phone:t.target.value}),maxLength:40})]}),e.jsxs("div",{children:[e.jsx(j,{htmlFor:"company",children:"Company"}),e.jsx(v,{id:"company",value:r.company,onChange:t=>g({...r,company:t.target.value}),maxLength:160})]})]}),e.jsxs("div",{children:[e.jsx(j,{htmlFor:"notes",children:"What would you like to discuss?"}),e.jsx(Y,{id:"notes",rows:4,value:r.notes,onChange:t=>g({...r,notes:t.target.value}),maxLength:2e3})]}),e.jsxs("div",{className:"flex justify-between pt-2",children:[e.jsxs(x,{type:"button",variant:"ghost",onClick:()=>c(2),children:[e.jsx(E,{className:"w-4 h-4 mr-1"})," Back"]}),e.jsx(x,{type:"submit",disabled:k.isPending,children:k.isPending?e.jsxs(e.Fragment,{children:[e.jsx(Q,{className:"w-4 h-4 mr-2 animate-spin"})," Booking..."]}):"Confirm booking"})]})]})]}),l===4&&b&&e.jsxs(p,{className:"p-8 text-center",children:[e.jsx("div",{className:"w-12 h-12 rounded-full bg-primary/10 text-primary flex items-center justify-center mx-auto mb-4",children:e.jsx(V,{className:"w-6 h-6"})}),e.jsx("h2",{className:"text-2xl font-display font-bold mb-2",children:"You're booked!"}),e.jsx("p",{className:"text-muted-foreground mb-1",children:b.when}),e.jsx("p",{className:"text-sm text-muted-foreground mb-6",children:"A calendar invite has been sent to your email."}),b.meet_url&&e.jsx("a",{href:b.meet_url,target:"_blank",rel:"noopener noreferrer",className:"inline-flex",children:e.jsxs(x,{children:[e.jsx(J,{className:"w-4 h-4 mr-2"})," Open Google Meet"]})})]})]})]})]})}export{ge 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.