1import{r as c,j as e,aq as I,ar as Ee,a4 as Ne,as as Ae,J as le}from"./vendor-react-CSQ4l2Qt.js";import{t as j,B as O}from"./index-BAoGeGy8.js";import{T as je}from"./textarea-B1UIiIRo.js";import{b as _e,a as Se}from"./vendor-router-CCuRhTj0.js";import"./vendor-common-Cpj98o6Y.js";import"./vendor-radix-ZWey7SXZ.js";import"./vendor-query-DKDaiBxq.js";import"./vendor-helmet-D0NSfYc1.js";import"./vendor-icons-BzYMg0rX.js";import"./vendor-markdown-Cz07tREc.js";const de="https://api.namiru.ai/api",H="namiru-live-handoff-access",ue="__cookie_session__",Fe=new Set([401,403,409,410]);let T=null;class A extends Error{constructor(a,t,o){super(o),this.status=a,this.code=t,this.name="LiveHandoffApiError"}}function me(){return typeof window>"u"?null:window.sessionStorage.getItem(H)}function pe(){const s=me();return!s||s===ue?{}:{Authorization:`Bearer ${s}`}}async function xe(s){let a=s.status===410?"expired":"request_failed",t="The request could not be completed.";try{const o=await s.json();a=o.code||a,t=o.message||o.error||t}catch{}return new A(s.status,a,t)}async function F(s,a={}){const t=await fetch(`${de}/public/human-handoff${s}`,{...a,credentials:"omit",headers:{...pe(),...a.body?{"Content-Type":"application/json"}:{},...a.headers}});if(!t.ok)throw await xe(t);return t.json()}function Re(s){typeof window>"u"||window.sessionStorage.setItem(H,s||ue)}function fe(){typeof window>"u"||window.sessionStorage.removeItem(H)}function he(){return!!me()}function Ce(s){if(T?.token===s)return T.promise;const a=he(),t=F("/exchange",{method:"POST",body:JSON.stringify({token:s})}).then(i=>(Re(i.accessToken),i.thread)).catch(async i=>{const l=i instanceof A?i:null;if(a&&l?.status===409)try{return await be()}catch{}throw l&&Fe.has(l.status)&&fe(),i});T={token:s,promise:t};const o=()=>{T?.promise===t&&(T=null)};return t.then(o,o),t}function be(){return F("/thread")}async function Te(s,a){return F("/reply",{method:"POST",body:JSON.stringify({content:s,message_id:a})})}async function Le(){return F("/extend",{method:"POST",body:JSON.stringify({})})}async function Ie(){return F("/return",{method:"POST"})}async function ke(){return F("/close",{method:"POST"})}function Me(s){let a="message";const t=[];for(const o of s.split(/\r?\n/))o.startsWith("event:")&&(a=o.slice(6).trim()),o.startsWith("data:")&&t.push(o.slice(5).trimStart());if(t.length===0)return null;try{return{event:a,data:JSON.parse(t.join(` 2`))}}catch{return null}}function De(s,a){if(!a||typeof a!="object")return null;const t=a;return s==="error"&&typeof t.code=="string"?{type:"error",code:t.code}:(s==="thread"||t.type==="thread")&&t.thread?{type:"thread",thread:t.thread}:(s==="message"||t.type==="message")&&t.message?{type:"message",message:t.message,state:t.state,revision:typeof t.revision=="number"?t.revision:void 0}:s==="auto_return"||t.type==="auto_return"?{type:"auto_return",autoReturnAt:typeof t.autoReturnAt=="string"?t.autoReturnAt:null,autoReturnMinutes:typeof t.autoReturnMinutes=="number"?t.autoReturnMinutes:void 0}:s==="conversation_state"||t.type==="conversation_state"||t.state?{type:"conversation_state",state:t.state,message:t.message,revision:typeof t.revision=="number"?t.revision:void 0}:null}async function Oe(s){const a=await fetch(`${de}/public/human-handoff/events`,{credentials:"omit",headers:{Accept:"text/event-stream",...pe()},signal:s.signal});if(!a.ok)throw await xe(a);if(!a.body)throw new A(502,"stream_unavailable","Live updates are unavailable.");s.onOpen?.();const t=a.body.getReader(),o=new TextDecoder;let i="";try{for(;!s.signal.aborted;){const{done:l,value:h}=await t.read();if(l)break;i+=o.decode(h,{stream:!0});let d=i.search(/\r?\n\r?\n/);for(;d!==-1;){const w=i.slice(0,d),y=i.slice(d).match(/^\r?\n\r?\n/)?.[0]||` 3 4`;i=i.slice(d+y.length);const x=Me(w);if(x){const v=De(x.event,x.data);v&&s.onEvent(v)}d=i.search(/\r?\n\r?\n/)}}}finally{t.releaseLock()}}const $e={expired:"This link is no longer active",rejected:"This secure session is no longer accepted",used:"This link is no longer active",error:"This link is no longer active"},Be=1500,Pe=3e4,He=8,Ue=1e4,ae="Live updates connected",ie="The visitor is no longer on the page, so this conversation is no longer live. Open the latest owner alert if they become available again.",re="This conversation is no longer available.",Ve="Live updates are already open in another tab or window. Close that view, then reload this page.",We="Your secure session was refused. Open the latest secure link from an owner alert to continue.",
4Ke="Reply links work while the visitor is waiting on your website. This visitor has left the page or the conversation has ended.",M="Namiru Live",oe="AI resumes within about a minute of the countdown reaching zero. Every reply restarts it.",Ye={ai:{label:"AI resumed",detail:"Namiru AI is back"},waiting_human:{label:"Visitor waiting",detail:"AI is paused"},human_active:{label:"Live now",detail:"Your replies appear instantly"},closed_by_human:{label:"Closed",detail:"No more replies can be sent"}};function ze(s){return s==="waiting_human"||s==="human_active"}function D(s,a){if(!a)return s;const t=s.findIndex(i=>i.id===a.id);if(t===-1)return[...s,a];const o=[...s];return o[t]=a,o}function L(s,a,t){return!Number.isSafeInteger(t)||Number(t)<0||!Number.isSafeInteger(s.revision)||s.revision<0?!0:Number(t)>s.revision||t===s.revision&&a===s.state}function ce(s){const a=new Date(s);return Number.isNaN(a.getTime())?"":a.toLocaleTimeString([],{hour:"2-digit",minute:"2-digit"})}function Ge(s){const a=Math.max(0,Math.ceil(s/1e3)),t=a%60,o=Math.floor(a/60),i=o%60,l=Math.floor(o/60),h=String(t).padStart(2,"0");return l>0?`${l}:${String(i).padStart(2,"0")}:${h}`:`${String(i).padStart(2,"0")}:${h}`}function Je(){return e.jsxs("span",{className:"flex-none whitespace-nowrap text-[15px] font-extrabold tracking-[-0.02em] text-[#141A2A] sm:text-base",children:["Namiru",e.jsx("span",{className:"text-[#4E7CF6]",children:" Live"})]})}function qe(){return e.jsx("main",{className:"flex min-h-[100dvh] items-center justify-center bg-[#F4F5FA] px-4 text-[#141A2A]",children:e.jsxs("div",{className:"flex flex-col items-center gap-4 text-center",role:"status",children:[e.jsx(I,{className:"h-7 w-7 animate-spin text-[#4E7CF6] motion-reduce:animate-none"}),e.jsxs("div",{children:[e.jsx("p",{className:"font-semibold",children:"Opening the conversation"}),e.jsx("p",{className:"mt-1 text-sm text-slate-500",children:"Verifying your secure reply link."})]})]})})}function Xe({state:s,detail:a}){return e.jsxs("main",{className:"flex h-[100dvh] min-h-[420px] flex-col overflow-y-auto bg-[#F4F5FA] text-[#141A2A] antialiased","data-testid":"live-access-settled",style:{fontFamily:'-apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif'},children:[e.jsxs("header",{className:"flex w-full flex-none items-center gap-2.5 px-5 py-4 sm:px-7 sm:py-5",children:[e.jsx("img",{src:"/namiru-story-avatar.png",alt:"","aria-hidden":"true",className:"h-7 w-7 flex-none rounded-lg","data-testid":"live-access-avatar"}),e.jsx("span",{className:"text-sm font-bold",children:"Namiru Live"})]}),e.jsx("div",{className:"flex w-full flex-1 items-center justify-center px-3 py-3 sm:px-7 sm:py-4",children:e.jsxs("section",{className:"flex w-full max-w-[400px] flex-col items-center gap-4 roun
4ded-[18px] border border-[#E6E9F2] bg-white px-6 py-8 text-center shadow-[0_12px_40px_rgba(10,14,30,0.08)] sm:px-8 sm:py-9","data-testid":"live-access-card",children:[e.jsx("div",{className:"flex h-14 w-14 flex-none items-center justify-center rounded-[17px] bg-[#FDF6E8] text-[#B07514]","data-testid":"live-access-icon",children:e.jsx(le,{className:"h-[26px] w-[26px]",weight:"duotone","aria-hidden":"true"})}),e.jsxs("div",{className:"flex flex-col gap-1.5",children:[e.jsx("h1",{className:"text-[19px] font-[750] leading-[1.3] tracking-[-0.01em]",children:$e[s]}),e.jsx("p",{className:"text-[13px] leading-[1.55] text-[#6B7386]",children:a})]})]})}),e.jsxs("p",{className:"flex-none px-4 pb-5 pt-4 text-center text-[11px] leading-4 text-[#9AA1B3]",children:["Powered by ",e.jsx("span",{className:"font-semibold text-[#4E7CF6]",children:"Namiru.ai"})]})]})}function Qe(s){const a=s.trim();if(!a||a.length>2048||!/^https?:\/\//i.test(a))return null;try{const t=new URL(a);return t.protocol!=="http:"&&t.protocol!=="https:"||t.username||t.password?null:t}catch{return null}}function Ze(s){const a=[],t=new Set,o=(l,h)=>{const d=Qe(h);if(!d)return;const w=`${d.host.toLowerCase().replace(/^www\./,"")}${d.pathname.replace(/\/+$/,"")}${d.search}`;if(t.has(w))return;t.add(w);const y=d.host.replace(/^www\./i,""),x=`${y}${d.pathname.replace(/\/+$/,"")}`,v=(l||"").replace(/\s+/g," ").trim();a.push({label:!v||/^https?:\/\//i.test(v)?y:v,description:x.length>64?`${x.slice(0,63)}â¦`:x,url:d.href})},i=s.replace(/\[([^\]\n]+)\]\((https?:\/\/[^)\s]+)\)/g,(l,h,d)=>(o(h,d)," "));for(const l of i.match(/https?:\/\/[^\s<>()"'`]+/g)||[])o(null,l.replace(/[.,;:!?]+$/,""));return a.slice(0,3)}function et({link:s}){return e.jsxs("a",{href:s.url,target:"_blank",rel:"noopener noreferrer",className:"mt-1.5 flex w-full items-center justify-between gap-3 rounded-xl border border-[#D6DEF5] bg-white px-[13px] py-[11px] text-left hover:border-[#4E7CF6]",children:[e.jsxs("span",{className:"flex min-w-0 flex-col gap-0.5",children:[e.jsx("span",{className:"text-[13px] font-bold leading-[1.35] text-[#141A2A] [overflow-wrap:anywhere]",children:s.label}),e.jsx("span",{className:"text-[11px] leading-[1.4] text-[#6B7386] [overflow-wrap:anywhere]",children:s.description})]}),e.jsx("span",{"aria-hidden":"true",className:"flex-none text-[17px] text-[#4E7CF6]",children:"â"})]})}function tt({message:s,businessName:a}){if(s.sender==="system"){const i=s.systemAction==="human_handoff_waiting";return e.jsx("div",{className:"flex justify-center py-2","data-sender":"system",children:e.jsx("p",{className:j("max-w-[92%] rounded-xl px-3 py-[5px] text-center text-[11.5px] font-semibold leading-5 [overflow-wrap:anywhere]",i?"bg-[#FDF6E8] text-[#9A600A]":"bg-[#EEF1F8] text-[#6B7386]"),children:s.content})})}const t=s.sender==="human_owner",o=s.sender==="visitor";return e.jsxs("article",{className:j("flex w-full flex-col gap-1",t?"items-end":"items-start"),"data-sender":s.sender,children:[e.jsxs("div",{className:"max-w-[80%] sm:max-w-[70%]",children:[e.jsx("div",{className:j("text-sm leading-[1.5] [overflow-wrap:anywhere] whitespace-pre-wrap","px-[13px] py-2.5 sm:px-[14px]",t&&"rounded-[16px_16px_4px_16px] bg-[#4E7CF6] text-white",o&&"rounded-[16px_16px_16px_4px] border border-[#E6E9F2] bg-white text-[#141A2A]",s.sender==="ai"&&"rounded-[16px_16px_16px_4px] bg-[#EEF1F8] text-[13px] text-[#5A6480]"),children:s.content}),Ze(s.content).map(i=>e.jsx(et,{link:i},i.url))]}),e.jsxs("span",{className:j("flex items-center gap-1 text-[10.5px] text-[#9AA1B3] sm:text-[11px]",t?"pr-1":"pl-1"),children:[t?ce(s.timestamp):`${o?"Visitor":`${a} AI`} · ${ce(s.timestamp)}`,t&&e.jsx("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"#4E7CF6",strokeWidth:"2.5","aria-hidden":"true",children:e.jsx("path",{d:"M2 13l4 4L14 9M9 13.5l3.5 3.5L21 9"})})]})]})}function st({autoReturnAt:s,extendMinutes:a,extending:t,disabled:o,onExtend:i}){const l=c.useMemo(()=>Date.parse(s),[s]),[h,d]=c.useState(()=>Math.max(0,l-Date.now()));if(c.useEffect(()=>{if(Number.isNaN(l))return;const x=()=>d(Math.max(0,l-Date.now()));x();const v=window.setInterval(x,1e3);return()=>window.clearInterval(v)},[l]),Number.isNaN(l))return null;const w=Ge(h),y=h<=6e4;return e.jsxs(e.Fragment,{children:[e.jsxs("span",{className:j("inline-flex items-center gap-[7px] rounded-[10px] border border-[#
4E6E9F2] bg-[#F7F8FC] px-3 py-[7px] text-xs",y?"text-[#9A600A]":"text-[#6B7386]"),"data-testid":"live-timer",title:oe,children:[e.jsx(le,{className:"h-3 w-3 flex-none","aria-hidden":"true"}),e.jsxs("span",{children:["AI takes over in"," ",e.jsx("strong",{className:"font-bold text-[#141A2A] [font-variant-numeric:tabular-nums]","data-testid":"live-countdown",children:w})]})]}),e.jsx(O,{type:"button",variant:"outline",onClick:i,disabled:o||t,"data-testid":"live-extend","aria-label":`Extend by ${a} minutes`,className:"min-h-11 rounded-[8px] border-[#DFE3EE] bg-white px-[11px] text-[11.5px] font-semibold text-[#4E7CF6] hover:border-[#4E7CF6] hover:bg-white hover:text-[#3E6CE6] sm:min-h-0 sm:h-auto sm:border-transparent sm:px-1.5 sm:py-0.5 sm:text-xs",children:t?e.jsx(I,{className:"h-4 w-4 animate-spin motion-reduce:animate-none"}):e.jsxs("span",{children:["+",a," min"]})}),e.jsx("span",{className:"sr-only",children:oe})]})}function pt(){const{token:s}=_e(),a=Se(),[t,o]=c.useState("loading"),[i,l]=c.useState(null),[h,d]=c.useState("This conversation cannot be opened from this link."),[w,y]=c.useState(""),[x,v]=c.useState(!1),[N,k]=c.useState(null),[$,R]=c.useState("Connecting live updates"),[U,S]=c.useState(""),[B,V]=c.useState(0),W=c.useRef(null),K=c.useRef(null),P=c.useRef(null),Y=c.useRef(""),z=c.useRef(new Set),G=c.useRef(new Set),ge=c.useRef(s),J=c.useRef(!1),q=i?.conversation.id,X=c.useCallback(n=>{if(!(typeof window>"u"||typeof Notification>"u")&&Notification.permission==="granted"&&!(document.visibilityState==="visible"&&document.hasFocus())&&!z.current.has(n.id)){z.current.add(n.id);try{const r=new Notification(`New message · ${Y.current||M}`,{body:n.content.slice(0,180),tag:`namiru-live-${n.id}`});r.onclick=()=>{window.focus(),r.close()}}catch{}}},[]),Q=c.useCallback(n=>{if(n.type==="error"){n.code==="expired"||n.code==="handoff_unavailable"?(d(ie),o("expired")):n.code==="not_found"?(d(re),o("error")):R("Live updates were interrupted");return}if(n.type==="thread"){l(r=>!r||L(r.conversation,n.thread.conversation.state,n.thread.conversation.revision)?n.thread:r);return}if(n.type==="auto_return"){l(r=>r&&{...r,autoReturnAt:n.autoReturnAt,...n.autoReturnMinutes?{autoReturnMinutes:n.autoReturnMinutes}:{}});return}n.type==="message"&&n.message.sender==="visitor"&&!G.current.has(n.message.id)&&(G.current.add(n.message.id),typeof document<"u"&&document.visibilityState==="visible"&&document.hasFocus()||V(u=>u+1),X(n.message)),l(r=>{if(!r)return r;if(n.type==="message"){const b=n.state||r.conversation.state,m=L(r.conversation,b,n.revision);return{...r,conversation:m?{...r.conversation,state:b,...n.revision!==void 0?{revision:n.revision}:{}}:r.conversation,messages:D(r.messages,n.message)}}const u=L(r.conversation,n.state,n.revision);return{...r,conversation:u?{...r.conversation,state:n.state,...n.revision!==void 0?{revision:n.revision}:{}}:r.conversation,messages:D(r.messages,n.message)}})},[X]);c.useEffect(()=>{if(J.current)return;J.current=!0;const n=ge.current;(async()=>{try{const u=n?await Ce(n):he()?await be():null;if(!u)throw new A(401,"missing_token","Open the secure link from an owner alert to reply.");l(u),o("ready")}catch(u){const b=u instanceof A?u:null;b?.status===401&&!n&&fe();const m=b?.code||"",g=m==="expired";o(g?"expired":m==="used"||m==="consumed"?"used":"error"),d(g?Ke:b?.message||"Open the secure link from an owner alert and try again.")}})()},[]),c.useEffect(()=>{!s||t==="loading"||a("/live",{replace:!0})},[a,t,s]),c.useEffect(()=>{if(t!=="ready"||!q)return;let n,r=0,u=0;const b=new AbortController,m=()=>{if(b.signal.aborted)return;if(u&&Date.now()-u>=Ue&&(r=0),u=0,r>=He){R("Live updates stopped. Reload this page to reconnect.");return}const C=Math.min(Be*2**r,Pe);r+=1,R(`Reconnecting live updates in ${Math.round(C/1e3)}s`),n=window.setTimeout(g,C)},g=()=>{R("Connecting live updates"),Oe({signal:b.signal,onEvent:Q,onOpen:()=>{u=Date.now(),R(ae)}}).then(m).catch(C=>{const p=C instanceof A?C:null;if(p&&(p.status===410||p.code==="expired"||p.status===409||p.code==="handoff_unavailable")){d(ie),o("expired");return}if(p&&(p.status===401||p.status===403||p.code==="missing_access"||p.co
4de==="invalid_access")){d(We),o("rejected");return}if(p&&(p.status===404||p.code==="not_found")){d(re),o("error");return}if(p&&(p.status===429||p.code==="too_many_streams")){d(Ve),o("error");return}m()})};return g(),()=>{b.abort(),n&&window.clearTimeout(n)}},[Q,q,t]),c.useEffect(()=>{W.current?.scrollIntoView({block:"end",behavior:"smooth"})},[i?.messages.length]),c.useEffect(()=>{Y.current=i?.business.name||""},[i?.business.name]),c.useEffect(()=>{typeof document>"u"||(document.title=B>0?`(${B}) ${M}`:M)},[B]),c.useEffect(()=>{if(typeof document>"u")return;const n=()=>{document.visibilityState==="visible"&&V(0)};return n(),document.addEventListener("visibilitychange",n),window.addEventListener("focus",n),()=>{document.removeEventListener("visibilitychange",n),window.removeEventListener("focus",n),document.title=M}},[]);const _=c.useMemo(()=>i?Ye[i.conversation.state]:null,[i]),E=ze(i?.conversation.state),Z=c.useCallback(()=>{typeof window>"u"||!(typeof window.matchMedia=="function"&&window.matchMedia("(pointer: fine)").matches)&&window.innerWidth<768||K.current?.focus()},[]),ve=async n=>{n.preventDefault();const r=w.trim();if(!r||!E||x)return;v(!0),S("");const u=P.current,b=u?.content===r?u.messageId:globalThis.crypto.randomUUID();P.current={content:r,messageId:b};try{const m=await Te(r,b);P.current=null,y(""),l(g=>g&&{...g,...m.autoReturnAt!==void 0?{autoReturnAt:m.autoReturnAt}:{},conversation:L(g.conversation,m.state,m.revision)?{...g.conversation,state:m.state,revision:m.revision}:g.conversation,messages:D(g.messages,m.message)}),Z()}catch(m){S(m instanceof A?m.message:"Your reply could not be sent. Please try again."),Z()}finally{v(!1)}},we=async()=>{if(!(!i||N||!E)){k("extend"),S("");try{const n=await Le();l(r=>r&&{...r,...typeof n.autoReturnAt=="string"?{autoReturnAt:n.autoReturnAt}:{},...n.autoReturnMinutes?{autoReturnMinutes:n.autoReturnMinutes}:{}})}catch(n){S(n instanceof A?n.message:"The timer could not be extended. Please try again.")}finally{k(null)}}},ee=async n=>{if(!(!i||N)){k(n),S("");try{const r=n==="return"?await Ie():await ke();l(u=>u&&{...u,autoReturnAt:null,conversation:L(u.conversation,r.state,r.revision)?{...u.conversation,state:r.state,revision:r.revision}:u.conversation,messages:D(u.messages,r.message)})}catch(r){S(r instanceof Error?r.message:"The conversation state could not be changed.")}finally{k(null)}}};if(t==="loading")return e.jsx(qe,{});if(t!=="ready"||!i||!_)return e.jsx(Xe,{state:t==="ready"?"error":t,detail:h});const te=i.visitor?.label||i.visitor?.email||i.visitor?.phone||"Website visitor",ye=te.trim().charAt(0).toUpperCase()||"V",se=i.conversation.escalationReason==="low_retrieval_confidence"?"Low answer confidence":"Asked for a human",f=i.conversation.state,ne=i.autoReturnMinutes||20;return e.jsx("main",{className:"min-h-[100dvh] bg-[#F4F5FA] text-[#141A2A] antialiased",children:e.jsxs("div",{className:"mx-auto flex h-[100dvh] w-full max-w-[1280px] flex-col overflow-hidden bg-[#F4F5FA] sm:border-x sm:border-[#E6E9F2]",children:[e.jsxs("header",{className:"flex-none bg-white",children:[e.jsxs("div",{className:"flex h-14 items-center gap-2.5 border-b border-[#E6E9F2] px-3 sm:gap-3 sm:px-6",children:[e.jsx(Je,{}),e.jsxs("span",{role:"status","aria-live":"polite","data-testid":"live-status-pill",className:j("hidden flex-none items-center gap-1.5 rounded-xl px-2.5 py-1 text-[11.5px] font-bold sm:inline-flex",f==="waiting_human"&&"bg-[#FDF6E8] text-[#9A600A]",f==="human_active"&&"bg-[#E9F9F1] text-[#1A9D68]",f==="ai"&&"bg-[#EEF1F8] text-[#4E7CF6]",f==="closed_by_human"&&"bg-[#EEF1F8] text-[#6B7386]"),children:[e.jsx("span",{className:j("h-1.5 w-1.5 rounded-full",f==="waiting_human"&&"bg-[#E8B64C]",f==="human_active"&&"bg-[#22B57A]",f==="ai"&&"bg-[#4E7CF6]",f==="closed_by_human"&&"bg-[#9AA1B3]")}),_.label]}),e.jsxs("div",{className:"ml-auto flex flex-none items-center gap-2 sm:gap-2.5",children:[e.jsxs(O,{type:"button",variant:"outline","aria-label":"Return to AI",className:"min-h-11 gap-1.5 rounded-[9px] border-[#E6E9F2] bg-white px-2.5 text-[12.5px] font-semibold text-[#141A2A] hover:bg-[#F7F8FC] hover:text-[#141A2A] sm:min-h-0 sm:h-auto sm:px-3.5 sm:py-2",disabled:!E||!!N,onClick:()=>void ee("return"),children:[N==="return"?e.jsx(I,{className:"h-4 w-4 animate-spin motion-reduce:animate-none"}):e.jsx(Ee,{className:"h-[13px] w-[13px]"}),e.jsx("span",{className:"sm:hidden",children:"To AI"}),e.jsx("span",{className:"hidden sm:inline",children:"Return to AI"})]}),e.jsxs(O,{type:"button",variant:"outline","aria-label":"End chat",className:"min-h-11 min-w-11 rounded-[9px] border-[#F2D9D9] bg-white px-2.5 text-[12.5px] font-semibold text-[#D64545] hover:bg-[#FDEEEE] hover:text-[#D64545] sm:min-h-0 sm:h-auto sm:min-w-0 sm:px-3.5 sm:py-2",disabled:!E||!!N,onClick:()=>void ee("close"),children:[N==="close"?e.jsx(I,{className:"h-4 w-4 animate-spin motion-reduce:animate-none"}):e.jsx(Ne,{className:"h-4 w-4 sm:hidden"}),e.jsx("span",{className:"hidden sm:inline",children:"End chat"})]})]})]}),e.jsx("div",{className:"flex justify-center border-b border-[#
4E6E9F2] px-3 py-2.5 sm:px-6",children:e.jsxs("div",{className:"flex w-full max-w-[720px] items-center gap-3",children:[e.jsxs("span",{className:"relative flex-none",children:[e.jsx("span",{"aria-hidden":"true",className:"flex h-9 w-9 items-center justify-center rounded-[11px] bg-[#EEF1F8] text-sm font-bold text-[#4E7CF6] sm:h-[38px] sm:w-[38px]",children:ye}),e.jsx("span",{className:j("absolute -bottom-0.5 -right-0.5 h-2.5 w-2.5 rounded-full border-2 border-white",f==="human_active"&&"bg-[#22B57A]",f==="waiting_human"&&"bg-[#E8B64C]",f==="ai"&&"bg-[#4E7CF6]",f==="closed_by_human"&&"bg-[#9AA1B3]")})]}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("h1",{className:"truncate text-[13.5px] font-bold text-[#141A2A] sm:text-sm",children:te}),e.jsxs("p",{className:"truncate text-[11.5px] text-[#6B7386] sm:text-xs","data-testid":"live-visitor-summary",title:`${se} · ${_.label} · ${_.detail}`,children:[e.jsxs("span",{className:"sm:hidden",children:[_.label," · ",_.detail]}),e.jsxs("span",{className:"hidden sm:inline",children:[se," · on ",e.jsx("strong",{className:"font-semibold text-[#141A2A]",children:i.business.name})," · ",_.detail]})]})]})]})}),e.jsx("p",{className:"sr-only","aria-live":"polite",children:$}),$!==ae&&e.jsx("p",{className:"border-b border-[#E6E9F2] bg-[#FDF6E8] px-3 py-1.5 text-center text-[11px] text-[#9A600A]",role:"status",children:$}),U&&e.jsx("p",{className:"border-b border-[#E6E9F2] bg-red-50 px-3 py-2 text-center text-xs text-red-700",role:"alert",children:U})]}),e.jsx("section",{className:"flex min-h-0 flex-1 justify-center overflow-y-auto overscroll-contain bg-[#F7F8FC] px-3 py-4 sm:bg-[#F4F5FA] sm:px-6 sm:py-5","aria-label":"Conversation transcript",role:"log","aria-live":"polite","aria-relevant":"additions text",children:e.jsxs("div",{className:"flex w-full max-w-[720px] flex-col gap-1",children:[i.messages.length>0&&e.jsx("p",{className:"pb-2 text-center text-[11px] font-bold uppercase tracking-[0.06em] text-[#9AA1B3]",children:new Date(i.messages[0].timestamp).toLocaleDateString([],{month:"short",day:"numeric"})}),i.messages.map(n=>e.jsx(tt,{message:n,businessName:i.business.name},n.id)),e.jsx("div",{ref:W})]})}),e.jsxs("div",{className:"flex-none border-t border-[#E6E9F2] bg-white",style:{paddingBottom:"max(0px, env(safe-area-inset-bottom))"},children:[e.jsx("form",{onSubmit:ve,className:"flex justify-center px-3 pt-3 sm:px-6",children:e.jsxs("div",{className:"flex w-full max-w-[720px] items-end gap-2",children:[e.jsx(je,{ref:K,value:w,onChange:n=>y(n.target.value),disabled:!E||x,"aria-label":"Reply to visitor",placeholder:E?`Reply as ${i.business.name}â¦`:f==="ai"?"AI has resumed":"Conversation is closed",rows:1,maxLength:4e3,className:"max-h-32 min-h-11 resize-none rounded-xl border-[#DFE3EE] bg-white px-3.5 py-3 text-base leading-6 text-[#141A2A] shadow-none placeholder:text-[#9AA1B3] focus-visible:border-[#4E7CF6] focus-visible:ring-[3px] focus-visible:ring-[#4E7CF6]/15 sm:text-sm",onKeyDown:n=>{n.key==="Enter"&&!n.shiftKey&&!n.nativeEvent.isComposing&&(n.preventDefault(),n.currentTarget.form?.requestSubmit())}}),e.jsx(O,{type:"submit",size:"icon",disabled:!E||!w.trim()||x,"aria-label":"Send reply",className:"h-11 w-11 flex-none rounded-xl bg-[#4E7CF6] text-white hover:bg-[#3E6CE6]",children:x?e.jsx(I,{className:"h-5 w-5 animate-spin motion-reduce:animate-none"}):e.jsx(Ae,{className:"h-5 w-5",weight:"fill"})})]})}),e.jsx("p",{className:"hidden px-3 pt-2.5 text-center text-[11.5px] text-[#9AA1B3] sm:block",children:"Enter to send · Shift+Enter for a new line"}),e.jsx("div",{className:"flex flex-wrap items-center justify-center gap-2 px-3 pb-3 pt-2 sm:gap-3",children:E&&i.autoReturnAt?e.jsx(st,{autoReturnAt:i.autoReturnAt,extendMinutes:ne,extending:N==="extend",disabled:!!N,onExtend:()=>void we()}):e.jsx("span",{className:"text-[11.5px] text-[#9AA1B3]","data-testid":"live-timer",children:E?`AI takes over after about ${ne} min without a reply`:f==="ai"?"AI is now handling visitor replies":"This conversation is closed"})})]})]})})}export{pt 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.