1import{r as l,j as n,B as u,s as b}from"./index-CiYeuz0N.js";import{T as f}from"./textarea-CHfYhtY8.js";import{S as g}from"./send-DIp21oOB.js";function _(t){const[a,i]=l.useState(null);return l.useEffect(()=>{if(!t)return;const e=window.visualViewport,s=()=>i({height:(e==null?void 0:e.height)??window.innerHeight,inset:Math.max(0,window.innerHeight-((e==null?void 0:e.height)??window.innerHeight)-((e==null?void 0:e.offsetTop)??0))});return s(),e==null||e.addEventListener("resize",s),e==null||e.addEventListener("scroll",s),window.addEventListener("resize",s),()=>{e==null||e.removeEventListener("resize",s),e==null||e.removeEventListener("scroll",s),window.removeEventListener("resize",s)}},[t]),a}function E({messages:t,draft:a,onDraft:i,onSend:e,sending:s,error:o,disabled:c=!1,hasMore:w,onEarlier:p,loading:d=!1}){var h;const m=l.useRef(null),x=(h=t.at(-1))==null?void 0:h.id;return l.useEffect(()=>{var r;(r=m.current)==null||r.scrollIntoView({block:"nearest"})},[x]),n.jsxs(n.Fragment,{children:[n.jsxs("div",{className:"min-h-0 flex-1 overflow-y-auto overscroll-contain px-4 py-3",role:"log","aria-label":"Chat messages","aria-live":"polite","aria-relevant":"additions",children:[w&&n.jsx(u,{variant:"ghost",className:"mb-3 min-h-11 w-full",onClick:p,disabled:d,children:"Load earlier messages"}),!t.length&&n.jsx("p",{className:"py-5 text-sm text-slate-500",children:d?"Loading conversationâ¦":"Your conversation will appear here."}),t.map(r=>n.jsxs("div",{className:`mb-4 flex flex-col ${r.sender==="client"?"items-end":"items-start"}`,children:[n.jsxs("p",{className:"mb-1 max-w-full break-words text-xs text-slate-500",children:[r.sender==="admin"?`${r.sender_name} · QCF team`:r.sender_name," ","·"," ",new Date(r.created_at).toLocaleTimeString([],{hour:"numeric",minute:"2-digit"})]}),n.jsx("p",{className:`max-w-[92%] whitespace-pre-wrap break-words rounded-2xl px-3 py-2 text-sm ${r.sender==="client"?"bg-blue-700 text-white":"bg-slate-100 text-slate-900"}`,children:r.body})]},r.id)),n.jsx("div",{ref:m})]}),o&&n.jsx("p",{role:"alert",className:"px-4 py-2 text-sm text-red-700",children:o}),n.jsxs("form",{onSubmit:r=>{r.preventDefault(),e()},className:"flex shrink-0 items-end gap-2 border-t bg-white p-3 pb-[max(0.75rem,env(safe-area-inset-bottom))]",children:[n.jsx(f,{"aria-label":"Your message",placeholder:c?"Reply unavailable right now":"Type your message",value:a,maxLength:2e3,disabled:c||s,onChange:r=>i(r.target.value),className:"min-h-12 max-h-28 resize-none border-slate-300 bg-white text-slate-900 placeholder:text-slate-500 text-base md:text-base",rows:2}),n.jsx(u,{type:"submit",className:"h-12 w-12 shrink-0 bg-blue-700 text-white hover:bg-blue-800",disabled:s||c||!a.trim(),"aria-label":s?"Sending message":"Send message",children:n.jsx(g,{className:"h-5 w-5"})})]})]})}async function N(t){var e;const{data:a,error:i}=await b.functions.invoke("website-chat",{body:t}).catch(()=>{throw new Error("Chat could not connect. Please try again.")});if(i){let s="Chat could not connect. Please try again.";try{const o=await((e=i.context)==null?void 0:e.json());typeof(o==null?void 0:o.error)=="string"&&(s=o.error)}catch{}throw new Error(s)}if(!(a!=null&&a.ok))throw new Error((a==null?void 0:a.error)||"Could not confirm your message. Please retry.");return a}function C(){const t=Array.from(crypto.getRandomValues(new Uint8Array(32)),a=>a.toString(16).padStart(2,"0")).join("");return{threadId:crypto.randomUUID(),token:t}}function L(t,a){const i=new Map(t.map(e=>[e.id,e]));return a.forEach(e=>i.set(e.id,e)),[...i.values()].sort((e,s)=>e.id-s.id)}const S=t=>!!t.last_client_at&&(!t.last_admin_at||Date.parse(t.last_client_at)>Date.parse(t.last_admin_at)),k=t=>t!=null&&t.active_until&&Date.parse(t.active_until)>Date.now()?t.active_admin_name:null;export{E as W,k as a,C as b,L as m,S as n,_ as u,N as w};
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.