PageSourceSearch

https://childcare.marketing/assets/AskUsChat-CHdc3ndJ.js

js childcare.marketing collected 2026-10-09 22:38:39 UTC 6,048 bytes, 4 lines download raw bytes

1import{r as l,j as e,a0 as O,m as z,B as W,al as H}from"./index-BYmaKest.js";import{M as B}from"./message-circle-Dv_kued_.js";import{S as G}from"./sparkles-B9hYiTt2.js";import{M as L}from"./index-C5bPKPpW.js";import{L as P}from"./loader-circle-CYTNQNry.js";import{S as D}from"./send-Bgm_gaZX.js";const F="https://ulxlxaokdyosddeaohua.supabase.co/functions/v1/ask-us",U=["How do I fill empty places?","Help me recruit staff","Improve my website","What marketing should I do?"],Q=()=>{const[x,j]=l.useState(!1),[r,f]=l.useState([{role:"assistant",content:"Hi! 👋 I'm your **Childcare Growth Advisor** — here to help you fill places, recruit amazing staff, and grow your setting. What's on your mind today?"}]),[p,N]=l.useState(""),[u,g]=l.useState(!1),h=l.useRef(null),v=l.useRef(null),I=l.useRef(r.length),b=l.useRef(!1);l.useEffect(()=>{if(!h.current)return;const t=r[r.length-1];r.length>I.current&&t?.role==="assistant"&&!b.current?(b.current=!0,requestAnimationFrame(()=>{v.current?.scrollIntoView({behavior:"smooth",block:"start"})})):t?.role==="user"&&(b.current=!1,h.current.scrollTop=h.current.scrollHeight),I.current=r.length},[r,x]);const k=async t=>{const c=(t??p).trim();if(!c||u)return;const T={role:"user",content:c},y=[...r,T];f(y),N(""),g(!0);let S="";try{const d=await fetch(F,{method:"POST",headers:{"Content-Type":"application/json",Authorization:"Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZSIsInJlZiI6InVseGx4YW9rZHlvc2RkZWFvaHVhIiwicm9sZSI6ImFub24iLCJpYXQiOjE3NzMzMjk3NjEsImV4cCI6MjA4ODkwNTc2MX0.UPNI-R9j8mbuaCLjUbK68TwYf5QdpY5GdWGeykIdTws"},body:JSON.stringify({messages:y.map(s=>({role:s.role,content:s.content}))})});if(!d.ok){const s=await d.json().catch(()=>({error:"Something went wrong"}));f(i=>[...i,{role:"assistant",content:s.error||"Sorry, something went wrong. Please try again or call us on **0118 237 0080**."}]),g(!1);return}if(!d.body)throw new Error("No response body");const w=d.body.getReader(),E=new TextDecoder;let o="";const C=s=>{S+=s;const i=S;f(a=>a[a.length-1]?.role==="assistant"&&a.length>y.length?a.map((m,R)=>R===a.length-1?{...m,content:i}:m):[...a,{role:"assistant",content:i}])};let M=!1;for(;!M;){const{done:s,value:i}=await w.read();if(s)break;o+=E.decode(i,{stream:!0});let a;for(;(a=o.indexOf(`
2`))!==-1;){let n=o.slice(0,a);if(o=o.slice(a+1),n.endsWith("\r")&&(n=n.slice(0,-1)),n.startsWith(":")||n.trim()===""||!n.startsWith("data: "))continue;const m=n.slice(6).trim();if(m==="[DONE]"){M=!0;break}try{const A=JSON.parse(m).choices?.[0]?.delta?.content;A&&C(A)}catch{o=n+`
3`+o;break}}}if(o.trim())for(let s of o.split(`
4`)){if(!s||(s.endsWith("\r")&&(s=s.slice(0,-1)),s.startsWith(":")||s.trim()==="")||!s.startsWith("data: "))continue;const i=s.slice(6).trim();if(i!=="[DONE]")try{const n=JSON.parse(i).choices?.[0]?.delta?.content;n&&C(n)}catch{}}}catch(d){console.error("Chat error:",d),f(w=>[...w,{role:"assistant",content:"Sorry, I couldn't connect. Please try again or call us on **0118 237 0080**."}])}g(!1)},J=r.length===1&&r[0].role==="assistant"&&!u;return e.jsxs(e.Fragment,{children:[e.jsx(O,{children:!x&&e.jsx(z.div,{initial:{scale:0},animate:{scale:1},exit:{scale:0},className:"fixed bottom-6 left-6 z-40",children:e.jsx(W,{onClick:()=>j(!0),size:"lg",className:"h-14 w-14 rounded-full shadow-elevated bg-info hover:bg-info/90 p-0",children:e.jsx(B,{className:"h-6 w-6 text-white"})})})}),e.jsx(O,{children:x&&e.jsxs(z.div,{initial:{opacity:0,y:20,scale:.95},animate:{opacity:1,y:0,scale:1},exit:{opacity:0,y:20,scale:.95},className:"fixed bottom-6 left-6 z-50 w-[360px] max-w-[calc(100vw-3rem)] rounded-2xl border border-border bg-card shadow-elevated flex flex-col overflow-hidden",style:{height:"min(540px, calc(100vh - 6rem))"},children:[e.jsxs("div",{className:"flex items-center justify-between bg-secondary px-4 py-3",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(G,{className:"h-5 w-5 text-accent"}),e.jsxs("div",{children:[e.jsx("p",{className:"text-sm font-semibold text-secondary-foreground",children:"Childcare Growth Advisor"}
4),e.jsx("p",{className:"text-xs text-secondary-foreground/60",children:"Your AI Business Growth Partner"})]})]}),e.jsx("button",{onClick:()=>j(!1),className:"text-secondary-foreground/60 hover:text-secondary-foreground",children:e.jsx(H,{className:"h-5 w-5"})})]}),e.jsxs("div",{ref:h,className:"flex-1 overflow-y-auto p-4 space-y-3",children:[r.map((t,c)=>e.jsx("div",{ref:c===r.length-1&&t.role==="assistant"?v:void 0,className:`flex ${t.role==="user"?"justify-end":"justify-start"}`,children:e.jsx("div",{className:`max-w-[85%] rounded-2xl px-4 py-2.5 text-sm ${t.role==="user"?"bg-primary text-primary-foreground rounded-br-md":"bg-muted text-foreground rounded-bl-md"}`,children:t.role==="assistant"?e.jsx("div",{className:"prose prose-sm max-w-none [&>p]:m-0 [&>ul]:mt-1 [&>ul]:mb-0 [&_a]:text-primary [&_a]:underline",children:e.jsx(L,{children:t.content})}):t.content})},c)),J&&e.jsx("div",{className:"flex flex-wrap gap-2 pt-1",children:U.map(t=>e.jsx("button",{onClick:()=>k(t),className:"rounded-full border border-border bg-background px-3 py-1.5 text-xs font-medium text-foreground hover:bg-muted transition-colors",children:t},t))}),u&&r[r.length-1]?.role==="user"&&e.jsx("div",{className:"flex justify-start",children:e.jsx("div",{className:"bg-muted rounded-2xl rounded-bl-md px-4 py-3",children:e.jsx(P,{className:"h-4 w-4 animate-spin text-muted-foreground"})})})]}),e.jsx("div",{className:"border-t border-border p-3",children:e.jsxs("form",{onSubmit:t=>{t.preventDefault(),k()},className:"flex items-center gap-2",children:[e.jsx("input",{type:"text",value:p,onChange:t=>N(t.target.value),placeholder:"Ask about filling places, recruiting, marketing...",className:"flex-1 rounded-xl border border-input bg-background px-3 py-2 text-sm outline-none focus:ring-1 focus:ring-ring",disabled:u}),e.jsx(W,{type:"submit",size:"sm",className:"h-9 w-9 rounded-xl p-0",disabled:u||!p.trim(),children:e.jsx(D,{className:"h-4 w-4"})})]})})]})})]})};export{Q 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.