PageSourceSearch

https://buildhome.ai/assets/ChatWidget-qZYhSAHR.js

js buildhome.ai collected 2026-10-05 12:13:56 UTC 6,292 bytes, 1 lines download raw bytes

1import{j as e}from"./vendor-ui-uBXRrZie.js";import{r}from"./vendor-react-xrnaEb-q.js";import{u as E,B as c,C as D,X as M,s as g}from"./index-BvbwRED0.js";import{I as m}from"./input-CeRD03VA.js";import{S as L}from"./scroll-area-7z3YLAQu.js";import{L as i}from"./label-DDun1yXE.js";import{R as T,a as N}from"./radio-group-cQGJXYJq.js";import{M as k}from"./message-square-BAg8r0f1.js";import{M as O}from"./mail-Bd9XRZup.js";import{L as R}from"./loader-circle-c0LT0qAz.js";import{S as A}from"./send-kYlKuRxn.js";import"./vendor-three-rLiihlwp.js";import"./vendor-query-CpsPhH-U.js";import"./vendor-charts-BaGe9Ks8.js";import"./circle-CC5rI7xX.js";const Z=()=>{const[f,y]=r.useState(!1),[p,d]=r.useState([]),[o,w]=r.useState(""),[x,S]=r.useState(!1),[b]=r.useState(()=>`session_${Date.now()}_${Math.random()}`),[I,j]=r.useState(!1),[a,l]=r.useState({firstName:"",lastName:"",email:"",phone:"",interestType:"learn_more"}),h=r.useRef(null),{toast:u}=E();r.useEffect(()=>{h.current&&(h.current.scrollTop=h.current.scrollHeight)},[p]),r.useEffect(()=>{f&&p.length===0&&d([{role:"assistant",content:"Hello! 👋 I'm your BuildHome.ai assistant. I can help you with home design, construction planning, cost estimates, and more. What would you like to know?",timestamp:new Date().toISOString()}])},[f]);const C=async()=>{if(!o.trim())return;const s={role:"user",content:o,timestamp:new Date().toISOString()};d(t=>[...t,s]),w(""),S(!0);try{const{data:t,error:n}=await g.functions.invoke("chatbot-agent",{body:{message:o,sessionId:b}});if(n)throw n;const v={role:"assistant",content:t.response,timestamp:new Date().toISOString()};d(_=>[..._,v]),(t.followUpAction==="show_demo_form"||t.followUpAction==="show_contact_form")&&j(!0)}catch(t){console.error("Error:",t),u({title:"Error",description:"Failed to send message. Please try again.",variant:"destructive"})}finally{S(!1)}},F=async()=>{if(!a.firstName||!a.lastName||!a.email){u({title:"Required fields",description:"Please fill in all required fields.",variant:"destructive"});return}try{const{data:s,error:t}=await g.from("chat_leads").insert({session_id:b,first_name:a.firstName,last_name:a.lastName,email:a.email,phone:a.phone,interest_type:a.interestType}).select().single();if(t)throw t;const{error:n}=await g.functions.invoke("send-verification-email",{body:{leadId:s.id}});n&&console.error("Email error:",n),u({title:"Thank you!",description:"We've sent you a verification email. Check your inbox to schedule your demo."}),j(!1),d(v=>[...v,{role:"assistant",content:"✅ Thank you! I've saved your information. You'll receive a verification email shortly. Once verified, you can schedule your demo at a time that works for you.",timestamp:new Date().toISOString()}])}catch(s){console.error("Error:",s),u({title:"Error",description:"Failed to submit. Please try again.",variant:"destructive"})}};return f?e.jsxs(D,{className:"fixed bottom-6 right-6 w-96 h-[600px] flex flex-col shadow-2xl z-50",children:[e.jsxs("div",{className:"flex items-center justify-between p-4 border-b bg-primary text-primary-foreground",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(k,{className:"h-5 w-5"}),e.jsx("h3",{className:"font-semibold",children:"BuildHome.ai Assistant"})]}),e.jsx(c,{variant:"ghost",size:"icon",onClick:()=>y(!1),className:"text-primary-foreground hover:bg-primary-foreground/20",children:e.jsx(M,{className:"h-4 w-4"})})]}),I?e.jsxs("div",{className:"flex-1 p-4 space-y-4 overflow-auto",children:[e.jsx("h4",{className:"font-semibold",children:"Schedule Demo / Contact Us"}),e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{children:[e.jsx(i,{htmlFor:"firstName",children:"First Name *"}),e.jsx(m,{id:"firstName",value:a.firstName,onChange:s=>l({...a,firstName:s.target.value}),placeholder:"John"})]}),e.jsxs("div",{children:[e.jsx(i,{htmlFor:"lastName",children:"Last Name *"}),e.jsx(m,{id:"lastName",value:a.lastName,onChange:s=>l({...a,lastName:s.target.value}),placeholder:"Doe"})]}),e.jsxs("div",{children:[e.jsx(i,{htmlFor:"email",children:"Email *"}),e.jsx(m,{id:"email",type:"email",value:a.email,onChange:s=>l({...a,email:s.target.value}),placeholder:"[email protected]"})]}),e.jsxs("div",{children:[e.jsx(i,{htmlFor:"phone",children:"Phone"}
1),e.jsx(m,{id:"phone",value:a.phone,onChange:s=>l({...a,phone:s.target.value}),placeholder:"+1 (555) 000-0000"})]}),e.jsxs("div",{children:[e.jsx(i,{children:"I want to:"}),e.jsxs(T,{value:a.interestType,onValueChange:s=>l({...a,interestType:s}),children:[e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(N,{value:"learn_more",id:"learn"}),e.jsx(i,{htmlFor:"learn",children:"Learn More"})]}),e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(N,{value:"schedule_demo",id:"demo"}),e.jsx(i,{htmlFor:"demo",children:"Schedule Demo"})]}),e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(N,{value:"contact_sales",id:"sales"}),e.jsx(i,{htmlFor:"sales",children:"Contact Sales"})]})]})]})]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsxs(c,{onClick:F,className:"flex-1",children:[e.jsx(O,{className:"h-4 w-4 mr-2"}),"Submit"]}),e.jsx(c,{variant:"outline",onClick:()=>j(!1),children:"Back"})]})]}):e.jsxs(e.Fragment,{children:[e.jsx(L,{className:"flex-1 p-4",ref:h,children:e.jsxs("div",{className:"space-y-4",children:[p.map((s,t)=>e.jsx("div",{className:`flex ${s.role==="user"?"justify-end":"justify-start"}`,children:e.jsx("div",{className:`max-w-[80%] rounded-lg p-3 ${s.role==="user"?"bg-primary text-primary-foreground":"bg-muted"}`,children:e.jsx("p",{className:"text-sm whitespace-pre-wrap",children:s.content})})},t)),x&&e.jsx("div",{className:"flex justify-start",children:e.jsx("div",{className:"bg-muted rounded-lg p-3",children:e.jsx(R,{className:"h-4 w-4 animate-spin"})})})]})}),e.jsx("div",{className:"p-4 border-t",children:e.jsxs("div",{className:"flex gap-2",children:[e.jsx(m,{value:o,onChange:s=>w(s.target.value),onKeyDown:s=>s.key==="Enter"&&C(),placeholder:"Ask me anything...",disabled:x}),e.jsx(c,{onClick:C,disabled:x||!o.trim(),children:e.jsx(A,{className:"h-4 w-4"})})]})})]})]}):e.jsx(c,{onClick:()=>y(!0),className:"fixed bottom-6 right-6 h-14 w-14 rounded-full shadow-lg z-50",size:"icon",children:e.jsx(k,{className:"h-6 w-6"})})};export{Z as ChatWidget};

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.