1import{d as o,j as e,S as D,p as C,dJ as O,aH as H,s as W}from"./index-70yz1Rcc.js";const G=["I'm feeling overwhelmed right now","I can't sleep and my mind is racing","Why do I keep shutting down?","Help me reset â I'm panicking"];function z(){const[n,y]=o.useState([]),[l,j]=o.useState(""),[i,h]=o.useState(!1),[w,g]=o.useState(null),f=o.useRef(null);o.useEffect(()=>{f.current?.scrollTo({top:f.current.scrollHeight,behavior:"smooth"})},[n,i]);async function p(t){const d=t.trim();if(!d||i)return;g(null);const v=[...n,{role:"user",content:d}];y(v),j(""),h(!0);try{const{data:u}=await W.auth.getSession(),N=u.session?.access_token;if(!N){g("The Guide is in demo mode â chat is unavailable without a backend session."),h(!1);return}const x=await fetch("/api/chat-guide",{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${N}`},body:JSON.stringify({messages:v})});if(!x.ok||!x.body){const c=await x.json().catch(()=>({error:"Something went wrong."}));throw new Error(c.error||"Request failed")}const I=x.body.getReader(),R=new TextDecoder;let s="",b="",S=!1;const A=c=>{b+=c,y(m=>{if(!S)return S=!0,[...m,{role:"assistant",content:b}];const r=m.slice();return r[r.length-1]={role:"assistant",content:b},r})};let k=!1;for(;!k;){const{value:c,done:m}=await I.read();if(m)break;s+=R.decode(c,{stream:!0});let r;for(;(r=s.indexOf(` 2`))!==-1;){let a=s.slice(0,r);if(s=s.slice(r+1),a.endsWith("\r")&&(a=a.slice(0,-1)),!a.startsWith("data: "))continue;const T=a.slice(6).trim();if(T==="[DONE]"){k=!0;break}try{const E=JSON.parse(T).choices?.[0]?.delta?.content;E&&A(E)}catch{s=a+` 3`+s;break}}}}catch(u){g(u instanceof Error?u.message:"Something went wrong.")}finally{h(!1)}}return e.jsxs("div",{className:"mx-auto flex max-w-3xl flex-col px-4 py-8 md:py-12",style:{minHeight:"calc(100vh - 80px)"},children:[e.jsxs("header",{className:"mb-6 text-center",children:[e.jsx("div",{className:"mx-auto mb-3 inline-flex h-12 w-12 items-center justify-center rounded-full bg-gradient-to-br from-gold/40 to-accent/40 ring-1 ring-gold/40",children:e.jsx(D,{className:"h-6 w-6 text-gold"})}),e.jsx("h1",{className:"font-display text-4xl tracking-tight md:text-5xl",children:"Recovery Trauma⢠Guide"}),e.jsx("p",{className:"mt-2 text-sm text-muted-foreground",children:"An AI companion for gentle reflection and finding your way around Recovery Traumaâ¢. It is AI, not a person â not a therapist, not medical advice and not a crisis service."})]}),e.jsxs("div",{ref:f,className:"flex-1 space-y-4 overflow-y-auto rounded-2xl border border-border/50 bg-card/50 p-4 md:p-6",children:[n.length===0&&e.jsxs("div",{className:"space-y-4",children:[e.jsx("p",{className:"text-center text-sm text-muted-foreground",children:"Share what's here. There's no wrong way to begin."}),e.jsx("div",{className:"grid gap-2 sm:grid-cols-2",children:G.map(t=>e.jsx("button",{onClick:()=>p(t),className:"rounded-xl border border-border/60 bg-background/60 px-4 py-3 text-start text-sm transition-colors hover:bg-accent hover:text-accent-foreground",children:t},t))})]}),n.map((t,d)=>e.jsx("div",{className:`flex ${t.role==="user"?"justify-end":"justify-start"}`,children:e.jsx("div",{className:`max-w-[85%] whitespace-pre-wrap rounded-2xl px-4 py-3 text-sm leading-relaxed ${t.role==="user"?"bg-gold/20 text-foreground ring-1 ring-gold/30":"bg-secondary/60 text-foreground"}`,children:t.content||e.jsx("span",{className:"opacity-60",children:"â¦"})})},d)),i&&n[n.length-1]?.role==="user"&&e.jsx("div",{className:"flex justify-start",children:e.jsxs("div",{className:"flex items-center gap-2 rounded-2xl bg-secondary/60 px-4 py-3 text-sm text-muted-foreground",children:[e.jsx(C,{className:"h-3.5 w-3.5 animate-spin"}),"gathering a thoughtâ¦"]})}),w&&e.jsx("div",{className:"rounded-xl border border-destructive/40 bg-destructive/10 px-4 py-3 text-sm text-destructive",children:w})]}),e.jsx(O,{className:"mt-3"}),e.jsxs("form",{onSubmit:t=>{t.preventDefault(),p(l)},className:"mt-4 flex items-end gap-2",children:[e.jsx("textarea",{value:l,onChange:t=>j(t.target.value),onKeyDown:t=>{t.key==="Enter"&&!t.shiftKey&&(t.preventDefault(),p(l))},rows:1,placeholder:"What's here right now?",className:"flex-1 resize-none rounded-2xl border border-border/60 bg-background/80 px-4 py-3 text-sm focus:border-gold/60 focus:outline-none focus:ring-1 focus:ring-gold/40",disabled:i}),e.jsx("button",{type:"submit",disabled:i||!l.trim(),className:"btn-gold flex h-11 w-11 items-center justify-center rounded-2xl disabled:opacity-50","aria-label":"Send",children:e.jsx(H,{className:"h-4 w-4"})})]}),e.jsxs("p",{className:"mt-3 text-center text-xs text-muted-foreground",children:["If you're in crisis, please call 988 (US) or visit"," ",e.jsx("a",{href:"/resources",className:"underline",children:"crisis resources"}),"."]})]})}export{z as component}; 4//# sourceMappingURL=guide-CgMSWMwC.js.map
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.