@snf/access-qa-bot 3.5.0-rc.1 → 3.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -35,7 +35,7 @@ var AccessQABot=function(jn){"use strict";var yn,K,ei,Rt,ti,ni,ri,oi,kr,Pr,Cr,ii
35
35
  background-color: #0000001a !important;
36
36
  opacity: 1 !important;
37
37
  }
38
- `),R.createElement("a",{href:t,target:"_blank",rel:"noopener noreferrer",className:"qa-bot-login-button ".concat(o?"qa-bot-header-login-button":""," ").concat(n),style:Object.assign(Object.assign({},s),r),onClick:()=>{i({type:"chatbot_login_clicked",loginUrl:t})}},"Log In"))},ap=()=>R.createElement("div",{className:"user-login-icon",style:{alignItems:"center",justifyContent:"center",width:"30px",height:"30px",borderRadius:"50%",backgroundColor:"var(--primaryColor, #1a5b6e)",marginRight:"5px",display:"flex"},role:"img","aria-label":"User logged in",title:"User logged in"},R.createElement("svg",{width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"white",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",focusable:"false"},R.createElement("path",{d:"M20 21v-2a4 4 0 0 0-4-4H8a4 4 0 0 0-4 4v2"}),R.createElement("circle",{cx:"12",cy:"7",r:"4"}))),Le=[];for(let e=0;e<256;++e)Le.push((e+256).toString(16).slice(1));let Fo;const sp=new Uint8Array(16);var pA={randomUUID:typeof crypto<"u"&&crypto.randomUUID&&crypto.randomUUID.bind(crypto)};function fA(e,t,n){var o;if(pA.randomUUID&&!e)return pA.randomUUID();const r=(e=e||{}).random??((o=e.rng)==null?void 0:o.call(e))??function(){if(!Fo){if(typeof crypto>"u"||!crypto.getRandomValues)throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");Fo=crypto.getRandomValues.bind(crypto)}return Fo(sp)}();if(r.length<16)throw new Error("Random bytes length must be >= 16");return r[6]=15&r[6]|64,r[8]=63&r[8]|128,function(i,s=0){return(Le[i[s+0]]+Le[i[s+1]]+Le[i[s+2]]+Le[i[s+3]]+"-"+Le[i[s+4]]+Le[i[s+5]]+"-"+Le[i[s+6]]+Le[i[s+7]]+"-"+Le[i[s+8]]+Le[i[s+9]]+"-"+Le[i[s+10]]+Le[i[s+11]]+Le[i[s+12]]+Le[i[s+13]]+Le[i[s+14]]+Le[i[s+15]]).toLowerCase()}(r)}function Wt(){return typeof localStorage<"u"&&localStorage.getItem("QA_BOT_DEBUG")==="true"}const Ap="background: #1a5b6e; color: white; padding: 2px 6px; border-radius: 3px;",lp="background: #7c3aed; color: white; padding: 2px 6px; border-radius: 3px;",cp="background: #059669; color: white; padding: 2px 6px; border-radius: 3px;",up="background: #f97316; color: white; padding: 2px 6px; border-radius: 3px;",dp="background: #f59e0b; color: #000; padding: 2px 6px; border-radius: 3px 0 0 3px; font-weight: bold;",pp="background: #fbbf24; color: #000; padding: 2px 6px; border-radius: 0 3px 3px 0;",fp=()=>{Wt()&&console.log("%c QA Bot Core %c v".concat("0.2.32-rc.1"," "),dp,pp)},hr=function(e){if(Wt()){for(var t=arguments.length,n=new Array(t>1?t-1:0),r=1;r<t;r++)n[r-1]=arguments[r];console.log("%c[Session]%c ".concat(e),Ap,"",...n)}},mt=function(e){if(Wt()){for(var t=arguments.length,n=new Array(t>1?t-1:0),r=1;r<t;r++)n[r-1]=arguments[r];console.log("%c[History]%c ".concat(e),lp,"",...n)}},hp=(e,t)=>{Wt()&&console.log("%c[Message]%c ".concat(e),cp,"",t)},gr=function(e){if(Wt()){for(var t=arguments.length,n=new Array(t>1?t-1:0),r=1;r<t;r++)n[r-1]=arguments[r];console.log("%c[Turnstile]%c ".concat(e),up,"",...n)}},zo=function(){console.warn(...arguments)},Re=function(){console.error(...arguments)},hA="qa_bot_session_messages",gA=()=>"qa_bot_session_".concat(fA()),Ln=()=>{try{const e=localStorage.getItem(hA);return e?JSON.parse(e):{}}catch{return{}}},gp=(e,t,n,r,o)=>{const i=Ln();if(!i[e]&&(i[e]={messages:[],startedAt:new Date().toISOString(),preview:""},mt("NEW session created",{sessionId:e.slice(-12)})),i[e].messages.some(l=>l.id===t))return void mt("DUPLICATE message skipped",{sessionId:e.slice(-12),messageId:t.slice(-8),sender:r});const s={id:t,content:n,sender:r,type:o,timestamp:Date.now()};i[e].messages.push(s),mt("MESSAGE added",{sessionId:e.slice(-12),messageId:t.slice(-8),sender:r,totalInSession:i[e].messages.length});const A=i[e].messages,a=A.find(l=>{var c;return l.sender.toLowerCase()==="bot"&&((c=l.content)===null||c===void 0?void 0:c.trim())&&l.content.length>=100});if(a){const l=a.content;i[e].preview=l.slice(0,50)+(l.length>50?"...":"")}else{const l=A.find(c=>{var u;return c.sender.toLowerCase()==="user"&&((u=c.content)===null||u===void 0?void 0:u.trim())});if(l&&!i[e].preview){const c=l.content;i[e].preview=c.slice(0,50)+(c.length>50?"...":"")}}(l=>{var c;const u=()=>Object.values(l).reduce((d,p)=>d+p.messages.length,0);for(;u()>100&&Object.keys(l).length>1;){const d=(c=Object.entries(l).sort((p,h)=>{let[,m]=p,[,f]=h;return new Date(m.startedAt).getTime()-new Date(f.startedAt).getTime()})[0])===null||c===void 0?void 0:c[0];if(!d)break;delete l[d]}localStorage.setItem(hA,JSON.stringify(l))})(i),mt("STORAGE state",{ourSessions:Object.keys(i).length,ourTotalMessages:Object.values(i).reduce((l,c)=>l+c.messages.length,0)})},mA=e=>{var t,n;return(n=(t=Ln()[e])===null||t===void 0?void 0:t.messages.length)!==null&&n!==void 0?n:0},mp=e=>{const t=Ln()[e];return t!=null&&t.startedAt?Date.now()-new Date(t.startedAt).getTime():0},yA=at(void 0),yp=e=>{let{children:t,getSessionId:n,setSessionId:r,resetSession:o,clearResettingFlag:i}=e;return R.createElement(yA.Provider,{value:{getSessionId:n,setSessionId:r,resetSession:o,clearResettingFlag:i}},t)},jo=()=>{const e=et(yA);if(!e)throw new Error("useSession must be used within a SessionProvider");return e},vp=()=>{const[e,t]=te(!1),[n,r]=te([]),[o,i]=te(null),[s,A]=te(0),a=oe(null),l=oe(null),{replaceMessages:c}=Dn(),{toggleTextAreaDisabled:u}=Ha(),{setSessionId:d,getSessionId:p}=jo();$(()=>{var m,f;const b=g=>{a.current&&!a.current.contains(g.target)&&l.current&&!l.current.contains(g.target)&&t(!1)},y=(f=(m=a.current)===null||m===void 0?void 0:m.getRootNode())!==null&&f!==void 0?f:document;return e&&y.addEventListener("mousedown",b),()=>{y.removeEventListener("mousedown",b)}},[e]);const h=m=>{var f;const b=p();if(mt("RESTORE requested",{targetSession:m.slice(-12),currentSession:b==null?void 0:b.slice(-12)}),m===b)return mt("RESTORE skipped - already on this session"),void t(!1);const y=(k=>{var E;return((E=Ln()[k])===null||E===void 0?void 0:E.messages)||[]})(m).filter(k=>{var E;return(E=k.content)===null||E===void 0?void 0:E.trim()});mt("Stored messages from our localStorage",{count:y.length,ids:y.map(k=>k.id.slice(-8))});const g=y.map(k=>({id:k.id,content:k.content,sender:k.sender.toUpperCase(),type:k.type||"string",timestamp:new Date(k.timestamp).toISOString()}));var x;d(m),mt("Session ID updated",{newSession:m.slice(-12)}),c(g),mt("replaceMessages called",{count:g.length}),x=(f=l.current)===null||f===void 0?void 0:f.getRootNode(),setTimeout(()=>{const k=(x||document).querySelector(".rcb-chat-body-container");k&&k.querySelectorAll(".rcb-bot-message").forEach(E=>{var P;let D=E.innerHTML,T=!1;D.includes("](")&&(D=D.replace(/\[([^\]]+)\]\(([^)]+)\)/g,'<a href="$2" target="_blank" rel="noopener noreferrer">$1</a>'),T=!0),D.includes("&lt;a href=")&&(D=D.replace(/&lt;a\s+href=["']([^"']+)["'][^&]*&gt;([^&]+)&lt;\/a&gt;/gi,'<a href="$1" target="_blank" rel="noopener noreferrer">$2</a>'),T=!0),(D.includes("&lt;a ")||!((P=E.textContent)===null||P===void 0)&&P.includes("<a href="))&&(E.textContent||"").includes("<a href=")&&(D=D.replace(/&lt;a\s+href="([^"]+)"[^&]*&gt;([^&]+)&lt;\/a&gt;/gi,'<a href="$1" target="_blank" rel="noopener noreferrer">$2</a>'),T=!0),T&&(E.innerHTML=D)})},50),u(!1),mt("Chat input enabled after restore"),t(!1)};return R.createElement("div",{style:{position:"relative"}},R.createElement("button",{ref:l,className:"history-button",onClick:()=>{if(!e&&(r((()=>{const m=Ln();return Object.entries(m).map(f=>{let[b,y]=f;return Object.assign({sessionId:b},y)}).sort((f,b)=>new Date(b.startedAt).getTime()-new Date(f.startedAt).getTime())})()),l.current)){const m=l.current.closest(".rcb-chat-window");if(m){const f=m.getBoundingClientRect(),b=l.current.getBoundingClientRect();i(f.width+3),A(f.right-b.right-18+4)}}t(!e)},style:{alignItems:"center",justifyContent:"center",width:"30px",height:"30px",borderRadius:"50%",backgroundColor:"var(--primaryColor, #1a5b6e)",marginRight:"18px",display:"flex",border:"none",cursor:"pointer",padding:0},"aria-label":"View chat history",title:"View chat history","aria-expanded":e,"aria-haspopup":"menu"},R.createElement("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"white",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",focusable:"false"},R.createElement("circle",{cx:"12",cy:"12",r:"10"}),R.createElement("polyline",{points:"12 6 12 12 16 14"}))),e&&R.createElement("div",{ref:a,role:"menu",style:{position:"absolute",right:s?"-".concat(s,"px"):"-18px",top:"100%",marginTop:"8px",width:o?"".concat(o,"px"):"550px",backgroundColor:"white",borderRadius:0,borderBottom:"3px solid var(--primaryColor, #1a5b6e)",boxShadow:"0 2px 8px rgba(0, 0, 0, 0.1)",maxHeight:"250px",overflowY:"auto",zIndex:1e3}},n.length===0?R.createElement("div",{style:{padding:"12px 16px",color:"#666",fontSize:"14px",textAlign:"center"}},"No chat history"):n.map(m=>R.createElement("button",{key:m.sessionId,role:"menuitem",onClick:()=>h(m.sessionId),style:{width:"100%",padding:"10px 14px",border:"none",backgroundColor:"transparent",cursor:"pointer",textAlign:"left",display:"flex",flexDirection:"column",gap:"2px",borderBottom:"1px solid #eee"},onMouseEnter:f=>{f.currentTarget.style.backgroundColor="#f5f5f5"},onMouseLeave:f=>{f.currentTarget.style.backgroundColor="transparent"}},R.createElement("span",{style:{fontSize:"14px",color:"#333",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"}},m.preview||"New conversation"),R.createElement("span",{style:{fontSize:"12px",color:"#888"}},(f=>{const b=new Date(f),y=new Date().getTime()-b.getTime(),g=Math.floor(y/864e5);return g===0?b.toLocaleTimeString([],{hour:"2-digit",minute:"2-digit"}):g===1?"Yesterday":g<7?b.toLocaleDateString([],{weekday:"short"}):b.toLocaleDateString([],{month:"short",day:"numeric"})})(m.startedAt))))))};function qo(){return qo=Object.assign?Object.assign.bind():function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var r in n)({}).hasOwnProperty.call(n,r)&&(e[r]=n[r])}return e},qo.apply(null,arguments)}const vA=({width:e=24,height:t=24,color:n="currentColor",children:r,...o})=>R.createElement("svg",qo({xmlns:"http://www.w3.org/2000/svg",width:e,height:t,viewBox:"0 0 24 24",fill:"none",stroke:n,strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",focusable:"false"},o),r),bp=e=>R.createElement(vA,e,R.createElement("path",{d:"M4 4v5h.582m15.356 2A8.001 8.001 0 004.582 9m0 0H9m11 11v-5h-.581m0 0a8.003 8.003 0 01-15.357-2m15.357 2H15"})),wp=()=>{const{restartFlow:e}=or(),{setTextAreaValue:t}=Ha(),{messages:n}=Dn(),{getSessionId:r,resetSession:o,clearResettingFlag:i}=jo(),{trackEvent:s}=uA();return R.createElement("button",{onClick:async()=>{const A=r(),a=A?mA(A):0;s({type:"chatbot_new_chat",previousMessageCount:a}),o(),await t(""),await e(),setTimeout(()=>{i()},100)},tabIndex:0,"aria-label":"New chat conversation",style:{backgroundColor:"var(--primaryColor, #107180)",border:"none",color:"#ffffff",fontSize:"14px",cursor:"pointer",padding:"8px 12px",borderRadius:"4px",transition:"all 0.2s ease",display:"flex",alignItems:"center",gap:"6px",fontWeight:"500"},onMouseEnter:A=>{A.target.style.backgroundColor="var(--secondaryColor, #0d5f6b)"},onMouseLeave:A=>{A.target.style.backgroundColor="var(--primaryColor, #107180)"}},R.createElement(bp,{width:16,height:16}),"New Chat")};function Wo(e){if(typeof e=="string")return e;if(typeof e=="number")return String(e);if(!e)return"";if(Array.isArray(e))return e.map(Wo).join("");if(typeof e=="object"&&e!==null&&"props"in e){const t=e.props;if(t&&"children"in t)return Wo(t.children)}return""}const xp=()=>{const{getSessionId:e}=jo(),t=G(n=>{var r;const o=(r=n.data)===null||r===void 0?void 0:r.message;if(!(o!=null&&o.id))return;const i=o.sender,s=o.type||"string";let A;if(A=typeof o.content=="string"?o.content:Wo(o.content),hp("TRACKED",{id:o.id,sender:i,content:A.substring(0,50)+(A.length>50?"...":"")}),A.includes("rcb-options-container")||!A.trim())return;const a=e();gp(a,o.id,A,i,s)},[e]);return $(()=>(window.addEventListener("rcb-pre-inject-message",t),()=>{window.removeEventListener("rcb-pre-inject-message",t)}),[t]),null},Ep=()=>($(()=>{const e=i=>{if(!["ArrowDown","ArrowUp","ArrowLeft","ArrowRight","Enter"," ","Home","End"].includes(i.key))return;const s=document.activeElement;if(s&&(s.tagName==="INPUT"||s.tagName==="TEXTAREA"||s.contentEditable==="true"||s.classList.contains("rcb-chat-input-textarea")))return;const A=document.querySelector(".rcb-chat-window");if(!A)return;const a=Array.from(A.querySelectorAll(".rcb-message-container, .rcb-bot-message-container, .rcb-user-message-container")).filter(u=>u.offsetParent!==null);if(a.length>0){const u=a[a.length-1].querySelector(".rcb-checkbox-container");if(u&&u.offsetParent!==null){const d=Array.from(u.querySelectorAll(".rcb-checkbox-row-container")),p=u.querySelector(".rcb-checkbox-next-button");if(d.length>0){const h=[...d];return p&&h.push(p),void((m,f)=>{m.preventDefault();let b=-1;for(let g=0;g<f.length;g++)if(f[g]===document.activeElement||f[g].contains(document.activeElement)){b=g;break}b===-1&&(b=0);let y=b;switch(m.key){case"ArrowDown":case"ArrowRight":y=b<f.length-1?b+1:0;break;case"ArrowUp":case"ArrowLeft":y=b>0?b-1:f.length-1;break;case"Home":y=0;break;case"End":y=f.length-1;break;case"Enter":case" ":{const g=f[b],x=new MouseEvent("mousedown",{bubbles:!0,cancelable:!0,view:window});return void g.dispatchEvent(x)}default:return}f[y].focus(),f[y].setAttribute("tabindex","0"),f[y].classList.add("keyboard-focused"),f.forEach((g,x)=>{x!==y&&(g.setAttribute("tabindex","-1"),g.classList.remove("keyboard-focused"))})})(i,h)}}}let l=[];if(a.length>0){const u=a[a.length-1],d=Array.from(u.querySelectorAll(".rcb-options-container")).filter(p=>p.offsetParent!==null);if(d.length>0){const p=d[d.length-1];l=Array.from(p.querySelectorAll(".rcb-options"))}}if(l.length===0)return;const c=l.findIndex(u=>u===document.activeElement);switch(i.key){case"ArrowDown":case"ArrowRight":{let u;i.preventDefault(),u=c<l.length-1?c+1:0,l[u].setAttribute("tabindex","0"),l.forEach((d,p)=>{p!==u&&(d.setAttribute("tabindex","-1"),d.classList.remove("keyboard-focused"))}),l[u].classList.add("keyboard-focused"),l[u].focus();break}case"ArrowUp":case"ArrowLeft":{let u;i.preventDefault(),u=c>0?c-1:l.length-1,l[u].setAttribute("tabindex","0"),l.forEach((d,p)=>{p!==u&&(d.setAttribute("tabindex","-1"),d.classList.remove("keyboard-focused"))}),l[u].classList.add("keyboard-focused"),l[u].focus();break}case"Enter":case" ":if(i.preventDefault(),document.activeElement&&l.includes(document.activeElement)){const u=document.activeElement;if(u.classList.contains("rcb-checkbox-row-container")||u.closest(".rcb-checkbox-row-container")){const d=new MouseEvent("mousedown",{bubbles:!0,cancelable:!0,view:window});u.dispatchEvent(d);const p=u.querySelector(".rcb-checkbox-label"),h=p?p.textContent:u.textContent||"checkbox",m=u.querySelector(".rcb-checkbox-mark"),f=m&&m.style.backgroundColor?"checked":"unchecked";t(`${h} ${f}`)}else{const d=new MouseEvent("mousedown",{bubbles:!0,cancelable:!0,view:window});u.dispatchEvent(d);const p=u.textContent||u.innerText;t(`Selected: ${p}`)}}break;case"Home":i.preventDefault(),l.length>0&&(l[0].setAttribute("tabindex","0"),l.forEach((u,d)=>{d!==0&&(u.setAttribute("tabindex","-1"),u.classList.remove("keyboard-focused"))}),l[0].classList.add("keyboard-focused"),l[0].focus());break;case"End":if(i.preventDefault(),l.length>0){const u=l.length-1;l[u].setAttribute("tabindex","0"),l.forEach((d,p)=>{p!==u&&(d.setAttribute("tabindex","-1"),d.classList.remove("keyboard-focused"))}),l[u].classList.add("keyboard-focused"),l[u].focus()}}},t=i=>{const s=document.createElement("div");s.setAttribute("aria-live","assertive"),s.setAttribute("aria-atomic","true"),s.className="sr-only",s.textContent=i,document.body.appendChild(s),setTimeout(()=>{document.body.contains(s)&&document.body.removeChild(s)},1e3)},n=(i=null)=>{let s=i;if(s||(s=document.querySelector(".rcb-chat-window"),s||(s=document.querySelector('[class*="rcb-chat"]')),s||(s=document.querySelector(".qa-bot"))),!s)return;const A=s.closest(".embedded-qa-bot")!==null,a=Array.from(s.querySelectorAll(".rcb-message-container, .rcb-bot-message-container, .rcb-user-message-container")).filter(d=>d.offsetParent!==null);if(a.length===0)return;const l=a[a.length-1],c=Array.from(l.querySelectorAll(".rcb-options-container")).filter(d=>d.offsetParent!==null);let u=[];if(c.length>0){const d=c[c.length-1];u=Array.from(d.querySelectorAll(".rcb-options"))}if(u.length===0){let d=l.querySelector(".rcb-checkbox-container");if(!d&&s&&(d=s.querySelector(".rcb-checkbox-container")),d&&d.offsetParent!==null){const p=Array.from(d.querySelectorAll(".rcb-checkbox-row-container")).filter(h=>h.offsetParent!==null&&h.style.display!=="none");if(p.length>0){const h=d.querySelector(".rcb-checkbox-next-button"),m=[...p];if(h&&h.offsetParent!==null&&m.push(h),m.forEach((f,b)=>{f.setAttribute("tabindex",b===0?"0":"-1"),b===0?f.classList.add("keyboard-focused"):f.classList.remove("keyboard-focused")}),p.length>1){d.querySelectorAll(".keyboard-nav-hint").forEach(b=>b.remove());const f=document.createElement("div");f.className="keyboard-nav-hint",f.textContent="Use arrow keys ↕ to navigate, Enter to select/deselect, or click any option",f.style.cssText="font-size: 12px !important; color: #666 !important; margin-bottom: 8px !important; font-style: italic !important; display: block !important;",d.insertBefore(f,d.firstChild)}return void setTimeout(()=>{m[0]&&m[0].offsetParent!==null&&!A&&m[0].focus()},150)}}}if(u.length>0){if(u.forEach((d,p)=>{const h=p===0?"0":"-1";d.setAttribute("tabindex",h),d.setAttribute("role","option"),d.setAttribute("aria-posinset",p+1),d.setAttribute("aria-setsize",u.length),p===0?d.classList.add("keyboard-focused"):d.classList.remove("keyboard-focused")}),u.length>1){const d=c.length>0?c[c.length-1]:null;if(d){d.querySelectorAll(".keyboard-nav-hint").forEach(h=>h.remove());const p=document.createElement("div");p.className="keyboard-nav-hint",p.textContent="Use arrow keys ↕ to navigate, Enter to select, or click any option",p.style.cssText="font-size: 12px !important; color: #666 !important; margin-bottom: 8px !important; font-style: italic !important; display: block !important;",d.insertBefore(p,d.firstChild)}}else{const d=c.length>0?c[c.length-1]:null;d&&d.querySelectorAll(".keyboard-nav-hint").forEach(p=>p.remove())}setTimeout(()=>{u[0]&&u[0].offsetParent!==null&&!A&&(u[0].focus(),u.length>1&&t(`${u.length} options available. Use arrow keys to navigate.`))},200)}},r=new MutationObserver(i=>{i.forEach(s=>{var A,a;if(s.type==="childList"){const l=Array.from(s.addedNodes),c=l.some(d=>{var p,h,m,f;return d.nodeType===Node.ELEMENT_NODE&&(((p=d.classList)==null?void 0:p.contains("rcb-options-container"))||((h=d.classList)==null?void 0:h.contains("rcb-options"))||((m=d.querySelector)==null?void 0:m.call(d,".rcb-options-container"))||((f=d.querySelector)==null?void 0:f.call(d,".rcb-options")))}),u=l.some(d=>{var p,h;return d.nodeType===Node.ELEMENT_NODE&&(((p=d.classList)==null?void 0:p.contains("rcb-checkbox-container"))||((h=d.querySelector)==null?void 0:h.call(d,".rcb-checkbox-container")))});if(c||u){let d=s.target;for(;d&&!((A=d.classList)!=null&&A.contains("qa-bot"))&&!((a=d.classList)!=null&&a.contains("rcb-chat-window"));)d=d.parentElement;(d||document).querySelectorAll(".rcb-options[tabindex], .rcb-checkbox-row-container[tabindex], .rcb-checkbox-next-button[tabindex]").forEach(p=>{p.setAttribute("tabindex","-1"),p.classList.remove("keyboard-focused")}),setTimeout(()=>n(d),100)}}})});r.observe(document.body,{childList:!0,subtree:!0}),document.addEventListener("keydown",e),n();const o=setInterval(()=>{document.querySelectorAll(".qa-bot").forEach(i=>{const s=i.querySelectorAll(".rcb-options-container .rcb-options").length>0,A=i.querySelectorAll(".rcb-checkbox-row-container").length>0;if(s){const a=i.querySelectorAll(".rcb-options[tabindex]").length;i.querySelectorAll(".rcb-options").length>a&&n(i)}if(A){const a=i.querySelectorAll(".rcb-checkbox-row-container[tabindex]").length;i.querySelectorAll(".rcb-checkbox-row-container").length>a&&n(i)}})},1e3);return()=>{document.removeEventListener("keydown",e),r.disconnect(),clearInterval(o)}},[]),null);let bA=!1,mr=null;function wA(){return bA?Promise.resolve():mr||(mr=new Promise((e,t)=>{const n=document.createElement("script");n.src="https://challenges.cloudflare.com/turnstile/v0/api.js?render=explicit",n.async=!0,n.onload=()=>{bA=!0,gr("Script loaded"),e()},n.onerror=()=>{mr=null,t(new Error("Failed to load Turnstile script"))},document.head.appendChild(n)}),mr)}const Rn=e=>{if(!e||typeof e!="string")return e;let t=e.replace(/\[(https?:\/\/[^\s]+?)\]/gi,"[$1]($1)");return t=t.replace(new RegExp(`(?<!\\]\\(|href=["']|\\[)https?:\\/\\/[^\\s[\\]()]+`,"gi"),n=>{let r=n,o="";const i=r.match(/([.,;:!?]+)$/);return i&&(o=i[1],r=r.slice(0,-o.length)),"[".concat(r,"](").concat(r,")").concat(o)}),t},_p=e=>{let{siteKey:t,onVerify:n,onError:r}=e;const o=oe(null),i=oe(!1);return $(()=>{!i.current&&o.current&&(i.current=!0,wA().then(()=>{const s=window.turnstile;if(!s||!o.current)return Re("Turnstile API not available after script load"),void(r==null||r());s.render(o.current,{sitekey:t,callback:A=>{gr("Visible challenge completed"),n(A)},"error-callback":()=>{Re("Turnstile challenge failed"),r==null||r()},"expired-callback":()=>{Re("Turnstile token expired"),r==null||r()}})}).catch(s=>{Re("Failed to load Turnstile script:",s),r==null||r()}))},[t,n,r]),R.createElement("div",{style:{padding:"8px 16px"}},R.createElement("div",{ref:o,style:{borderRadius:"8px",overflow:"hidden"}}))};function xA(e){const{confidence:t,tools_used:n,metadata:r}=e;if(!(t||n&&n.length!==0))return"";const o=[];return t&&o.push("• Confidence: ".concat(t)),n&&n.length>0&&o.push("• Tools used: ".concat(n.join(", "))),r!=null&&r.agent&&o.push("• Agent: ".concat(r.agent)),`---
38
+ `),R.createElement("a",{href:t,target:"_blank",rel:"noopener noreferrer",className:"qa-bot-login-button ".concat(o?"qa-bot-header-login-button":""," ").concat(n),style:Object.assign(Object.assign({},s),r),onClick:()=>{i({type:"chatbot_login_clicked",loginUrl:t})}},"Log In"))},ap=()=>R.createElement("div",{className:"user-login-icon",style:{alignItems:"center",justifyContent:"center",width:"30px",height:"30px",borderRadius:"50%",backgroundColor:"var(--primaryColor, #1a5b6e)",marginRight:"5px",display:"flex"},role:"img","aria-label":"User logged in",title:"User logged in"},R.createElement("svg",{width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"white",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",focusable:"false"},R.createElement("path",{d:"M20 21v-2a4 4 0 0 0-4-4H8a4 4 0 0 0-4 4v2"}),R.createElement("circle",{cx:"12",cy:"7",r:"4"}))),Le=[];for(let e=0;e<256;++e)Le.push((e+256).toString(16).slice(1));let Fo;const sp=new Uint8Array(16);var pA={randomUUID:typeof crypto<"u"&&crypto.randomUUID&&crypto.randomUUID.bind(crypto)};function fA(e,t,n){var o;if(pA.randomUUID&&!e)return pA.randomUUID();const r=(e=e||{}).random??((o=e.rng)==null?void 0:o.call(e))??function(){if(!Fo){if(typeof crypto>"u"||!crypto.getRandomValues)throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");Fo=crypto.getRandomValues.bind(crypto)}return Fo(sp)}();if(r.length<16)throw new Error("Random bytes length must be >= 16");return r[6]=15&r[6]|64,r[8]=63&r[8]|128,function(i,s=0){return(Le[i[s+0]]+Le[i[s+1]]+Le[i[s+2]]+Le[i[s+3]]+"-"+Le[i[s+4]]+Le[i[s+5]]+"-"+Le[i[s+6]]+Le[i[s+7]]+"-"+Le[i[s+8]]+Le[i[s+9]]+"-"+Le[i[s+10]]+Le[i[s+11]]+Le[i[s+12]]+Le[i[s+13]]+Le[i[s+14]]+Le[i[s+15]]).toLowerCase()}(r)}function Wt(){return typeof localStorage<"u"&&localStorage.getItem("QA_BOT_DEBUG")==="true"}const Ap="background: #1a5b6e; color: white; padding: 2px 6px; border-radius: 3px;",lp="background: #7c3aed; color: white; padding: 2px 6px; border-radius: 3px;",cp="background: #059669; color: white; padding: 2px 6px; border-radius: 3px;",up="background: #f97316; color: white; padding: 2px 6px; border-radius: 3px;",dp="background: #f59e0b; color: #000; padding: 2px 6px; border-radius: 3px 0 0 3px; font-weight: bold;",pp="background: #fbbf24; color: #000; padding: 2px 6px; border-radius: 0 3px 3px 0;",fp=()=>{Wt()&&console.log("%c QA Bot Core %c v".concat("0.2.32"," "),dp,pp)},hr=function(e){if(Wt()){for(var t=arguments.length,n=new Array(t>1?t-1:0),r=1;r<t;r++)n[r-1]=arguments[r];console.log("%c[Session]%c ".concat(e),Ap,"",...n)}},mt=function(e){if(Wt()){for(var t=arguments.length,n=new Array(t>1?t-1:0),r=1;r<t;r++)n[r-1]=arguments[r];console.log("%c[History]%c ".concat(e),lp,"",...n)}},hp=(e,t)=>{Wt()&&console.log("%c[Message]%c ".concat(e),cp,"",t)},gr=function(e){if(Wt()){for(var t=arguments.length,n=new Array(t>1?t-1:0),r=1;r<t;r++)n[r-1]=arguments[r];console.log("%c[Turnstile]%c ".concat(e),up,"",...n)}},zo=function(){console.warn(...arguments)},Re=function(){console.error(...arguments)},hA="qa_bot_session_messages",gA=()=>"qa_bot_session_".concat(fA()),Ln=()=>{try{const e=localStorage.getItem(hA);return e?JSON.parse(e):{}}catch{return{}}},gp=(e,t,n,r,o)=>{const i=Ln();if(!i[e]&&(i[e]={messages:[],startedAt:new Date().toISOString(),preview:""},mt("NEW session created",{sessionId:e.slice(-12)})),i[e].messages.some(l=>l.id===t))return void mt("DUPLICATE message skipped",{sessionId:e.slice(-12),messageId:t.slice(-8),sender:r});const s={id:t,content:n,sender:r,type:o,timestamp:Date.now()};i[e].messages.push(s),mt("MESSAGE added",{sessionId:e.slice(-12),messageId:t.slice(-8),sender:r,totalInSession:i[e].messages.length});const A=i[e].messages,a=A.find(l=>{var c;return l.sender.toLowerCase()==="bot"&&((c=l.content)===null||c===void 0?void 0:c.trim())&&l.content.length>=100});if(a){const l=a.content;i[e].preview=l.slice(0,50)+(l.length>50?"...":"")}else{const l=A.find(c=>{var u;return c.sender.toLowerCase()==="user"&&((u=c.content)===null||u===void 0?void 0:u.trim())});if(l&&!i[e].preview){const c=l.content;i[e].preview=c.slice(0,50)+(c.length>50?"...":"")}}(l=>{var c;const u=()=>Object.values(l).reduce((d,p)=>d+p.messages.length,0);for(;u()>100&&Object.keys(l).length>1;){const d=(c=Object.entries(l).sort((p,h)=>{let[,m]=p,[,f]=h;return new Date(m.startedAt).getTime()-new Date(f.startedAt).getTime()})[0])===null||c===void 0?void 0:c[0];if(!d)break;delete l[d]}localStorage.setItem(hA,JSON.stringify(l))})(i),mt("STORAGE state",{ourSessions:Object.keys(i).length,ourTotalMessages:Object.values(i).reduce((l,c)=>l+c.messages.length,0)})},mA=e=>{var t,n;return(n=(t=Ln()[e])===null||t===void 0?void 0:t.messages.length)!==null&&n!==void 0?n:0},mp=e=>{const t=Ln()[e];return t!=null&&t.startedAt?Date.now()-new Date(t.startedAt).getTime():0},yA=at(void 0),yp=e=>{let{children:t,getSessionId:n,setSessionId:r,resetSession:o,clearResettingFlag:i}=e;return R.createElement(yA.Provider,{value:{getSessionId:n,setSessionId:r,resetSession:o,clearResettingFlag:i}},t)},jo=()=>{const e=et(yA);if(!e)throw new Error("useSession must be used within a SessionProvider");return e},vp=()=>{const[e,t]=te(!1),[n,r]=te([]),[o,i]=te(null),[s,A]=te(0),a=oe(null),l=oe(null),{replaceMessages:c}=Dn(),{toggleTextAreaDisabled:u}=Ha(),{setSessionId:d,getSessionId:p}=jo();$(()=>{var m,f;const b=g=>{a.current&&!a.current.contains(g.target)&&l.current&&!l.current.contains(g.target)&&t(!1)},y=(f=(m=a.current)===null||m===void 0?void 0:m.getRootNode())!==null&&f!==void 0?f:document;return e&&y.addEventListener("mousedown",b),()=>{y.removeEventListener("mousedown",b)}},[e]);const h=m=>{var f;const b=p();if(mt("RESTORE requested",{targetSession:m.slice(-12),currentSession:b==null?void 0:b.slice(-12)}),m===b)return mt("RESTORE skipped - already on this session"),void t(!1);const y=(k=>{var E;return((E=Ln()[k])===null||E===void 0?void 0:E.messages)||[]})(m).filter(k=>{var E;return(E=k.content)===null||E===void 0?void 0:E.trim()});mt("Stored messages from our localStorage",{count:y.length,ids:y.map(k=>k.id.slice(-8))});const g=y.map(k=>({id:k.id,content:k.content,sender:k.sender.toUpperCase(),type:k.type||"string",timestamp:new Date(k.timestamp).toISOString()}));var x;d(m),mt("Session ID updated",{newSession:m.slice(-12)}),c(g),mt("replaceMessages called",{count:g.length}),x=(f=l.current)===null||f===void 0?void 0:f.getRootNode(),setTimeout(()=>{const k=(x||document).querySelector(".rcb-chat-body-container");k&&k.querySelectorAll(".rcb-bot-message").forEach(E=>{var P;let D=E.innerHTML,T=!1;D.includes("](")&&(D=D.replace(/\[([^\]]+)\]\(([^)]+)\)/g,'<a href="$2" target="_blank" rel="noopener noreferrer">$1</a>'),T=!0),D.includes("&lt;a href=")&&(D=D.replace(/&lt;a\s+href=["']([^"']+)["'][^&]*&gt;([^&]+)&lt;\/a&gt;/gi,'<a href="$1" target="_blank" rel="noopener noreferrer">$2</a>'),T=!0),(D.includes("&lt;a ")||!((P=E.textContent)===null||P===void 0)&&P.includes("<a href="))&&(E.textContent||"").includes("<a href=")&&(D=D.replace(/&lt;a\s+href="([^"]+)"[^&]*&gt;([^&]+)&lt;\/a&gt;/gi,'<a href="$1" target="_blank" rel="noopener noreferrer">$2</a>'),T=!0),T&&(E.innerHTML=D)})},50),u(!1),mt("Chat input enabled after restore"),t(!1)};return R.createElement("div",{style:{position:"relative"}},R.createElement("button",{ref:l,className:"history-button",onClick:()=>{if(!e&&(r((()=>{const m=Ln();return Object.entries(m).map(f=>{let[b,y]=f;return Object.assign({sessionId:b},y)}).sort((f,b)=>new Date(b.startedAt).getTime()-new Date(f.startedAt).getTime())})()),l.current)){const m=l.current.closest(".rcb-chat-window");if(m){const f=m.getBoundingClientRect(),b=l.current.getBoundingClientRect();i(f.width+3),A(f.right-b.right-18+4)}}t(!e)},style:{alignItems:"center",justifyContent:"center",width:"30px",height:"30px",borderRadius:"50%",backgroundColor:"var(--primaryColor, #1a5b6e)",marginRight:"18px",display:"flex",border:"none",cursor:"pointer",padding:0},"aria-label":"View chat history",title:"View chat history","aria-expanded":e,"aria-haspopup":"menu"},R.createElement("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"white",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",focusable:"false"},R.createElement("circle",{cx:"12",cy:"12",r:"10"}),R.createElement("polyline",{points:"12 6 12 12 16 14"}))),e&&R.createElement("div",{ref:a,role:"menu",style:{position:"absolute",right:s?"-".concat(s,"px"):"-18px",top:"100%",marginTop:"8px",width:o?"".concat(o,"px"):"550px",backgroundColor:"white",borderRadius:0,borderBottom:"3px solid var(--primaryColor, #1a5b6e)",boxShadow:"0 2px 8px rgba(0, 0, 0, 0.1)",maxHeight:"250px",overflowY:"auto",zIndex:1e3}},n.length===0?R.createElement("div",{style:{padding:"12px 16px",color:"#666",fontSize:"14px",textAlign:"center"}},"No chat history"):n.map(m=>R.createElement("button",{key:m.sessionId,role:"menuitem",onClick:()=>h(m.sessionId),style:{width:"100%",padding:"10px 14px",border:"none",backgroundColor:"transparent",cursor:"pointer",textAlign:"left",display:"flex",flexDirection:"column",gap:"2px",borderBottom:"1px solid #eee"},onMouseEnter:f=>{f.currentTarget.style.backgroundColor="#f5f5f5"},onMouseLeave:f=>{f.currentTarget.style.backgroundColor="transparent"}},R.createElement("span",{style:{fontSize:"14px",color:"#333",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"}},m.preview||"New conversation"),R.createElement("span",{style:{fontSize:"12px",color:"#888"}},(f=>{const b=new Date(f),y=new Date().getTime()-b.getTime(),g=Math.floor(y/864e5);return g===0?b.toLocaleTimeString([],{hour:"2-digit",minute:"2-digit"}):g===1?"Yesterday":g<7?b.toLocaleDateString([],{weekday:"short"}):b.toLocaleDateString([],{month:"short",day:"numeric"})})(m.startedAt))))))};function qo(){return qo=Object.assign?Object.assign.bind():function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var r in n)({}).hasOwnProperty.call(n,r)&&(e[r]=n[r])}return e},qo.apply(null,arguments)}const vA=({width:e=24,height:t=24,color:n="currentColor",children:r,...o})=>R.createElement("svg",qo({xmlns:"http://www.w3.org/2000/svg",width:e,height:t,viewBox:"0 0 24 24",fill:"none",stroke:n,strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",focusable:"false"},o),r),bp=e=>R.createElement(vA,e,R.createElement("path",{d:"M4 4v5h.582m15.356 2A8.001 8.001 0 004.582 9m0 0H9m11 11v-5h-.581m0 0a8.003 8.003 0 01-15.357-2m15.357 2H15"})),wp=()=>{const{restartFlow:e}=or(),{setTextAreaValue:t}=Ha(),{messages:n}=Dn(),{getSessionId:r,resetSession:o,clearResettingFlag:i}=jo(),{trackEvent:s}=uA();return R.createElement("button",{onClick:async()=>{const A=r(),a=A?mA(A):0;s({type:"chatbot_new_chat",previousMessageCount:a}),o(),await t(""),await e(),setTimeout(()=>{i()},100)},tabIndex:0,"aria-label":"New chat conversation",style:{backgroundColor:"var(--primaryColor, #107180)",border:"none",color:"#ffffff",fontSize:"14px",cursor:"pointer",padding:"8px 12px",borderRadius:"4px",transition:"all 0.2s ease",display:"flex",alignItems:"center",gap:"6px",fontWeight:"500"},onMouseEnter:A=>{A.target.style.backgroundColor="var(--secondaryColor, #0d5f6b)"},onMouseLeave:A=>{A.target.style.backgroundColor="var(--primaryColor, #107180)"}},R.createElement(bp,{width:16,height:16}),"New Chat")};function Wo(e){if(typeof e=="string")return e;if(typeof e=="number")return String(e);if(!e)return"";if(Array.isArray(e))return e.map(Wo).join("");if(typeof e=="object"&&e!==null&&"props"in e){const t=e.props;if(t&&"children"in t)return Wo(t.children)}return""}const xp=()=>{const{getSessionId:e}=jo(),t=G(n=>{var r;const o=(r=n.data)===null||r===void 0?void 0:r.message;if(!(o!=null&&o.id))return;const i=o.sender,s=o.type||"string";let A;if(A=typeof o.content=="string"?o.content:Wo(o.content),hp("TRACKED",{id:o.id,sender:i,content:A.substring(0,50)+(A.length>50?"...":"")}),A.includes("rcb-options-container")||!A.trim())return;const a=e();gp(a,o.id,A,i,s)},[e]);return $(()=>(window.addEventListener("rcb-pre-inject-message",t),()=>{window.removeEventListener("rcb-pre-inject-message",t)}),[t]),null},Ep=()=>($(()=>{const e=i=>{if(!["ArrowDown","ArrowUp","ArrowLeft","ArrowRight","Enter"," ","Home","End"].includes(i.key))return;const s=document.activeElement;if(s&&(s.tagName==="INPUT"||s.tagName==="TEXTAREA"||s.contentEditable==="true"||s.classList.contains("rcb-chat-input-textarea")))return;const A=document.querySelector(".rcb-chat-window");if(!A)return;const a=Array.from(A.querySelectorAll(".rcb-message-container, .rcb-bot-message-container, .rcb-user-message-container")).filter(u=>u.offsetParent!==null);if(a.length>0){const u=a[a.length-1].querySelector(".rcb-checkbox-container");if(u&&u.offsetParent!==null){const d=Array.from(u.querySelectorAll(".rcb-checkbox-row-container")),p=u.querySelector(".rcb-checkbox-next-button");if(d.length>0){const h=[...d];return p&&h.push(p),void((m,f)=>{m.preventDefault();let b=-1;for(let g=0;g<f.length;g++)if(f[g]===document.activeElement||f[g].contains(document.activeElement)){b=g;break}b===-1&&(b=0);let y=b;switch(m.key){case"ArrowDown":case"ArrowRight":y=b<f.length-1?b+1:0;break;case"ArrowUp":case"ArrowLeft":y=b>0?b-1:f.length-1;break;case"Home":y=0;break;case"End":y=f.length-1;break;case"Enter":case" ":{const g=f[b],x=new MouseEvent("mousedown",{bubbles:!0,cancelable:!0,view:window});return void g.dispatchEvent(x)}default:return}f[y].focus(),f[y].setAttribute("tabindex","0"),f[y].classList.add("keyboard-focused"),f.forEach((g,x)=>{x!==y&&(g.setAttribute("tabindex","-1"),g.classList.remove("keyboard-focused"))})})(i,h)}}}let l=[];if(a.length>0){const u=a[a.length-1],d=Array.from(u.querySelectorAll(".rcb-options-container")).filter(p=>p.offsetParent!==null);if(d.length>0){const p=d[d.length-1];l=Array.from(p.querySelectorAll(".rcb-options"))}}if(l.length===0)return;const c=l.findIndex(u=>u===document.activeElement);switch(i.key){case"ArrowDown":case"ArrowRight":{let u;i.preventDefault(),u=c<l.length-1?c+1:0,l[u].setAttribute("tabindex","0"),l.forEach((d,p)=>{p!==u&&(d.setAttribute("tabindex","-1"),d.classList.remove("keyboard-focused"))}),l[u].classList.add("keyboard-focused"),l[u].focus();break}case"ArrowUp":case"ArrowLeft":{let u;i.preventDefault(),u=c>0?c-1:l.length-1,l[u].setAttribute("tabindex","0"),l.forEach((d,p)=>{p!==u&&(d.setAttribute("tabindex","-1"),d.classList.remove("keyboard-focused"))}),l[u].classList.add("keyboard-focused"),l[u].focus();break}case"Enter":case" ":if(i.preventDefault(),document.activeElement&&l.includes(document.activeElement)){const u=document.activeElement;if(u.classList.contains("rcb-checkbox-row-container")||u.closest(".rcb-checkbox-row-container")){const d=new MouseEvent("mousedown",{bubbles:!0,cancelable:!0,view:window});u.dispatchEvent(d);const p=u.querySelector(".rcb-checkbox-label"),h=p?p.textContent:u.textContent||"checkbox",m=u.querySelector(".rcb-checkbox-mark"),f=m&&m.style.backgroundColor?"checked":"unchecked";t(`${h} ${f}`)}else{const d=new MouseEvent("mousedown",{bubbles:!0,cancelable:!0,view:window});u.dispatchEvent(d);const p=u.textContent||u.innerText;t(`Selected: ${p}`)}}break;case"Home":i.preventDefault(),l.length>0&&(l[0].setAttribute("tabindex","0"),l.forEach((u,d)=>{d!==0&&(u.setAttribute("tabindex","-1"),u.classList.remove("keyboard-focused"))}),l[0].classList.add("keyboard-focused"),l[0].focus());break;case"End":if(i.preventDefault(),l.length>0){const u=l.length-1;l[u].setAttribute("tabindex","0"),l.forEach((d,p)=>{p!==u&&(d.setAttribute("tabindex","-1"),d.classList.remove("keyboard-focused"))}),l[u].classList.add("keyboard-focused"),l[u].focus()}}},t=i=>{const s=document.createElement("div");s.setAttribute("aria-live","assertive"),s.setAttribute("aria-atomic","true"),s.className="sr-only",s.textContent=i,document.body.appendChild(s),setTimeout(()=>{document.body.contains(s)&&document.body.removeChild(s)},1e3)},n=(i=null)=>{let s=i;if(s||(s=document.querySelector(".rcb-chat-window"),s||(s=document.querySelector('[class*="rcb-chat"]')),s||(s=document.querySelector(".qa-bot"))),!s)return;const A=s.closest(".embedded-qa-bot")!==null,a=Array.from(s.querySelectorAll(".rcb-message-container, .rcb-bot-message-container, .rcb-user-message-container")).filter(d=>d.offsetParent!==null);if(a.length===0)return;const l=a[a.length-1],c=Array.from(l.querySelectorAll(".rcb-options-container")).filter(d=>d.offsetParent!==null);let u=[];if(c.length>0){const d=c[c.length-1];u=Array.from(d.querySelectorAll(".rcb-options"))}if(u.length===0){let d=l.querySelector(".rcb-checkbox-container");if(!d&&s&&(d=s.querySelector(".rcb-checkbox-container")),d&&d.offsetParent!==null){const p=Array.from(d.querySelectorAll(".rcb-checkbox-row-container")).filter(h=>h.offsetParent!==null&&h.style.display!=="none");if(p.length>0){const h=d.querySelector(".rcb-checkbox-next-button"),m=[...p];if(h&&h.offsetParent!==null&&m.push(h),m.forEach((f,b)=>{f.setAttribute("tabindex",b===0?"0":"-1"),b===0?f.classList.add("keyboard-focused"):f.classList.remove("keyboard-focused")}),p.length>1){d.querySelectorAll(".keyboard-nav-hint").forEach(b=>b.remove());const f=document.createElement("div");f.className="keyboard-nav-hint",f.textContent="Use arrow keys ↕ to navigate, Enter to select/deselect, or click any option",f.style.cssText="font-size: 12px !important; color: #666 !important; margin-bottom: 8px !important; font-style: italic !important; display: block !important;",d.insertBefore(f,d.firstChild)}return void setTimeout(()=>{m[0]&&m[0].offsetParent!==null&&!A&&m[0].focus()},150)}}}if(u.length>0){if(u.forEach((d,p)=>{const h=p===0?"0":"-1";d.setAttribute("tabindex",h),d.setAttribute("role","option"),d.setAttribute("aria-posinset",p+1),d.setAttribute("aria-setsize",u.length),p===0?d.classList.add("keyboard-focused"):d.classList.remove("keyboard-focused")}),u.length>1){const d=c.length>0?c[c.length-1]:null;if(d){d.querySelectorAll(".keyboard-nav-hint").forEach(h=>h.remove());const p=document.createElement("div");p.className="keyboard-nav-hint",p.textContent="Use arrow keys ↕ to navigate, Enter to select, or click any option",p.style.cssText="font-size: 12px !important; color: #666 !important; margin-bottom: 8px !important; font-style: italic !important; display: block !important;",d.insertBefore(p,d.firstChild)}}else{const d=c.length>0?c[c.length-1]:null;d&&d.querySelectorAll(".keyboard-nav-hint").forEach(p=>p.remove())}setTimeout(()=>{u[0]&&u[0].offsetParent!==null&&!A&&(u[0].focus(),u.length>1&&t(`${u.length} options available. Use arrow keys to navigate.`))},200)}},r=new MutationObserver(i=>{i.forEach(s=>{var A,a;if(s.type==="childList"){const l=Array.from(s.addedNodes),c=l.some(d=>{var p,h,m,f;return d.nodeType===Node.ELEMENT_NODE&&(((p=d.classList)==null?void 0:p.contains("rcb-options-container"))||((h=d.classList)==null?void 0:h.contains("rcb-options"))||((m=d.querySelector)==null?void 0:m.call(d,".rcb-options-container"))||((f=d.querySelector)==null?void 0:f.call(d,".rcb-options")))}),u=l.some(d=>{var p,h;return d.nodeType===Node.ELEMENT_NODE&&(((p=d.classList)==null?void 0:p.contains("rcb-checkbox-container"))||((h=d.querySelector)==null?void 0:h.call(d,".rcb-checkbox-container")))});if(c||u){let d=s.target;for(;d&&!((A=d.classList)!=null&&A.contains("qa-bot"))&&!((a=d.classList)!=null&&a.contains("rcb-chat-window"));)d=d.parentElement;(d||document).querySelectorAll(".rcb-options[tabindex], .rcb-checkbox-row-container[tabindex], .rcb-checkbox-next-button[tabindex]").forEach(p=>{p.setAttribute("tabindex","-1"),p.classList.remove("keyboard-focused")}),setTimeout(()=>n(d),100)}}})});r.observe(document.body,{childList:!0,subtree:!0}),document.addEventListener("keydown",e),n();const o=setInterval(()=>{document.querySelectorAll(".qa-bot").forEach(i=>{const s=i.querySelectorAll(".rcb-options-container .rcb-options").length>0,A=i.querySelectorAll(".rcb-checkbox-row-container").length>0;if(s){const a=i.querySelectorAll(".rcb-options[tabindex]").length;i.querySelectorAll(".rcb-options").length>a&&n(i)}if(A){const a=i.querySelectorAll(".rcb-checkbox-row-container[tabindex]").length;i.querySelectorAll(".rcb-checkbox-row-container").length>a&&n(i)}})},1e3);return()=>{document.removeEventListener("keydown",e),r.disconnect(),clearInterval(o)}},[]),null);let bA=!1,mr=null;function wA(){return bA?Promise.resolve():mr||(mr=new Promise((e,t)=>{const n=document.createElement("script");n.src="https://challenges.cloudflare.com/turnstile/v0/api.js?render=explicit",n.async=!0,n.onload=()=>{bA=!0,gr("Script loaded"),e()},n.onerror=()=>{mr=null,t(new Error("Failed to load Turnstile script"))},document.head.appendChild(n)}),mr)}const Rn=e=>{if(!e||typeof e!="string")return e;let t=e.replace(/\[(https?:\/\/[^\s]+?)\]/gi,"[$1]($1)");return t=t.replace(new RegExp(`(?<!\\]\\(|href=["']|\\[)https?:\\/\\/[^\\s[\\]()]+`,"gi"),n=>{let r=n,o="";const i=r.match(/([.,;:!?]+)$/);return i&&(o=i[1],r=r.slice(0,-o.length)),"[".concat(r,"](").concat(r,")").concat(o)}),t},_p=e=>{let{siteKey:t,onVerify:n,onError:r}=e;const o=oe(null),i=oe(!1);return $(()=>{!i.current&&o.current&&(i.current=!0,wA().then(()=>{const s=window.turnstile;if(!s||!o.current)return Re("Turnstile API not available after script load"),void(r==null||r());s.render(o.current,{sitekey:t,callback:A=>{gr("Visible challenge completed"),n(A)},"error-callback":()=>{Re("Turnstile challenge failed"),r==null||r()},"expired-callback":()=>{Re("Turnstile token expired"),r==null||r()}})}).catch(s=>{Re("Failed to load Turnstile script:",s),r==null||r()}))},[t,n,r]),R.createElement("div",{style:{padding:"8px 16px"}},R.createElement("div",{ref:o,style:{borderRadius:"8px",overflow:"hidden"}}))};function xA(e){const{confidence:t,tools_used:n,metadata:r}=e;if(!(t||n&&n.length!==0))return"";const o=[];return t&&o.push("• Confidence: ".concat(t)),n&&n.length>0&&o.push("• Tools used: ".concat(n.join(", "))),r!=null&&r.agent&&o.push("• Agent: ".concat(r.agent)),`---
39
39
  `.concat(o.join(`
40
40
  `))}function kp(e){let{getState:t,onResubmit:n,trackEvent:r,loginUrl:o}=e;const[i,s]=R.useState(!1),A=t();return R.useEffect(()=>{if(!A.siteKey)return;s(!1);const a=setTimeout(()=>{A.token||(s(!0),r==null||r({type:"chatbot_turnstile_error"}))},5e3);return()=>clearTimeout(a)},[A.siteKey]),A.siteKey?i?R.createElement("div",{style:{padding:"8px 16px",fontSize:"14px",lineHeight:"1.5"}},R.createElement("p",{style:{margin:0}},"I'm having trouble verifying your session. Please try"," ",R.createElement("a",{href:"",onClick:a=>{a.preventDefault(),window.location.reload()},style:{color:"var(--primaryColor, #107180)"}},"refreshing the page"),", or"," ",R.createElement("a",{href:o,target:"_blank",rel:"noopener noreferrer",style:{color:"var(--primaryColor, #107180)",fontWeight:"bold"}},"log in")," ","to continue.")):R.createElement(_p,{siteKey:A.siteKey,onVerify:a=>{A.token=a,r==null||r({type:"chatbot_turnstile_completed"}),n(a)},onError:()=>{zo("Turnstile widget error (may auto-recover)")}}):null}const Pp="#1a5b6e",Cp="#107180",Sp="Arial, sans-serif",EA="Q&A Bot",Dp="/chat-icon.svg",Bp="Type your question here...",Ip="Select an option to continue",Tp=!1,Qp="Ask me a question!",_A="/login",Mp={general:{showHeader:!0,showFooter:!0},tooltip:{mode:"CLOSE"},chatInput:{disabled:!1,characterLimit:5e3,showCharacterCount:!1,allowNewline:!0,blockSpam:!1},chatWindow:{defaultOpen:!1,showScrollbar:!1},botBubble:{simulateStream:!0,streamSpeed:10,showAvatar:!1},userBubble:{showAvatar:!1},notification:{disabled:!0,showCount:!1},audio:{disabled:!0},emoji:{disabled:!0},fileAttachment:{disabled:!0}},Go=qe((e,t)=>{var n,r,o;const{apiKey:i,qaEndpoint:s,ratingEndpoint:A,capabilitiesEndpoint:a,agentRatingEndpoint:l,welcomeMessage:c,open:u,onOpenChange:d,isLoggedIn:p,allowAnonAccess:h=!1,actingUser:m,primaryColor:f,secondaryColor:b,botName:y,logo:g,placeholder:x,errorMessage:k,embedded:E,footerText:P,footerLink:D,tooltipText:T,loginUrl:S,turnstileSiteKey:Q,resourceContext:C,customFlow:O,onAnalyticsEvent:U}=e,N=oe("bot_".concat(Math.random().toString(36).substr(2,9)));$(()=>{fp()},[]);const L=oe(null);L.current===null&&(L.current=gA(),hr("CREATED",L.current));const B=oe(!1),M=oe({getSessionId:()=>L.current,isResetting:()=>B.current}),w=function(j){const[Y,ce]=te(null),[se,de]=te("idle"),me=oe(null),he=oe(null),Fe=oe(!0),Ke=G(()=>{const Ne=window.turnstile;if(he.current&&(Ne!=null&&Ne.remove)){try{Ne.remove(he.current)}catch{}he.current=null}me.current&&(me.current.remove(),me.current=null)},[]);return $(()=>{if(Fe.current=!0,!j)return de("idle"),void ce(null);de("loading");const Ne=document.createElement("div");return Ne.style.position="fixed",Ne.style.left="-9999px",Ne.style.top="-9999px",Ne.style.width="0",Ne.style.height="0",Ne.style.overflow="hidden",Ne.setAttribute("aria-hidden","true"),document.body.appendChild(Ne),me.current=Ne,wA().then(()=>{if(!Fe.current)return;const vt=window.turnstile;if(!vt||!me.current)return Re("Turnstile API not available for silent verification"),void de("failed");const un=vt.render(me.current,{sitekey:j,execution:"render","refresh-expired":"auto",callback:_e=>{Fe.current&&(gr("Silent verification succeeded"),ce(_e),de("verified"))},"error-callback":()=>{Fe.current&&(Re("Turnstile silent verification failed"),de("failed"))},"expired-callback":()=>{Fe.current&&(gr("Token expired, awaiting refresh"),ce(null),de("loading"))}});he.current=un}).catch(vt=>{Fe.current&&(Re("Failed to load Turnstile script for silent verification:",vt),de("failed"))}),()=>{Fe.current=!1,Ke()}},[j,Ke]),{token:Y,status:se}}(Q),F=oe(null);F.current=w.token;const[v,W]=te(p);$(()=>{W(p)},[p]);const Z=E!==void 0?E:Tp,X=G(j=>{var Y;U&&U(Object.assign(Object.assign({},j),{timestamp:Date.now(),sessionId:(Y=L.current)!==null&&Y!==void 0?Y:void 0,pageUrl:typeof window<"u"?window.location.href:void 0,isEmbedded:Z}))},[U,Z]),le=De(()=>{const j=Object.assign({},Mp);j.general=Object.assign(Object.assign({},j.general),{primaryColor:f||Pp,secondaryColor:b||Cp,fontFamily:Sp,embedded:Z});const Y=v===!1?[R.createElement(dA,{key:"login-button",loginUrl:S||_A,isHeaderButton:!0})]:[R.createElement(vp,{key:"history-button"}),R.createElement(ap,{key:"user-icon"})];j.header={title:R.createElement("span",{style:{fontSize:14,fontWeight:500}},y||EA),showAvatar:!0,avatar:g||Dp,buttons:[...Y,Pe.CLOSE_CHAT_BUTTON]},j.chatInput=Object.assign(Object.assign({},j.chatInput),{disabled:!1,enabledPlaceholderText:x||Bp,disabledPlaceholderText:k||Ip}),j.tooltip=Object.assign(Object.assign({},j.tooltip),{text:T||Qp});const ce=P?D?R.createElement("a",{href:D,target:"_blank",rel:"noopener noreferrer",key:"footer-link"},P):R.createElement("span",{key:"footer-text"},P):null;return j.footer={text:ce,buttons:[R.createElement(wp,{key:"new-chat-button"})]},j.chatWindow=Object.assign(Object.assign({},j.chatWindow),{defaultOpen:!!Z}),j.event={rcbPreInjectMessage:!0,rcbPostInjectMessage:!0,rcbUserSubmitText:!0,rcbChangePath:!0,rcbToggleChatWindow:!0},j},[f,b,y,g,x,k,Z,T,v,S,P,D]),Oe=oe(null),ge=function(j){let Y=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{};return De(()=>{const ce=(se,de)=>{if(j.current){const me=getComputedStyle(j.current).getPropertyValue(se);if(me&&me.trim()!=="")return me.trim();if(j.current.parentElement){const he=getComputedStyle(j.current.parentElement).getPropertyValue(se);if(he&&he.trim()!=="")return he.trim()}}return de};return{primaryColor:ce("--primaryColor",Y.primaryColor),secondaryColor:ce("--secondaryColor",Y.secondaryColor),fontFamily:ce("--fontFamily",Y.fontFamily)}},[j,Y])}(Oe,le.general);((j,Y)=>{$(()=>{Y.current&&(j?Y.current.classList.add("bot-logged-in"):Y.current.classList.remove("bot-logged-in"))},[j,Y])})(v!==!1,Oe),(j=>{let{settings:Y,themeColors:ce}=j;$(()=>{ce&&(Object.entries(ce).forEach(se=>{let[de,me]=se;me&&document.documentElement.style.setProperty("--".concat(de),me)}),ce.primaryColor&&document.documentElement.style.setProperty("--rcb-header-background",ce.primaryColor),ce.secondaryColor&&document.documentElement.style.setProperty("--rcb-header-background-hover",ce.secondaryColor))},[ce]),$(()=>{var se,de;!((se=Y.header)===null||se===void 0)&&se.title&&typeof Y.header.title=="string"&&(Y.header.title=R.createElement("div",{key:"header-title"},R.createElement("h1",{className:"sr-only"},Y.header.title),R.createElement("span",{"aria-hidden":"true"},Y.header.title))),Y.device={desktopEnabled:!0,mobileEnabled:!0,applyMobileOptimizations:!1},Y.chatHistory={disabled:!0},Y.chatButton=Object.assign(Object.assign({},Y.chatButton),{icon:(de=Y.header)===null||de===void 0?void 0:de.avatar}),Y.event=Object.assign(Object.assign({},Y.event),{rcbToggleChatWindow:!0})},[Y])})({settings:le,themeColors:ge});const ot=De(()=>{const j=(ce=>{let{endpoint:se,ratingEndpoint:de,agentRatingEndpoint:me,apiKey:he,sessionId:Fe,isResetting:Ke=()=>!1,isLoggedIn:Ne,allowAnonAccess:vt=!1,loginUrl:un="/login",trackEvent:_e,getTurnstileToken:Fn,resourceContext:dn}=ce;if(Ne===!1&&!vt)return _e==null||_e({type:"chatbot_login_prompt_shown"}),{qa_loop:{message:"To ask questions, please log in first.",component:R.createElement(dA,{loginUrl:un}),chatDisabled:!0,path:"qa_loop"}};let it=null,bt=null,Kt=!1;const be={siteKey:null,token:null,pendingQuery:null,needsChallenge:!1};let I=null;if(!se)throw new Error("Q&A endpoint is required");return{qa_loop:{message:async z=>{var V;I=z.injectMessage.bind(z);const{userInput:ae}=z;if(Ke&&Ke()||!ae||ae.trim()==="")return null;if(ae==="👍 Helpful"||ae==="👎 Not helpful"){if(it){const ee=ae==="👍 Helpful",Ee=bt==="agent"?me:de;if(Ee)try{const Ce={"Content-Type":"application/json"};he&&(Ce["X-API-KEY"]=he);const we=Fe();we&&(Ce["X-Session-ID"]=we,Ce["X-Query-ID"]=it),await fetch(Ee,{method:"POST",headers:Ce,credentials:"include",body:JSON.stringify(bt==="agent"?{query_id:it,rating:ee?"helpful":"not_helpful",session_id:we}:{sessionId:we,queryId:it,rating:ee?1:0})}),_e==null||_e({type:"chatbot_rating_sent",queryId:it,rating:ee?"helpful":"not_helpful"})}catch(Ce){Re("Error sending feedback:",Ce)}}return"Thanks for the feedback!"}try{const ee=fA();it=ee,_e==null||_e({type:"chatbot_question_sent",queryId:ee,questionLength:ae.length});const Ee={"Content-Type":"application/json"};he&&(Ee["X-API-KEY"]=he);const Ce=Fe();Ce&&(Ee["X-Session-ID"]=Ce,Ee["X-Query-ID"]=ee);const we={query:ae,session_id:Ce,question_id:ee};dn&&(we.resource_context=dn);const Ze=Fn==null?void 0:Fn();Ze&&(we.turnstile_token=Ze),hr("SENT to API",{session_id:Ce,question_id:ee});const Mt=Date.now(),Se=await fetch(se,{method:"POST",headers:Ee,credentials:"include",body:JSON.stringify(we)});if(!Se.ok)throw new Error("API returned ".concat(Se.status));if((Se.headers.get("content-type")||"").includes("text/event-stream")){const Er=(V=Se.body)===null||V===void 0?void 0:V.getReader();if(!Er)throw new Error("Response body is not readable");const Zo=new TextDecoder;let wt="",Pt="",Nt=!1;try{for(;;){const{done:Lt,value:xt}=await Er.read();if(Lt)break;wt+=Zo.decode(xt,{stream:!0});let hn=wt.indexOf(`
41
41
 
@@ -292,5 +292,5 @@ Would you like to submit this security incident report?`},options:["Submit Secur
292
292
  display: inline !important;
293
293
  margin: 0 !important;
294
294
  }
295
- `;function Af(e){if(!e)return;const t=e.getRootNode();if(!(t instanceof ShadowRoot)||t.getElementById(CA))return;const n=document.createElement("style");n.id=CA,n.textContent=sf,t.appendChild(n)}const SA=qe((e,t)=>{const{apiKey:n=yt.DEFAULT_API_KEY,isLoggedIn:r=!1,loginUrl:o=Gt.LOGIN_URL,userEmail:i,userName:s,accessId:A,actingUser:a,ringEffect:l,defaultOpen:c,onClose:u,open:d,onOpenChange:p,embedded:h=!1,welcome:m,qaEndpoint:f,ratingEndpoint:b,agentEndpoint:y,resourceContext:g,onAnalyticsEvent:x}=e,k=oe(null),E=oe(null),[P,D]=te({}),[T,S]=te(null),Q=De(()=>({email:i,name:s,accessId:A}),[i,s,A]);$(()=>{Af(E.current)},[]),$(()=>{jp({ticketForm:P,setTicketForm:D})},[P]);const C=y||yt.AGENT_ENDPOINT,O=g?`${C}/capabilities?resource_context=${encodeURIComponent(g)}`:`${C}/capabilities`,U=`${C}/rating`;$(()=>{C.includes("localhost")&&!window.location.hostname.includes("localhost")&&console.warn("[AccessQABot] VITE_AGENT_ENDPOINT not set — agent requests will go to localhost. Set VITE_AGENT_ENDPOINT in your environment.")},[C]),$(()=>{let F=!1;async function v(){try{const W=await fetch(O,{credentials:"include"});if(!W.ok)throw new Error(`Capabilities API returned ${W.status}`);const Z=await W.json();F||S(Z)}catch(W){console.warn("Failed to fetch capabilities:",W),F||S({categories:[],is_authenticated:!1})}}return v(),()=>{F=!0}},[O,r]),$(()=>{if(!r)return;let F=!1;const v=`${C}/capabilities/personalized`;async function W(){try{const Z=await fetch(v,{credentials:"include"});if(!Z.ok)return;const X=await Z.json();F||console.debug("Personalized context loaded:",X)}catch{}}return W(),()=>{F=!0}},[C,r]),Gn(t,()=>({addMessage:F=>{var v,W;(W=(v=k.current)==null?void 0:v.addMessage)==null||W.call(v,F)}}));const N=m||Gt.WELCOME_MESSAGE,L=De(()=>af(),[]),B=G(F=>{x&&x({...F,type:F.type,timestamp:F.timestamp??Date.now(),sessionId:F.sessionId??L})},[x,L]),M=G(F=>{x&&x({...F,type:F.type,timestamp:typeof F.timestamp=="number"?F.timestamp:Date.now(),sessionId:typeof F.sessionId=="string"?F.sessionId:L})},[x,L]),w=De(()=>{const F=zp({welcome:N,trackEvent:B}),v=Jp({ticketForm:{},setTicketForm:D,userInfo:Q,trackEvent:B}),W=ef({ticketForm:{},setTicketForm:D,userInfo:Q,trackEvent:B}),Z=of({sessionId:L,apiKey:n,trackEvent:B}),X={...F,...v,...W,...Z};return Up(X,{disableOnOptions:!0})},[N,Q,L,n,r,B,T]);return T?_("div",{ref:E,children:_(Go,{ref:k,isLoggedIn:r,allowAnonAccess:yt.ALLOW_ANON_ACCESS,actingUser:a,onAnalyticsEvent:M,apiKey:n,qaEndpoint:f||yt.QA_ENDPOINT,ratingEndpoint:b||yt.RATING_ENDPOINT,capabilitiesEndpoint:O,agentRatingEndpoint:U,botName:Gt.BOT_NAME,logo:Gt.LOGO,primaryColor:Gt.PRIMARY_COLOR,secondaryColor:Gt.SECONDARY_COLOR,welcomeMessage:N,tooltipText:Gt.TOOLTIP,turnstileSiteKey:yt.TURNSTILE_SITE_KEY,loginUrl:o,open:d,onOpenChange:p,embedded:h,footerText:"AI-powered · Privacy Notice",footerLink:"https://support.access-ci.org/tools/access-qa-tool/privacy",resourceContext:g,customFlow:w})}):_("div",{ref:E})});SA.displayName="AccessQABot";function Jo(e){const{target:t,...n}=e;if(!t)throw new Error("qaBot: target element is required");const r=si();let o=n.isLoggedIn||!1,i=n.open!==void 0?n.open:n.defaultOpen||!1;const s=pl(t),A=()=>{s.render(_(SA,{ref:r,...n,isLoggedIn:o,open:i,onOpenChange:a=>{var l;i=a,(l=n.onOpenChange)==null||l.call(n,a)}}))};return A(),{addMessage(a){var l;(l=r.current)==null||l.addMessage(a)},setBotIsLoggedIn(a){o=a,A()},openChat(){i=!0,A()},closeChat(){i=!1,A()},toggleChat(){i=!i,A()},destroy(){s.unmount()}}}return typeof window<"u"&&(window.qaBot=Jo),jn.default=Jo,jn.qaBot=Jo,Object.defineProperties(jn,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}}),jn}({});
295
+ `;function Af(e){if(!e)return;const t=e.getRootNode();if(!(t instanceof ShadowRoot)||t.getElementById(CA))return;const n=document.createElement("style");n.id=CA,n.textContent=sf,t.appendChild(n)}const SA=qe((e,t)=>{const{apiKey:n=yt.DEFAULT_API_KEY,isLoggedIn:r=!1,loginUrl:o=Gt.LOGIN_URL,userEmail:i,userName:s,accessId:A,actingUser:a,ringEffect:l,defaultOpen:c,onClose:u,open:d,onOpenChange:p,embedded:h=!1,welcome:m,qaEndpoint:f,ratingEndpoint:b,agentEndpoint:y,resourceContext:g,onAnalyticsEvent:x}=e,k=oe(null),E=oe(null),[P,D]=te({}),[T,S]=te(null),Q=De(()=>({email:i,name:s,accessId:A}),[i,s,A]);$(()=>{Af(E.current)},[]),$(()=>{jp({ticketForm:P,setTicketForm:D})},[P]);const C=y||yt.AGENT_ENDPOINT,O=g?`${C}/capabilities?resource_context=${encodeURIComponent(g)}`:`${C}/capabilities`,U=`${C}/rating`;$(()=>{C.includes("localhost")&&!window.location.hostname.includes("localhost")&&console.warn("[AccessQABot] VITE_AGENT_ENDPOINT not set — agent requests will go to localhost. Set VITE_AGENT_ENDPOINT in your environment.")},[C]),$(()=>{let F=!1;async function v(){try{const W=await fetch(O,{credentials:"include"});if(!W.ok)throw new Error(`Capabilities API returned ${W.status}`);const Z=await W.json();F||S(Z)}catch(W){console.warn("Failed to fetch capabilities:",W),F||S({categories:[],is_authenticated:!1})}}return v(),()=>{F=!0}},[O,r]),$(()=>{if(!r)return;let F=!1;const v=`${C}/capabilities/personalized`;async function W(){try{const Z=await fetch(v,{credentials:"include"});if(!Z.ok)return;const X=await Z.json();F||console.debug("Personalized context loaded:",X)}catch{}}return W(),()=>{F=!0}},[C,r]),Gn(t,()=>({addMessage:F=>{var v,W;(W=(v=k.current)==null?void 0:v.addMessage)==null||W.call(v,F)}}));const N=m||(T==null?void 0:T.welcome_message)||Gt.WELCOME_MESSAGE,L=De(()=>af(),[]),B=G(F=>{x&&x({...F,type:F.type,timestamp:F.timestamp??Date.now(),sessionId:F.sessionId??L})},[x,L]),M=G(F=>{x&&x({...F,type:F.type,timestamp:typeof F.timestamp=="number"?F.timestamp:Date.now(),sessionId:typeof F.sessionId=="string"?F.sessionId:L})},[x,L]),w=De(()=>{const F=zp({welcome:N,trackEvent:B}),v=Jp({ticketForm:{},setTicketForm:D,userInfo:Q,trackEvent:B}),W=ef({ticketForm:{},setTicketForm:D,userInfo:Q,trackEvent:B}),Z=of({sessionId:L,apiKey:n,trackEvent:B}),X={...F,...v,...W,...Z};return Up(X,{disableOnOptions:!0})},[N,Q,L,n,r,B,T]);return T?_("div",{ref:E,children:_(Go,{ref:k,isLoggedIn:r,allowAnonAccess:yt.ALLOW_ANON_ACCESS,actingUser:a,onAnalyticsEvent:M,apiKey:n,qaEndpoint:f||yt.QA_ENDPOINT,ratingEndpoint:b||yt.RATING_ENDPOINT,capabilitiesEndpoint:O,agentRatingEndpoint:U,botName:Gt.BOT_NAME,logo:Gt.LOGO,primaryColor:Gt.PRIMARY_COLOR,secondaryColor:Gt.SECONDARY_COLOR,welcomeMessage:N,tooltipText:Gt.TOOLTIP,turnstileSiteKey:yt.TURNSTILE_SITE_KEY,loginUrl:o,open:d,onOpenChange:p,embedded:h,footerText:"AI-powered · Privacy Notice",footerLink:"https://support.access-ci.org/tools/access-qa-tool/privacy",resourceContext:g,customFlow:w})}):_("div",{ref:E})});SA.displayName="AccessQABot";function Jo(e){const{target:t,...n}=e;if(!t)throw new Error("qaBot: target element is required");const r=si();let o=n.isLoggedIn||!1,i=n.open!==void 0?n.open:n.defaultOpen||!1;const s=pl(t),A=()=>{s.render(_(SA,{ref:r,...n,isLoggedIn:o,open:i,onOpenChange:a=>{var l;i=a,(l=n.onOpenChange)==null||l.call(n,a)}}))};return A(),{addMessage(a){var l;(l=r.current)==null||l.addMessage(a)},setBotIsLoggedIn(a){o=a,A()},openChat(){i=!0,A()},closeChat(){i=!1,A()},toggleChat(){i=!i,A()},destroy(){s.unmount()}}}return typeof window<"u"&&(window.qaBot=Jo),jn.default=Jo,jn.qaBot=Jo,Object.defineProperties(jn,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}}),jn}({});
296
296
  //# sourceMappingURL=access-qa-bot.standalone.js.map