@webority/chat-react 0.134.0 → 0.135.1

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.
@@ -1,4 +1,4 @@
1
- import{AppBadge as e,AppButton as t,AppChart as n,AppDataTable as r,AppDescriptions as i,AppIcon as a,AppLightbox as o,AppMarkdown as s,AppMetricStrip as c,AppPopover as l,AppSkeleton as u,AppTooltip as d}from"@webority/ui-react";import{Fragment as f,createContext as p,useCallback as m,useContext as h,useEffect as g,useId as _,useLayoutEffect as v,useMemo as y,useRef as b,useState as x,useSyncExternalStore as S}from"react";import{CHAT_HANDOFF_REQUEST_ID as C,LOADER_STYLES as w,buildTranscript as T,createChatSession as E,createConversationList as D,createDictation as O,createExplain as k,createTurnApi as A,emptyFeatures as j,formatChatDate as M,formatChatValue as N,formatClipTime as P,formatFigure as F,formatFileSize as I,isHandoffTarget as L,loaderView as ee,mergeLabels as te,mergeLook as ne,messagePlainText as R,resolveNudge as z,showsCaptchaNote as re,toFigureRuns as ie,toFigureText as B,transcriptToText as V,voiceClipBars as H}from"@webority/chat-core";import{createAvoidance as U,createBehaviourCollector as ae,createSound as oe,createWebSpeech as se,fitToViewport as ce,lockPageScroll as le,returnFocus as ue,switchPanel as de,trapTab as fe,vibrate as pe,watchAutoOpen as me,watchReducedMotion as he}from"@webority/chat-elements/web";import{Fragment as W,jsx as G,jsxs as K}from"react/jsx-runtime";import{parseInline as ge}from"@webority/markdown-core";import{EMPTY_VALUE as _e,formatDate as q,formatDateTime as ve,formatNumber as ye}from"@webority/ui-elements/helpers";function be({value:e,span:t,selectionStart:n,selectionEnd:r,text:i,maxLength:a}){let o=t?t.start:n,s=t?t.end:r,c=!t&&o>0&&e.charAt(o-1).trim()!==``?` `:``,l=a-(e.length-(s-o))-c.length,u=i.slice(0,Math.max(0,l)),d=o+c.length,f=d+u.length;return{value:e.slice(0,o)+c+u+e.slice(s),span:{start:d,end:f},caret:f}}var xe=8e3,Se=Object.freeze({status:`Idle`}),Ce=()=>()=>void 0,we=()=>Se,Te=/* @__PURE__ */ new Set([`Blocked`,`NotHeard`,`Failed`,`NoMicrophone`,`Unavailable`]),Ee=/* @__PURE__ */ new Set([`Blocked`,`NoMicrophone`]),De={Blocked:`dictationBlocked`,NotHeard:`dictationNotHeard`,Failed:`dictationFailed`,NoMicrophone:`dictationNoMicrophone`,Unavailable:`dictationUnavailable`};function J({speech:e,enabled:t,labels:n,onText:r}){let i=b(null),a=b(r);a.current=r;let[o,s]=x(null);g(()=>{if(!e){s(null);return}let t=O({adapter:e,onText:(e,t)=>a.current(e,t),onLevel:e=>i.current?.style.setProperty(`--wui-chat-mic-level`,String(e))});return s({speech:e,instance:t}),()=>t.dispose()},[e]);let c=o!==null&&o.speech===e?o.instance:null,l=S(c?c.subscribe:Ce,c?c.getState:we).status,u=l===`Listening`,[d,f]=x(!1);g(()=>{if(!Te.has(l)){f(!1);return}if(f(!0),Ee.has(l))return;let e=setTimeout(()=>f(!1),xe);return()=>clearTimeout(e)},[l]),g(()=>{u||i.current?.style.removeProperty(`--wui-chat-mic-level`)},[u]);let p=m(()=>c?.toggle(),[c]),h=m(()=>c?.stop(),[c]),_=Te.has(l)&&d?l:null,v=_?n[De[_]]:null;return{available:!!(t&&e?.dictation),listening:u,note:v,noteKind:_,toggle:p,stop:h,buttonRef:i}}var Oe=/* @__PURE__ */ new WeakMap;function ke(e){if(!e.profile?.speechAvailable||!e.features.Dictation&&!e.features.ReadAloud)return null;let t=Oe.get(e.client);return t||(t=se(e.client),Oe.set(e.client,t)),t}var Y=10,Ae=.9,X=/* @__PURE__ */ new Set([`Shift`,`Control`,`Alt`,`Meta`,`Escape`]);function je(e){e.style.height=`auto`,e.style.height=`${e.scrollHeight}px`}function Me({chat:e,labels:n,maxLength:r,inputRef:i}){let{features:o}=e,s=_(),c=b(null),l=b(null),u=b(null),d=b(null),[f,p]=x(``),[m,h]=x(null);e.editing&&e.editing.messageId!==m&&(h(e.editing.messageId),p(e.editing.text)),!e.editing&&m!==null&&h(null),g(()=>{let t=e.draft;t&&!e.editing&&(u.current=null,c.current?.value!==t&&(d.current=t.length),p(t),c.current?.focus(),e.session.consumeDraft())},[e.draft,e.editing,e.session]);let y=J({speech:ke(e),enabled:e.features.Dictation,labels:n,onText:S});function S(e){let t=c.current;if(!t)return;let n=be({value:t.value,span:u.current,selectionStart:t.selectionStart,selectionEnd:t.selectionEnd,text:e,maxLength:r});u.current=n.span,n.value===t.value?t.setSelectionRange(n.caret,n.caret):(d.current=n.caret,p(n.value))}v(()=>{let e=c.current;d.current!==null&&e&&e.value===f&&(je(e),e.setSelectionRange(d.current,d.current),d.current=null)},[f]),g(()=>{e.editing&&y.stop()},[e.editing,y.stop]),g(()=>{e.handoffPause&&y.stop()},[e.handoffPause,y.stop]),g(()=>{y.listening||(u.current=null)},[y.listening]);let C=e.messages.flatMap(e=>e.parts).filter(e=>e.kind===`InputRequest`&&e.state===`Open`).at(-1),w=C?.fields[0],T=e.messagesLeftToday,E=e.profile?.limits,D=e.attachments.some(e=>e.status===`Uploading`),O=e.attachments.some(e=>e.status===`Ready`),k=o.Attachments&&(E?.maxAttachments??0)>0&&!e.handoffPause,A=e.streaming&&o.Stop,j=e.streaming&&!o.Stop||T===0||D||f.trim()===``&&!O||e.handoffPause,M=f.length>r*Ae,N=T!==null&&T<=Y;function P(e){c.current=e,typeof i==`function`?i(e):i&&(i.current=e)}function F(){let t=f.trim();j||t===``&&!O||(y.stop(),u.current=null,e.submit(t),p(``),c.current&&(c.current.style.height=`auto`))}function I(t){let n=Array.from(t.target.files??[]);t.target.value=``,n.length>0&&e.attach(n)}return/* @__PURE__ */ K(W,{children:[/* @__PURE__ */ G(`p`,{className:`wui-chat-allowance`,role:`status`,hidden:!N,children:N?n.allowance(T):``}),/* @__PURE__ */ G(`div`,{className:`wui-chat-editing`,hidden:!e.editing,children:e.editing&&/* @__PURE__ */ K(W,{children:[/* @__PURE__ */ G(`span`,{children:n.editing}),/* @__PURE__ */ G(t,{className:`wui-chat-action-btn`,size:`sm`,variant:`ghost`,onClick:()=>e.cancelEdit(),children:n.cancel})]})}),/* @__PURE__ */ G(`div`,{className:`wui-chat-attachments`,hidden:e.attachments.length===0,children:e.attachments.map(t=>/* @__PURE__ */ K(`span`,{className:`wui-chat-chip`,title:t.status===`Failed`?t.error??``:void 0,children:[/* @__PURE__ */ G(`span`,{children:t.fileName}),t.status===`Uploading`&&/* @__PURE__ */ G(`span`,{className:`wui-chat-chip-status`,"aria-live":`polite`,children:n.attachmentUploading}),t.status===`Failed`&&/* @__PURE__ */ G(`span`,{className:`wui-chat-chip-error`,role:`status`,children:t.error||n.attachmentFailed}),/* @__PURE__ */ G(`button`,{type:`button`,className:`wui-chat-chip-remove`,"aria-label":n.removeAttachment(t.fileName),onClick:()=>e.removeAttachment(t.key),children:/* @__PURE__ */ G(a,{name:`x`,size:14,"aria-hidden":`true`})})]},t.key))}),/* @__PURE__ */ K(`form`,{className:`wui-chat-composer`,"aria-label":n.composer,onSubmit:e=>{e.preventDefault(),F()},children:[k&&/* @__PURE__ */ K(W,{children:[/* @__PURE__ */ G(`button`,{type:`button`,className:`wui-chat-tool`,"aria-label":n.attach,title:n.attachHint,onClick:()=>l.current?.click(),children:/* @__PURE__ */ G(a,{name:`paperclip`,size:18,"aria-hidden":`true`})}),/* @__PURE__ */ G(`input`,{ref:l,type:`file`,multiple:!0,hidden:!0,accept:E.contentTypes.join(`,`),onChange:I})]}),/* @__PURE__ */ G(`textarea`,{ref:P,className:`wui-chat-input`,"aria-label":n.composer,"aria-describedby":s,placeholder:w?.label??C?.title??n.placeholder,rows:1,maxLength:r,value:f,disabled:T===0||e.handoffPause,onChange:t=>{u.current=null,p(t.target.value),je(t.target),t.target.value!==``&&e.notifyTyping()},onKeyDown:e=>{y.listening&&e.nativeEvent.isTrusted&&!X.has(e.key)&&y.stop(),e.key===`Enter`&&!e.shiftKey&&!e.nativeEvent.isComposing&&(e.preventDefault(),F())}}),/* @__PURE__ */ G(`span`,{id:s,className:`visually-hidden`,children:n.composerHint}),/* @__PURE__ */ G(`span`,{className:`wui-chat-counter`,hidden:!M,children:M?n.counter(f.length,r):``}),y.available&&/* @__PURE__ */ K(`button`,{type:`button`,className:y.listening?`wui-chat-tool wui-chat-mic wui-chat-mic--listening`:`wui-chat-tool wui-chat-mic`,ref:y.buttonRef,"aria-pressed":y.listening,"aria-label":y.listening?n.dictateStop:n.dictate,title:y.listening?n.dictateStop:n.dictate,disabled:T===0||e.handoffPause,onClick:y.toggle,children:[/* @__PURE__ */ G(`span`,{className:`wui-chat-mic-ring`,"aria-hidden":`true`}),/* @__PURE__ */ G(`span`,{className:`wui-chat-mic-ring wui-chat-mic-ring--late`,"aria-hidden":`true`}),/* @__PURE__ */ G(a,{name:`microphone`,size:18,"aria-hidden":`true`}),/* @__PURE__ */ K(`span`,{className:`wui-chat-mic-level`,"aria-hidden":`true`,children:[/* @__PURE__ */ G(`span`,{className:`wui-chat-mic-bar`}),/* @__PURE__ */ G(`span`,{className:`wui-chat-mic-bar`}),/* @__PURE__ */ G(`span`,{className:`wui-chat-mic-bar`}),/* @__PURE__ */ G(`span`,{className:`wui-chat-mic-bar`}),/* @__PURE__ */ G(`span`,{className:`wui-chat-mic-bar`})]})]}),/* @__PURE__ */ G(`span`,{className:`visually-hidden`,"aria-live":`polite`,children:y.listening?n.dictateListening:``}),A?/* @__PURE__ */ G(`button`,{type:`button`,className:`wui-chat-send wui-chat-send--stop`,"aria-label":n.stop,onClick:()=>e.stop(),children:/* @__PURE__ */ G(a,{name:`stop`,size:18,"aria-hidden":`true`})}):/* @__PURE__ */ G(`button`,{type:`submit`,className:`wui-chat-send`,"aria-label":n.send,disabled:j,children:/* @__PURE__ */ G(a,{name:`send`,size:18,"aria-hidden":`true`})})]}),y.note!==null&&/* @__PURE__ */ G(`p`,{className:`wui-chat-dictate-note`,role:y.noteKind===`Blocked`||y.noteKind===`NoMicrophone`?`alert`:`status`,children:y.note})]})}var Ne=6e4,Pe=`
1
+ import{AppBadge as e,AppButton as t,AppChart as n,AppDataTable as r,AppDescriptions as i,AppIcon as a,AppLightbox as o,AppMarkdown as s,AppMetricStrip as c,AppPopover as l,AppSkeleton as u,AppTooltip as d}from"@webority/ui-react";import{Fragment as f,createContext as p,useCallback as m,useContext as h,useEffect as g,useId as _,useLayoutEffect as v,useMemo as y,useRef as b,useState as x,useSyncExternalStore as S}from"react";import{CHAT_HANDOFF_REQUEST_ID as C,LOADER_STYLES as w,buildTranscript as T,createChatSession as E,createConversationList as D,createDictation as O,createExplain as k,createTurnApi as A,emptyFeatures as j,formatChatDate as M,formatChatValue as N,formatClipTime as P,formatFigure as F,formatFileSize as I,isHandoffTarget as L,loaderView as ee,mergeLabels as te,mergeLook as ne,messagePlainText as re,resolveNudge as R,showsCaptchaNote as z,toFigureRuns as ie,toFigureText as ae,transcriptToText as oe,voiceClipBars as B}from"@webority/chat-core";import{createAvoidance as V,createBehaviourCollector as H,createSound as U,createWebSpeech as se,fitToViewport as ce,growFromButton as le,lockPageScroll as ue,returnFocus as de,switchPanel as fe,trapTab as pe,vibrate as me,watchAutoOpen as he,watchReducedMotion as ge}from"@webority/chat-elements/web";import{Fragment as W,jsx as G,jsxs as K}from"react/jsx-runtime";import{parseInline as _e}from"@webority/markdown-core";import{EMPTY_VALUE as ve,formatDate as ye,formatDateTime as be,formatNumber as q}from"@webority/ui-elements/helpers";function xe({value:e,span:t,selectionStart:n,selectionEnd:r,text:i,maxLength:a}){let o=t?t.start:n,s=t?t.end:r,c=!t&&o>0&&e.charAt(o-1).trim()!==``?` `:``,l=a-(e.length-(s-o))-c.length,u=i.slice(0,Math.max(0,l)),d=o+c.length,f=d+u.length;return{value:e.slice(0,o)+c+u+e.slice(s),span:{start:d,end:f},caret:f}}var Se=8e3,Ce=Object.freeze({status:`Idle`}),we=()=>()=>void 0,Te=()=>Ce,Ee=/* @__PURE__ */ new Set([`Blocked`,`NotHeard`,`Failed`,`NoMicrophone`,`Unavailable`]),De=/* @__PURE__ */ new Set([`Blocked`,`NoMicrophone`]),Oe={Blocked:`dictationBlocked`,NotHeard:`dictationNotHeard`,Failed:`dictationFailed`,NoMicrophone:`dictationNoMicrophone`,Unavailable:`dictationUnavailable`};function ke({speech:e,enabled:t,labels:n,onText:r}){let i=b(null),a=b(r);a.current=r;let[o,s]=x(null);g(()=>{if(!e){s(null);return}let t=O({adapter:e,onText:(e,t)=>a.current(e,t),onLevel:e=>i.current?.style.setProperty(`--wui-chat-mic-level`,String(e))});return s({speech:e,instance:t}),()=>t.dispose()},[e]);let c=o!==null&&o.speech===e?o.instance:null,l=S(c?c.subscribe:we,c?c.getState:Te).status,u=l===`Listening`,[d,f]=x(!1);g(()=>{if(!Ee.has(l)){f(!1);return}if(f(!0),De.has(l))return;let e=setTimeout(()=>f(!1),Se);return()=>clearTimeout(e)},[l]),g(()=>{u||i.current?.style.removeProperty(`--wui-chat-mic-level`)},[u]);let p=m(()=>c?.toggle(),[c]),h=m(()=>c?.stop(),[c]),_=Ee.has(l)&&d?l:null,v=_?n[Oe[_]]:null;return{available:!!(t&&e?.dictation),listening:u,note:v,noteKind:_,toggle:p,stop:h,buttonRef:i}}var Ae=/* @__PURE__ */ new WeakMap;function J(e){if(!e.profile?.speechAvailable||!e.features.Dictation&&!e.features.ReadAloud)return null;let t=Ae.get(e.client);return t||(t=se(e.client),Ae.set(e.client,t)),t}var je=10,Me=.9,Y=/* @__PURE__ */ new Set([`Shift`,`Control`,`Alt`,`Meta`,`Escape`]);function Ne(e){e.style.height=`auto`,e.style.height=`${e.scrollHeight}px`}function X({chat:e,labels:n,maxLength:r,inputRef:i,sendIcon:o=`arrow-up`}){let{features:s}=e,c=_(),l=b(null),u=b(null),d=b(null),f=b(null),[p,m]=x(``),[h,y]=x(null);e.editing&&e.editing.messageId!==h&&(y(e.editing.messageId),m(e.editing.text)),!e.editing&&h!==null&&y(null),g(()=>{let t=e.draft;t&&!e.editing&&(d.current=null,l.current?.value!==t&&(f.current=t.length),m(t),l.current?.focus(),e.session.consumeDraft())},[e.draft,e.editing,e.session]);let S=ke({speech:J(e),enabled:e.features.Dictation,labels:n,onText:C});function C(e){let t=l.current;if(!t)return;let n=xe({value:t.value,span:d.current,selectionStart:t.selectionStart,selectionEnd:t.selectionEnd,text:e,maxLength:r});d.current=n.span,n.value===t.value?t.setSelectionRange(n.caret,n.caret):(f.current=n.caret,m(n.value))}v(()=>{let e=l.current;f.current!==null&&e&&e.value===p&&(Ne(e),e.setSelectionRange(f.current,f.current),f.current=null)},[p]),g(()=>{e.editing&&S.stop()},[e.editing,S.stop]),g(()=>{e.handoffPause&&S.stop()},[e.handoffPause,S.stop]),g(()=>{S.listening||(d.current=null)},[S.listening]);let w=e.messages.flatMap(e=>e.parts).filter(e=>e.kind===`InputRequest`&&e.state===`Open`).at(-1),T=w?.fields[0],E=e.messagesLeftToday,D=e.profile?.limits,O=e.attachments.some(e=>e.status===`Uploading`),k=e.attachments.some(e=>e.status===`Ready`),A=s.Attachments&&(D?.maxAttachments??0)>0&&!e.handoffPause,j=e.streaming&&s.Stop,M=e.streaming&&!s.Stop||E===0||O||p.trim()===``&&!k||e.handoffPause,N=p.length>r*Me,P=E!==null&&E<=je;function F(e){l.current=e,typeof i==`function`?i(e):i&&(i.current=e)}function I(){let t=p.trim();M||t===``&&!k||(S.stop(),d.current=null,e.submit(t),m(``),l.current&&(l.current.style.height=`auto`))}function L(t){let n=Array.from(t.target.files??[]);t.target.value=``,n.length>0&&e.attach(n)}return/* @__PURE__ */ K(W,{children:[/* @__PURE__ */ G(`p`,{className:`wui-chat-allowance`,role:`status`,hidden:!P,children:P?n.allowance(E):``}),/* @__PURE__ */ G(`div`,{className:`wui-chat-editing`,hidden:!e.editing,children:e.editing&&/* @__PURE__ */ K(W,{children:[/* @__PURE__ */ G(`span`,{children:n.editing}),/* @__PURE__ */ G(t,{className:`wui-chat-action-btn`,size:`sm`,variant:`ghost`,onClick:()=>e.cancelEdit(),children:n.cancel})]})}),/* @__PURE__ */ G(`div`,{className:`wui-chat-attachments`,hidden:e.attachments.length===0,children:e.attachments.map(t=>/* @__PURE__ */ K(`span`,{className:`wui-chat-chip`,title:t.status===`Failed`?t.error??``:void 0,children:[/* @__PURE__ */ G(`span`,{children:t.fileName}),t.status===`Uploading`&&/* @__PURE__ */ G(`span`,{className:`wui-chat-chip-status`,"aria-live":`polite`,children:n.attachmentUploading}),t.status===`Failed`&&/* @__PURE__ */ G(`span`,{className:`wui-chat-chip-error`,role:`status`,children:t.error||n.attachmentFailed}),/* @__PURE__ */ G(`button`,{type:`button`,className:`wui-chat-chip-remove`,"aria-label":n.removeAttachment(t.fileName),onClick:()=>e.removeAttachment(t.key),children:/* @__PURE__ */ G(a,{name:`x`,size:14,"aria-hidden":`true`})})]},t.key))}),/* @__PURE__ */ K(`form`,{className:p.trim()!==``||k?`wui-chat-composer wui-chat-composer--has-text`:`wui-chat-composer`,"aria-label":n.composer,onSubmit:e=>{e.preventDefault(),I()},children:[A&&/* @__PURE__ */ K(W,{children:[/* @__PURE__ */ G(`button`,{type:`button`,className:`wui-chat-tool`,"aria-label":n.attach,title:n.attachHint,onClick:()=>u.current?.click(),children:/* @__PURE__ */ G(a,{name:`paperclip`,size:18,"aria-hidden":`true`})}),/* @__PURE__ */ G(`input`,{ref:u,type:`file`,multiple:!0,hidden:!0,accept:D.contentTypes.join(`,`),onChange:L})]}),/* @__PURE__ */ G(`textarea`,{ref:F,className:`wui-chat-input`,"aria-label":n.composer,"aria-describedby":c,placeholder:T?.label??w?.title??n.placeholder,rows:1,maxLength:r,value:p,disabled:E===0||e.handoffPause,onChange:t=>{d.current=null,m(t.target.value),Ne(t.target),t.target.value!==``&&e.notifyTyping()},onKeyDown:e=>{S.listening&&e.nativeEvent.isTrusted&&!Y.has(e.key)&&S.stop(),e.key===`Enter`&&!e.shiftKey&&!e.nativeEvent.isComposing&&(e.preventDefault(),I())}}),/* @__PURE__ */ G(`span`,{id:c,className:`visually-hidden`,children:n.composerHint}),/* @__PURE__ */ G(`span`,{className:`wui-chat-counter`,hidden:!N,children:N?n.counter(p.length,r):``}),S.available&&/* @__PURE__ */ K(`button`,{type:`button`,className:S.listening?`wui-chat-tool wui-chat-mic wui-chat-mic--listening`:`wui-chat-tool wui-chat-mic`,ref:S.buttonRef,"aria-pressed":S.listening,"aria-label":S.listening?n.dictateStop:n.dictate,title:S.listening?n.dictateStop:n.dictate,disabled:E===0||e.handoffPause,onClick:S.toggle,children:[/* @__PURE__ */ G(`span`,{className:`wui-chat-mic-ring`,"aria-hidden":`true`}),/* @__PURE__ */ G(`span`,{className:`wui-chat-mic-ring wui-chat-mic-ring--late`,"aria-hidden":`true`}),/* @__PURE__ */ G(a,{name:`microphone`,size:18,"aria-hidden":`true`}),/* @__PURE__ */ K(`span`,{className:`wui-chat-mic-level`,"aria-hidden":`true`,children:[/* @__PURE__ */ G(`span`,{className:`wui-chat-mic-bar`}),/* @__PURE__ */ G(`span`,{className:`wui-chat-mic-bar`}),/* @__PURE__ */ G(`span`,{className:`wui-chat-mic-bar`}),/* @__PURE__ */ G(`span`,{className:`wui-chat-mic-bar`}),/* @__PURE__ */ G(`span`,{className:`wui-chat-mic-bar`})]})]}),/* @__PURE__ */ G(`span`,{className:`visually-hidden`,"aria-live":`polite`,children:S.listening?n.dictateListening:``}),j?/* @__PURE__ */ G(`button`,{type:`button`,className:`wui-chat-send wui-chat-send--stop`,"aria-label":n.stop,onClick:()=>e.stop(),children:/* @__PURE__ */ G(a,{name:`stop`,size:18,"aria-hidden":`true`})}):/* @__PURE__ */ G(`button`,{type:`submit`,className:`wui-chat-send`,"aria-label":n.send,disabled:M,children:/* @__PURE__ */ G(a,{name:o,size:18,"aria-hidden":`true`})})]}),S.note!==null&&/* @__PURE__ */ G(`p`,{className:`wui-chat-dictate-note`,role:S.noteKind===`Blocked`||S.noteKind===`NoMicrophone`?`alert`:`status`,children:S.note})]})}var Pe=6e4,Fe=`
2
2
  @page { margin: 16mm }
3
3
  body { font-family: system-ui, sans-serif; font-size: 11pt; line-height: 1.5; color: CanvasText; background: Canvas }
4
4
  h1 { font-size: 18pt; margin: 0 0 4pt }
@@ -11,4 +11,4 @@ table { border-collapse: collapse; margin: 0 0 6pt; max-width: 100% }
11
11
  caption { text-align: left; font-weight: 600 }
12
12
  th, td { border: 1px solid currentColor; padding: 2pt 6pt; text-align: left; vertical-align: top }
13
13
  thead { display: table-header-group }
14
- `;function Z(e,t,n){let r=e.createElement(t);return n!==void 0&&(r.textContent=n),r}function Fe(e,t){if(t.kind===`paragraph`)return Z(e,`p`,t.text);if(t.kind===`list`){let n=Z(e,t.ordered?`ol`:`ul`);for(let r of t.items)n.append(Z(e,`li`,r));return n}let n=Z(e,`table`);if(t.title!==null&&n.append(Z(e,`caption`,t.title)),t.head.length>0){let r=Z(e,`thead`),i=Z(e,`tr`);for(let n of t.head)i.append(Z(e,`th`,n));r.append(i),n.append(r)}let r=Z(e,`tbody`);for(let n of t.rows){let t=Z(e,`tr`);for(let r of n)t.append(Z(e,`td`,r));r.append(t)}return n.append(r),n}function Ie(e,t){if(typeof e.CSSStyleSheet==`function`&&`adoptedStyleSheets`in t){let n=new e.CSSStyleSheet;n.replaceSync(Pe),t.adoptedStyleSheets=[n];return}let n=Z(t,`style`,Pe);t.head.append(n)}function Le(e,t={}){let n=t.lang||document.documentElement.lang||`en`,r=document.createElement(`iframe`);r.title=`Print`,r.setAttribute(`aria-hidden`,`true`),r.tabIndex=-1;let i=r.style;i.position=`fixed`,i.right=`0`,i.bottom=`0`,i.width=`0`,i.height=`0`,i.border=`0`,document.body.append(r);let a=r.contentWindow,o=r.contentDocument;if(!a||!o)return r.remove(),!1;o.open(),o.write(`<!doctype html><title></title>`),o.close(),o.title=e.title,o.documentElement.lang=n,Ie(a,o),o.body.append(Z(o,`h1`,e.title));let s=t.printedOn??e.dateText;if(s!=null){let e=Z(o,`p`,s);e.className=`date`,o.body.append(e)}for(let t of e.entries){let e=Z(o,`section`);e.append(Z(o,`h2`,t.speaker));for(let n of t.blocks)e.append(Fe(o,n));o.body.append(e)}let c=()=>{r.isConnected&&r.remove(),clearTimeout(l)};a.addEventListener(`afterprint`,c);let l=setTimeout(c,Ne);return a.focus(),a.print(),!0}var Re=3e3;function ze(e,t){let[n,r]=x(null),i=b(null),a=b(!1);g(()=>(a.current=!0,()=>{a.current=!1,clearTimeout(i.current)}),[]);function o(e){a.current&&(clearTimeout(i.current),r(e),i.current=setTimeout(()=>r(null),Re))}let s={labels:t,title:e.title,figureText:e.features.FigureText},c=e.features.Share&&typeof navigator<`u`&&typeof navigator.share==`function`,l=e.features.Print&&typeof document<`u`;async function u(e,n){let r=T(e,s);if(r.entries.length===0)return;let i={title:r.title,text:V(r,{heading:n,speakers:n})};if(typeof navigator.canShare==`function`&&!navigator.canShare(i))o(t.shareFailed);else try{await navigator.share(i)}catch(e){e?.name!==`AbortError`&&o(t.shareFailed)}}function d(e){let n=T(e,s);n.entries.length!==0&&(Le(n,{printedOn:t.printedOn(M((/* @__PURE__ */ new Date()).toISOString()))})||o(t.printFailed))}return{canShare:c,canPrint:l,notice:n,shareReply:e=>u([e],!1),printReply:e=>d([e]),shareConversation:()=>u(e.messages,!0),printConversation:()=>d(e.messages)}}function Be({chat:e,labels:t}){let n=ze(e,t),r=e.streaming||e.thinking,i=e.messages.some(e=>e.stored&&(e.author.kind===`Assistant`||e.author.kind===`Agent`||e.author.kind===`Script`)&&R(e.parts)!==``);return r||e.loading||e.conversationId===null||!i||!n.canShare&&!n.canPrint?null:/* @__PURE__ */ K(W,{children:[n.canShare&&/* @__PURE__ */ G(`button`,{type:`button`,className:`wui-chat-icon-btn`,"aria-label":t.shareConversation,title:t.shareConversation,onClick:()=>n.shareConversation(),children:/* @__PURE__ */ G(a,{name:`share`,size:18,"aria-hidden":`true`})}),n.canPrint&&/* @__PURE__ */ G(`button`,{type:`button`,className:`wui-chat-icon-btn`,"aria-label":t.printConversation,title:t.printConversation,onClick:()=>n.printConversation(),children:/* @__PURE__ */ G(a,{name:`printer`,size:18,"aria-hidden":`true`})}),n.notice!==null&&/* @__PURE__ */ G(`span`,{className:`wui-chat-action-notice`,role:`status`,children:n.notice})]})}function Ve({chat:e,labels:t}){let n=e.profile;if(!n)return null;let r=n.footer.disclaimer||t.disclaimer,i=n.footer.privacyText,a=n.footer.privacyUrl,o=n.footer.assuranceText,s=re(n);return!r&&!i&&!a&&!o&&!s?null:/* @__PURE__ */ K(`p`,{className:`wui-chat-footer`,children:[r&&/* @__PURE__ */ G(`span`,{className:`wui-chat-footer-text`,children:r}),(i||a)&&/* @__PURE__ */ K(`span`,{className:`wui-chat-footer-privacy`,children:[i,i&&a&&` `,a&&/* @__PURE__ */ G(`a`,{className:`wui-chat-footer-link`,href:a,children:t.footerPrivacy})]}),o&&/* @__PURE__ */ G(`span`,{className:`wui-chat-footer-text`,children:o}),s&&/* @__PURE__ */ K(`span`,{className:`wui-chat-footer-captcha`,children:[t.captchaNote,` `,/* @__PURE__ */ G(`a`,{className:`wui-chat-footer-link`,href:`https://policies.google.com/privacy`,target:`_blank`,rel:`noopener noreferrer`,children:t.captchaPrivacy}),` `,/* @__PURE__ */ G(`a`,{className:`wui-chat-footer-link`,href:`https://policies.google.com/terms`,target:`_blank`,rel:`noopener noreferrer`,children:t.captchaTerms})]})]})}var He=Object.freeze({items:[],totalCount:null,loading:!1,error:null,hasMore:!1}),Ue=()=>()=>{};function We({chat:e,labels:n,onOpen:r}){let[i,o]=x(null),s=i!==null&&i.client===e.client?i.list:null,c=m(e=>s?s.subscribe(e):Ue(),[s]),l=m(()=>s?s.getState():He,[s]),u=S(c,l),[d,f]=x(null),[p,h]=x(``),[_,v]=x(!1),[y,C]=x(null),[w,T]=x(!1),E=b(null),O=b(!1),[k,A]=x(!1);g(()=>{let t=D({client:e.client});return o({client:e.client,list:t}),t.load(),()=>t.dispose()},[e.client]),g(()=>{d!==null&&E.current?.focus()},[d]);function j(e){f(e.publicId),h(e.title||``),v(!1)}async function N(e){if(!(O.current||p.trim()===``)){O.current=!0,A(!0);try{await s.rename(e,p),f(null)}catch{v(!0)}finally{O.current=!1,A(!1)}}}async function P(t){if(!O.current){O.current=!0,A(!0);try{await s.remove(t),C(null),T(!1),t===e.conversationId&&e.newConversation()}catch{T(!0)}finally{O.current=!1,A(!1)}}}let F=!u.loading&&u.error===null&&u.totalCount!==null&&u.items.length===0;return/* @__PURE__ */ K(`div`,{className:`wui-chat-history`,children:[u.error&&/* @__PURE__ */ K(`p`,{className:`wui-chat-history-error`,role:`alert`,children:[n.loadFailed,` `,/* @__PURE__ */ G(t,{className:`wui-chat-action-btn`,size:`sm`,variant:`ghost`,onClick:()=>s.load(),children:n.retry})]}),u.loading&&u.items.length===0&&/* @__PURE__ */ G(`p`,{className:`wui-chat-history-empty`,role:`status`,children:n.loadingConversation}),F&&/* @__PURE__ */ K(`p`,{className:`wui-chat-history-empty`,children:[/* @__PURE__ */ G(`span`,{children:n.historyEmptyTitle}),` `,/* @__PURE__ */ G(`span`,{children:n.historyEmptyText})]}),u.items.length>0&&/* @__PURE__ */ G(`ul`,{className:`wui-chat-history-list`,"aria-label":n.history,children:u.items.map(i=>d===i.publicId?/* @__PURE__ */ K(`li`,{className:`wui-chat-history-row wui-chat-history-row--editing`,children:[/* @__PURE__ */ G(`input`,{ref:E,className:`wui-chat-history-input`,"aria-label":n.conversationTitle,maxLength:120,value:p,onChange:e=>h(e.target.value),onKeyDown:e=>{e.key===`Enter`&&N(i.publicId),e.key===`Escape`&&(e.preventDefault(),e.stopPropagation(),f(null))}}),/* @__PURE__ */ G(t,{className:`wui-chat-action-btn`,size:`sm`,disabled:k||p.trim()===``,onClick:()=>N(i.publicId),children:n.renameSave}),/* @__PURE__ */ G(t,{className:`wui-chat-action-btn`,size:`sm`,variant:`ghost`,onClick:()=>f(null),children:n.cancel}),_&&/* @__PURE__ */ G(`p`,{className:`wui-chat-history-error`,role:`alert`,children:n.renameFailed})]},i.publicId):y===i.publicId?/* @__PURE__ */ K(`li`,{className:`wui-chat-history-row wui-chat-history-row--confirm`,children:[/* @__PURE__ */ G(`p`,{children:n.deleteConfirmTitle}),/* @__PURE__ */ G(`p`,{children:n.deleteConfirmMessage}),/* @__PURE__ */ G(t,{className:`wui-chat-action-btn`,size:`sm`,tone:`danger`,disabled:k,onClick:()=>P(i.publicId),children:n.deleteConfirm}),/* @__PURE__ */ G(t,{className:`wui-chat-action-btn`,size:`sm`,variant:`ghost`,onClick:()=>C(null),children:n.cancel}),w&&/* @__PURE__ */ G(`p`,{className:`wui-chat-history-error`,role:`alert`,children:n.deleteFailed})]},i.publicId):/* @__PURE__ */ K(`li`,{className:`wui-chat-history-row`,children:[/* @__PURE__ */ K(`button`,{type:`button`,className:`wui-chat-history-open`,onClick:()=>{e.openConversation(i.publicId),r()},children:[/* @__PURE__ */ G(`span`,{className:`wui-chat-history-title`,children:i.title||n.untitled}),/* @__PURE__ */ G(`span`,{className:`wui-chat-history-time`,children:M(i.lastActivityDateTimeUtc)})]}),e.features.Rename&&/* @__PURE__ */ G(`button`,{type:`button`,className:`wui-chat-icon-btn`,"aria-label":n.rename,title:n.rename,onClick:()=>j(i),children:/* @__PURE__ */ G(a,{name:`pencil`,size:18,"aria-hidden":`true`})}),e.features.Delete&&/* @__PURE__ */ G(`button`,{type:`button`,className:`wui-chat-icon-btn`,"aria-label":n.deleteChat,title:n.deleteChat,onClick:()=>{T(!1),C(i.publicId)},children:/* @__PURE__ */ G(a,{name:`trash`,size:18,"aria-hidden":`true`})})]},i.publicId))}),!u.loading&&u.hasMore&&/* @__PURE__ */ G(t,{className:`wui-chat-action-btn`,size:`sm`,variant:`soft`,onClick:()=>s.loadMore(),children:n.loadMore})]})}var Ge=/* @__PURE__ */ new Map([[`Open`,`info`],[`InProgress`,`info`],[`WaitingOnCustomer`,`warning`],[`Resolved`,`success`]]);function Ke(e){let t=(e??``).trim().split(/\s+/).filter(Boolean);if(t.length===0)return`?`;let n=Array.from(t[0])[0];return t.length===1?n.toUpperCase():`${n}${Array.from(t.at(-1))[0]}`.toUpperCase()}function qe(e){return Ge.get(e)??`neutral`}function Je(e){for(let t=e.length-1;t>=0;--t){let{author:n}=e[t];if(n.kind===`Agent`&&typeof n.displayName==`string`&&n.displayName.trim()!==``)return n.displayName}return null}function Ye(e,t){return e.conversationState===`WaitingForAgent`?t.statusWaitingForAgent:e.conversationState===`WithAgent`?t.statusWithAgent(Je(e.messages)??t.handoffAgentFallback):null}function Xe(e){return e.features.HumanHandoff===!0&&e.conversationState===`Open`&&e.messages.some(e=>e.author.kind===`Visitor`||e.author.kind===`Customer`)&&!e.streaming&&!e.thinking}function Ze({chat:e,labels:n}){let[r,i]=x(!1),[a,o]=x(null),s=e.live===`Lost`,c=s?null:Ye(e,n),l=Xe(e);if(c===null&&!l&&!s)return null;async function u(){i(!0),o(null);try{await e.requestHandoff()}catch(e){o(e?.message||n.errorGeneric)}finally{i(!1)}}return/* @__PURE__ */ K(W,{children:[s&&/* @__PURE__ */ K(`p`,{className:`wui-chat-live-status`,role:`status`,children:[n.liveLost,` `,/* @__PURE__ */ G(t,{variant:`ghost`,size:`sm`,onClick:()=>e.session.resumeLive(),children:n.retry})]}),c!==null&&/* @__PURE__ */ G(`p`,{className:`wui-chat-live-status`,role:`status`,children:c}),l&&/* @__PURE__ */ K(`div`,{className:`wui-chat-live-actions`,children:[/* @__PURE__ */ G(t,{variant:`outline`,size:`sm`,leftIcon:`user`,className:`wui-chat-handoff-request`,disabled:r,onClick:u,children:n.talkToPerson}),a&&/* @__PURE__ */ G(`p`,{className:`wui-chat-live-error`,role:`alert`,children:a})]})]})}var Qe=Object.freeze({state:`idle`,answer:null,pillVisible:!1,resetsDateTimeUtc:null,offline:!1}),$e=()=>void 0,et=()=>Qe;function tt({request:e,enabled:t=!0}){let n=b(e);n.current=e;let[r,i]=x(null);g(()=>{let e=k({request:e=>n.current(e)});return i(e),()=>e.dispose()},[]);let a=m(e=>r?r.subscribe(e):$e,[r]),o=S(a,r?r.getSnapshot:et),s=m(()=>{t&&r?.ask()},[t,r]),c=m(()=>r?.reset(),[r]),l=t?o:Qe;return{state:l.state,answer:l.answer,pillVisible:l.pillVisible,resetsDateTimeUtc:l.resetsDateTimeUtc,offline:l.offline,ask:s,reset:c}}function nt(e){if(typeof e!=`string`||e===``)return``;let t=new Date(e);return Number.isNaN(t.getTime())?``:new Intl.DateTimeFormat(void 0,{dateStyle:`medium`,timeStyle:`short`}).format(t)}var rt=20,it=Object.freeze({items:[],totalCount:null,loading:!1,error:null,hasMore:!1}),at=()=>void 0,ot=()=>it;function st(e,t){let n=Date.parse(e);if(Number.isNaN(n))return``;let r=(Date.now()-n)/1e3;if(r<60)return t.justNow;let i=new Intl.RelativeTimeFormat(void 0,{numeric:`auto`});return r<3600?i.format(-Math.floor(r/60),`minute`):r<86400?i.format(-Math.floor(r/3600),`hour`):r<604800?i.format(-Math.floor(r/86400),`day`):nt(e)}function ct({chat:e,labels:t,open:n}){let r=e.features.History===!0,i=e.client,[a,o]=x(null);g(()=>{if(!r)return;let e=D({client:i,pageSize:rt});return o(e),()=>e.dispose()},[i,r]);let s=m(e=>a?a.subscribe(e):at,[a]),c=S(s,a?a.getState:ot);g(()=>{n&&a&&a.load()},[n,a]);let l=e.features.ResumeLast?e.lastConversation?.publicId:void 0,u=c.items.filter(e=>e.publicId!==l).slice(0,rt);return!r||c.error||u.length===0?null:/* @__PURE__ */ G(`div`,{className:`wui-chat-empty-rows wui-chat-past`,role:`group`,"aria-label":t.history,children:u.map(n=>/* @__PURE__ */ K(`button`,{type:`button`,className:`wui-chat-empty-row`,onClick:()=>e.openConversation(n.publicId),children:[/* @__PURE__ */ G(`span`,{className:`wui-chat-empty-row-title`,children:n.title||t.earlierChat}),/* @__PURE__ */ G(`span`,{className:`wui-chat-empty-row-time`,title:nt(n.lastActivityDateTimeUtc)||void 0,children:st(n.lastActivityDateTimeUtc,t)})]},n.publicId))})}var lt=3;function ut({chat:t,labels:n,onOpenTicket:r}){return!t.features.OpenTickets||t.openTickets.length===0?null:/* @__PURE__ */ G(`div`,{className:`wui-chat-open-tickets`,role:`group`,"aria-label":n.openTickets,children:t.openTickets.slice(0,lt).map(t=>{let i=/* @__PURE__ */ K(W,{children:[/* @__PURE__ */ G(`span`,{className:`wui-chat-empty-row-label`,children:n.ticketAria(t.number)}),/* @__PURE__ */ G(`span`,{className:`wui-chat-empty-row-title`,children:t.subject}),/* @__PURE__ */ G(e,{className:`wui-chat-empty-row-status`,tone:qe(t.status),children:n.ticketStatus(t.status)||t.status})]});return r?/* @__PURE__ */ G(`button`,{type:`button`,className:`wui-chat-empty-row`,onClick:()=>r({ticketId:t.ticketId,number:t.number}),children:i},t.ticketId):/* @__PURE__ */ G(`span`,{className:`wui-chat-empty-row`,children:i},t.ticketId)})})}function dt({chat:e,labels:t,onOpenTicket:n}){if(!e.profile)return null;let r=e.features.Starters&&!e.streaming&&e.starters.length>0,i=e.features.ResumeLast&&!e.features.History?e.lastConversation:null;return/* @__PURE__ */ K(`div`,{className:`wui-chat-empty`,role:`group`,"aria-label":t.emptyTitle,children:[/* @__PURE__ */ K(`div`,{className:`wui-chat-empty-hero`,children:[/* @__PURE__ */ G(`span`,{className:`wui-chat-orb`,"aria-hidden":`true`}),e.greeting?/* @__PURE__ */ G(`h2`,{className:`wui-chat-greeting`,children:e.greeting}):null]}),r&&/* @__PURE__ */ G(`div`,{className:`wui-chat-starters`,role:`group`,"aria-label":t.starters,children:e.starters.map((t,n)=>/* @__PURE__ */ K(`button`,{type:`button`,className:`wui-chat-starter`,style:{"--wui-chat-i":n},onClick:()=>e.submit(t.message),children:[t.icon?/* @__PURE__ */ G(`span`,{className:`wui-chat-starter-icon`,"aria-hidden":`true`,children:/* @__PURE__ */ G(a,{name:t.icon,size:16})}):null,t.label]},t.id))}),i&&/* @__PURE__ */ G(`div`,{className:`wui-chat-empty-rows`,children:/* @__PURE__ */ K(`button`,{type:`button`,className:`wui-chat-empty-row`,onClick:()=>e.resumeLast(),children:[/* @__PURE__ */ G(`span`,{className:`wui-chat-empty-row-label`,children:t.resumeLast}),/* @__PURE__ */ G(`span`,{className:`wui-chat-empty-row-title`,children:i.title||t.untitled}),/* @__PURE__ */ G(`span`,{className:`wui-chat-empty-row-time`,children:M(i.lastActivityDateTimeUtc)})]})}),/* @__PURE__ */ G(ut,{chat:e,labels:t,onOpenTicket:n})]})}function ft({chat:e,labels:t}){let n=e.agentTyping;if(!n)return null;let r=typeof n==`object`&&n.displayName||Je(e.messages)||t.agent;return/* @__PURE__ */ G(`li`,{className:`wui-chat-message wui-chat-message--agent wui-chat-message--typing`,children:/* @__PURE__ */ K(`div`,{className:`wui-chat-typing`,role:`status`,children:[/* @__PURE__ */ K(`span`,{className:`wui-chat-typing-dots`,"aria-hidden":`true`,children:[/* @__PURE__ */ G(`span`,{className:`wui-chat-typing-dot`}),/* @__PURE__ */ G(`span`,{className:`wui-chat-typing-dot`}),/* @__PURE__ */ G(`span`,{className:`wui-chat-typing-dot`})]}),/* @__PURE__ */ G(`span`,{className:`visually-hidden`,children:t.agentTyping(r)})]})})}function pt({author:e,labels:t}){if(e.kind!==`Agent`)return null;let n=typeof e.avatarUrl==`string`&&e.avatarUrl!==``?e.avatarUrl:null;return/* @__PURE__ */ K(`span`,{className:`wui-chat-author-badge`,children:[n?/* @__PURE__ */ G(`img`,{className:`wui-chat-author-avatar`,src:n,alt:``,"aria-hidden":`true`,width:24,height:24}):/* @__PURE__ */ G(`span`,{className:`wui-chat-author-avatar`,"aria-hidden":`true`,children:Ke(e.displayName)}),/* @__PURE__ */ G(`span`,{className:`wui-chat-author-name`,children:e.displayName||t.agent}),/* @__PURE__ */ G(`span`,{className:`wui-chat-author-role`,children:t.agent})]})}var mt=null;function ht({speech:e,enabled:t}){let n=!!(t&&e?.readAloud),[r,i]=x(!1),[a,o]=x(!1),s=b(null),c=b(null),l=b(!1);return g(()=>(l.current=!0,()=>{l.current=!1,s.current?.abort(),s.current=null,mt===c.current&&(mt=null),c.current=null}),[]),{available:n,speaking:r,failed:a,toggle:m(t=>{if(s.current){s.current.abort();return}if(!e||t.trim()===``)return;mt?.();let n=new AbortController;s.current=n;let r=()=>n.abort();mt=r,c.current=r,i(!0),o(!1),e.speak(t,{signal:n.signal}).catch(()=>{!n.signal.aborted&&l.current&&o(!0)}).finally(()=>{s.current===n&&(s.current=null),mt===r&&(mt=null),l.current&&i(!1)})},[e])}}var gt=/* @__PURE__ */ new Set([`Assistant`,`Agent`,`Script`]),_t=6e3;function vt(e){let t=R(e).replace(/ ?\[\d+\]/g,``).replace(/\s+/g,` `).trim();if(t.length<=_t)return t;let n=t.slice(0,_t),r=n.lastIndexOf(`. `);return r===-1?n.trim():n.slice(0,r+1)}function yt({chat:e,labels:n,message:r}){let i=ht({speech:ke(e),enabled:e.features.ReadAloud});if(!i.available||r.streaming||!gt.has(r.author.kind))return null;let a=r.parts.filter(e=>e.kind===`Text`),o=vt(e.features.FigureText?a.map(e=>({...e,text:B(e.text)})):a);if(o.trim()===``)return null;let s=i.speaking?n.readAloudStop:n.readAloud;return/* @__PURE__ */ K(W,{children:[/* @__PURE__ */ G(t,{className:`wui-chat-action-btn`,size:`sm`,variant:`ghost`,leftIcon:`volume-high`,tone:i.speaking?`neutral`:void 0,"aria-pressed":i.speaking,"aria-label":s,title:s,onClick:()=>i.toggle(o)}),i.failed&&/* @__PURE__ */ G(`span`,{className:`wui-chat-action-notice`,role:`status`,children:n.readAloudFailed})]})}function bt(e){return e===`wchat:muted`?globalThis.localStorage:globalThis.sessionStorage}var xt={get(e){try{return bt(e)?.getItem(e)??null}catch{return null}},set(e,t){try{bt(e)?.setItem(e,t)}catch{}}};async function St(e){try{if(navigator.clipboard?.writeText)return await navigator.clipboard.writeText(e),!0}catch{}let t=document.createElement(`textarea`);t.value=e,t.setAttribute(`readonly`,``),t.style.position=`fixed`,t.style.opacity=`0`,document.body.appendChild(t),t.select();try{return document.execCommand(`copy`)}catch{return!1}finally{t.remove()}}async function Ct(e,t){try{let n=await e.getAttachment(t.attachmentId),r=URL.createObjectURL(new Blob([n],{type:t.contentType}));return window.open(r,`_blank`,`noopener`),setTimeout(()=>URL.revokeObjectURL(r),6e4),!0}catch(e){return globalThis.reportError?.(e),!1}}function wt(e){/^https?:\/\//i.test(e)?window.open(e,`_blank`,`noopener`):window.location.assign(e)}function Tt(e){for(let t=e?.parentElement;t&&t!==document.body;t=t.parentElement){let{overflowY:e}=getComputedStyle(t);if((e===`auto`||e===`scroll`)&&t.scrollHeight>t.clientHeight)return t}return null}function Et(e){let t=0;for(let n of e.parts)n.kind===`Text`&&(t+=n.text.length);return`${e.id}:${e.parts.length}:${t}`}function Dt(e){return e===`Reduced`?`wui-chat--reduced`:``}var Ot={Up:`check`,Down:`x`};function kt({chat:e,message:n,labels:r,isLast:i,isLastVisitor:a}){let{features:o}=e,[s,c]=x(!1),[l,u]=x(!1),[d,f]=x(!1),p=ze(e,r),m=e.streaming||e.thinking;if(g(()=>{if(!s)return;let e=setTimeout(()=>c(!1),2e3);return()=>clearTimeout(e)},[s]),n.streaming)return null;let h=n.author.kind===`Assistant`||n.author.kind===`Agent`||n.author.kind===`Script`,_=h?R(n.parts):``,v=h&&_!==``&&o.Copy,y=h&&_!==``&&o.ReadAloud,b=h&&_!==``&&o.Share&&p.canShare,S=h&&_!==``&&o.Print&&p.canPrint,C=i&&n.author.kind===`Assistant`&&!e.streaming&&!e.thinking&&o.Regenerate&&e.messages.some(e=>e.author.kind===`Visitor`&&e.stored),w=a&&o.Edit&&!m,T=o.Rating&&n.stored&&(n.author.kind===`Assistant`||n.author.kind===`Agent`);if(!v&&!y&&!b&&!S&&!C&&!w&&!T)return null;async function E(t){u(!1);try{await e.rate(n.id,t),f(!0)}catch{u(!0)}}return/* @__PURE__ */ K(W,{children:[v&&/* @__PURE__ */ G(t,{className:`wui-chat-action-btn`,size:`sm`,variant:`ghost`,leftIcon:`copy`,onClick:async()=>{let e=await St(_);c(e)},children:s?r.copied:r.copy}),y&&/* @__PURE__ */ G(yt,{chat:e,labels:r,message:n}),b&&/* @__PURE__ */ G(t,{className:`wui-chat-action-btn`,size:`sm`,variant:`ghost`,leftIcon:`share`,disabled:m,onClick:()=>p.shareReply(n),children:r.share}),S&&/* @__PURE__ */ G(t,{className:`wui-chat-action-btn`,size:`sm`,variant:`ghost`,leftIcon:`printer`,disabled:m,onClick:()=>p.printReply(n),children:r.print}),C&&/* @__PURE__ */ G(t,{className:`wui-chat-action-btn`,size:`sm`,variant:`ghost`,leftIcon:`refresh`,onClick:()=>e.regenerate(),children:r.regenerate}),w&&/* @__PURE__ */ G(t,{className:`wui-chat-action-btn`,size:`sm`,variant:`ghost`,leftIcon:`pencil`,onClick:()=>e.startEdit(n.id),children:r.edit}),T&&/* @__PURE__ */ K(`div`,{className:`wui-chat-rating`,role:`group`,"aria-label":`${r.rateUp} / ${r.rateDown}`,children:[[`Up`,`Down`].map(e=>/* @__PURE__ */ G(t,{className:`wui-chat-action-btn`,size:`sm`,variant:`ghost`,leftIcon:Ot[e],tone:n.rating===e?`neutral`:void 0,"aria-pressed":n.rating===e,"aria-label":e===`Up`?r.rateUp:r.rateDown,onClick:()=>E(e)},e)),l&&/* @__PURE__ */ G(`span`,{role:`status`,children:r.ratingFailed}),d&&!l&&/* @__PURE__ */ G(`span`,{role:`status`,children:r.rated})]}),p.notice!==null&&/* @__PURE__ */ G(`span`,{className:`wui-chat-action-notice`,role:`status`,children:p.notice})]})}function At({view:e}){return/* @__PURE__ */ K(`div`,{className:`wui-chat-loader-orb`,children:[/* @__PURE__ */ K(`span`,{className:`wui-chat-loader-orb-mark`,children:[/* @__PURE__ */ G(`span`,{className:`wui-chat-loader-orb-glow`,"aria-hidden":`true`}),/* @__PURE__ */ G(`span`,{className:`wui-chat-loader-orb-disc`,"aria-hidden":`true`})]}),/* @__PURE__ */ G(`span`,{className:`wui-chat-loader-orb-label`,children:e.label})]})}var jt=150;function Mt({view:e,motion:t}){let n=t===`Reduced`,[r,i]=x(()=>({id:0,label:e.label,previous:null}));e.label!==r.label&&i({id:r.id+1,label:e.label,previous:{id:r.id,label:r.label}}),g(()=>{if(!r.previous)return;let e=setTimeout(()=>i(e=>({...e,previous:null})),jt);return()=>clearTimeout(e)},[r.previous]);let a=n?null:r.previous;return/* @__PURE__ */ K(`div`,{className:`wui-chat-loader-phrases`,children:[/* @__PURE__ */ G(`span`,{className:`wui-chat-loader-phrases-orb`,"aria-hidden":`true`}),/* @__PURE__ */ K(`span`,{className:`wui-chat-loader-phrases-stage`,children:[a&&/* @__PURE__ */ G(`span`,{className:`wui-chat-loader-phrases-text wui-chat-loader-phrases-text--out`,children:a.label},`out-${a.id}`),/* @__PURE__ */ G(`span`,{className:`wui-chat-loader-phrases-text wui-chat-loader-phrases-text--in`,children:r.label},`in-${r.id}`)]})]})}var Nt=[`92%`,`78%`,`85%`,`40%`];function Pt({view:e}){return/* @__PURE__ */ K(`div`,{className:`wui-chat-loader-skeleton`,children:[/* @__PURE__ */ G(`div`,{className:`wui-chat-loader-skeleton-label`,children:e.label}),/* @__PURE__ */ K(`div`,{className:`wui-chat-loader-skeleton-body`,children:[Nt.map(e=>/* @__PURE__ */ G(`span`,{className:`wui-chat-loader-skeleton-line`,"aria-hidden":`true`,style:{width:e}},e)),/* @__PURE__ */ G(`span`,{className:`wui-chat-loader-skeleton-table`,"aria-hidden":`true`})]})]})}function Ft(e,t){return e<t?`done`:e===t?`active`:`pending`}function It(e){let t=/* @__PURE__ */ new Map;return e.map(e=>{let n=(t.get(e)??0)+1;return t.set(e,n),{key:`${e}\u0000${n}`,text:e}})}function Lt({state:e}){return e===`done`?/* @__PURE__ */ G(`svg`,{viewBox:`0 0 16 16`,className:`wui-chat-loader-steps-check`,"aria-hidden":`true`,children:/* @__PURE__ */ G(`path`,{d:`M3 8.5 6.5 12 13 4.5`,pathLength:1})}):e===`active`?/* @__PURE__ */ G(`span`,{className:`wui-chat-loader-steps-ring`,"aria-hidden":`true`}):/* @__PURE__ */ G(`span`,{className:`wui-chat-loader-steps-dot`,"aria-hidden":`true`})}function Rt({view:e}){return/* @__PURE__ */ G(`div`,{className:`wui-chat-loader-steps`,children:/* @__PURE__ */ G(`ol`,{className:`wui-chat-loader-steps-list`,children:It(e.steps).map(({key:t,text:n},r)=>{let i=Ft(r,e.activeIndex);return/* @__PURE__ */ K(`li`,{className:`wui-chat-loader-steps-item`,"data-state":i,children:[/* @__PURE__ */ G(`span`,{className:`wui-chat-loader-steps-icon`,"aria-hidden":`true`,children:/* @__PURE__ */ G(Lt,{state:i})}),/* @__PURE__ */ G(`span`,{className:`wui-chat-loader-steps-text`,children:n})]},t)})})})}var zt=500;function Bt({style:e,view:t,motion:n}){return e===`Phrases`?/* @__PURE__ */ G(Mt,{view:t,motion:n}):G(e===`Orb`?At:e===`Skeleton`?Pt:Rt,{view:t})}function Vt({style:e=`Steps`,steps:t=[],phrases:n,intervalMs:r,announce:i,motion:a=`On`}){let o=a===`Reduced`,[s,c]=x({style:e,count:0}),[l,u]=x(!1);if(g(()=>{if(o)return;let t=setInterval(()=>c(t=>({style:e,count:t.count+1})),r);return()=>clearInterval(t)},[e,r,o]),g(()=>{let e=setTimeout(()=>u(!0),zt);return()=>clearTimeout(e)},[]),!w.includes(e))throw Error(`ChatLoader style must be one of ${w.join(`, `)}, got "${e}".`);if(!(r>0))throw Error(`ChatLoader needs intervalMs, a positive number of milliseconds.`);s.style!==e&&c({style:e,count:0});let d=o?0:s.count,f=ee(e,t,n,d);return/* @__PURE__ */ K(`div`,{className:o?`wui-chat-loader wui-chat-loader--reduced`:`wui-chat-loader`,role:`status`,"aria-label":f.label,children:[/* @__PURE__ */ G(`div`,{className:`wui-chat-loader-body`,children:/* @__PURE__ */ G(Bt,{style:e,view:f,motion:a})}),/* @__PURE__ */ G(`span`,{className:`visually-hidden`,"aria-live":`polite`,children:l?i:``})]})}function Ht({motion:e,mark:t}){return/* @__PURE__ */ K(`div`,{className:e===`Reduced`?`wui-chat-loader-typing wui-chat-loader--reduced`:`wui-chat-loader-typing`,"aria-hidden":`true`,children:[t===`None`?null:/* @__PURE__ */ G(`span`,{className:`wui-chat-loader-typing-orb`,"aria-hidden":`true`}),/* @__PURE__ */ K(`span`,{className:`wui-chat-loader-typing-dots`,"aria-hidden":`true`,children:[/* @__PURE__ */ G(`span`,{className:`wui-chat-loader-typing-dot`,"aria-hidden":`true`}),/* @__PURE__ */ G(`span`,{className:`wui-chat-loader-typing-dot`,"aria-hidden":`true`}),/* @__PURE__ */ G(`span`,{className:`wui-chat-loader-typing-dot`,"aria-hidden":`true`})]})]})}var Ut=`ChatLeadCapture`,Wt=/^https?:\/\//i,Gt={strong:`strong`,em:`em`,strike:`s`};function Kt(e,t={next:0}){return e.map(e=>{let n=t.next++;if(e.type===`text`||e.type===`citation`)return e.text;if(e.type===`link`){let r=Kt(e.children,t);return Wt.test(e.href)?/* @__PURE__ */ G(`a`,{href:e.href,target:`_blank`,rel:`noopener noreferrer`,children:r},n):/* @__PURE__ */ G(f,{children:r},n)}if(e.type in Gt){let r=Gt[e.type];return/* @__PURE__ */ G(r,{children:Kt(e.children,t)},n)}return e.type===`code`?/* @__PURE__ */ G(`code`,{children:e.text},n):null})}function qt(e,t){return e.state===`Repeat`?e.decidedDateTimeUtc?t.actionRepeat(M(e.decidedDateTimeUtc)):t.actionDone:{Confirmed:t.actionConfirmed,Done:t.actionDone,Rejected:t.actionRejected,Expired:t.actionExpired,Failed:t.actionFailed}[e.state]}function Jt(e){let t=e.indexOf(`: `);return t<0?{term:e,detail:null}:{term:e.slice(0,t),detail:e.slice(t+2)}}function Yt(e,t){return{id:e,label:t,action:`Send`,target:null,navigateAfterMs:null,icon:null,variant:null}}function Xt({part:e,turn:t}){let{labels:n,features:r}=t,i=r.LeadRecap&&e.actionKind===Ut,a=e.state===`Pending`,o=e.editFields??[],s=i&&o.length>0,c=i&&e.confirmLabel||n.actionConfirm,l=i&&e.rejectLabel||n.actionDismiss,[u,d]=x(null),[f,p]=x(null),[m,h]=x(!1),v=_(),y=b(null),S=b(null),C=u!==null;g(()=>{m&&S.current?.querySelector(`[role="menuitem"]`)?.focus()},[m]);async function w(e,t){p(null),d(e);try{await t()}catch(e){p(e?.message||n.actionFailed),d(null)}}function T(e){h(!1),y.current?.focus(),t.chooseQuickReply(Yt(`lead.edit:${e.id}`,e.label))}function E(e){let t=[...e.currentTarget.querySelectorAll(`[role="menuitem"]`)],n=t.indexOf(e.target);e.key===`Escape`?(e.preventDefault(),h(!1),y.current?.focus()):e.key===`ArrowDown`?(e.preventDefault(),t[(n+1)%t.length]?.focus()):e.key===`ArrowUp`?(e.preventDefault(),t[n<=0?t.length-1:n-1]?.focus()):e.key===`Home`?(e.preventDefault(),t[0]?.focus()):e.key===`End`?(e.preventDefault(),t[t.length-1]?.focus()):e.key===`Tab`&&h(!1)}return/* @__PURE__ */ K(`div`,{className:`wui-chat-action wui-chat-action--${e.state.toLowerCase()}`,children:[/* @__PURE__ */ G(`strong`,{className:`wui-chat-action-title`,children:e.title}),e.lines.length>0&&(i?/* @__PURE__ */ G(`dl`,{className:`wui-chat-action-lines`,children:e.lines.map(e=>{let{term:t,detail:n}=Jt(e);return/* @__PURE__ */ K(`div`,{className:`wui-chat-action-line`,children:[/* @__PURE__ */ G(`dt`,{children:t}),n!==null&&/* @__PURE__ */ G(`dd`,{children:n})]},e)})}):/* @__PURE__ */ G(`ul`,{className:`wui-chat-action-lines`,children:e.lines.map(e=>/* @__PURE__ */ G(`li`,{children:e},e))})),i&&e.consentText&&/* @__PURE__ */ G(`p`,{className:`wui-chat-action-consent`,children:Kt(ge(e.consentText))}),e.note&&/* @__PURE__ */ G(`p`,{className:`wui-chat-action-note`,children:e.note}),!a&&/* @__PURE__ */ K(`p`,{className:`wui-chat-action-status wui-chat-action-status--${e.state.toLowerCase()}`,children:[qt(e,n),e.state===`Done`&&e.decidedDateTimeUtc&&/* @__PURE__ */ K(W,{children:[` `,/* @__PURE__ */ G(`time`,{dateTime:e.decidedDateTimeUtc,children:M(e.decidedDateTimeUtc)})]})]}),(a||s)&&/* @__PURE__ */ K(`div`,{className:`wui-chat-action-buttons`,children:[a&&/* @__PURE__ */ K(W,{children:[/* @__PURE__ */ G(`button`,{className:`btn btn-primary btn-sm`,type:`button`,disabled:C,onClick:()=>w(`confirm`,()=>t.confirmAction(e.actionId)),children:u===`confirm`?n.actionWorking:c}),/* @__PURE__ */ G(`button`,{className:`btn btn-soft-primary btn-sm`,type:`button`,disabled:C,onClick:()=>w(`reject`,()=>t.rejectAction(e.actionId)),children:l})]}),s&&/* @__PURE__ */ G(`button`,{ref:y,className:`btn btn-soft-primary btn-sm wui-chat-action-edit`,type:`button`,"aria-haspopup":`menu`,"aria-expanded":m,"aria-controls":m?v:void 0,disabled:!a||C,onClick:()=>h(e=>!e),children:n.editSomething})]}),s&&m&&/* @__PURE__ */ G(`ul`,{id:v,ref:S,className:`list-group wui-chat-action-menu`,role:`menu`,"aria-label":n.editSomething,onKeyDown:E,children:o.map(e=>/* @__PURE__ */ G(`li`,{role:`none`,children:/* @__PURE__ */ G(`button`,{className:`list-group-item list-group-item-action wui-chat-action-menu-item`,type:`button`,role:`menuitem`,tabIndex:-1,onClick:()=>T(e),children:e.label})},e.id))}),f&&/* @__PURE__ */ G(`p`,{className:`wui-chat-action-error`,role:`alert`,children:f})]})}function Q({text:e,enabled:t}){if(!t||typeof e!=`string`)return e;let n=0;return/* @__PURE__ */ G(W,{children:ie(e).map(e=>{let t=`${n}-${e.kind}`;return n+=e.text.length,e.kind===`sub`?/* @__PURE__ */ G(`sub`,{children:e.text},t):e.kind===`sup`?/* @__PURE__ */ G(`sup`,{children:e.text},t):/* @__PURE__ */ G(f,{children:e.text},t)})})}function Zt(e,t){return t&&typeof e==`string`?B(e):e}var Qt={Bar:`column`,Line:`line`,Donut:`donut`},$t=8,en=4;function tn({part:e,turn:r}){let[i,a]=x(`chart`),o=r.features.FigureText,s=e.chartType===`Donut`?e.series.slice(0,1):e.series.slice(0,$t),c=s.map(e=>new Map(e.points.map(e=>[e.label,e.value]))),l=[...new Set(s.flatMap(e=>e.points.map(e=>e.label)))].map(e=>{let t={label:Zt(e,o)};return c.forEach((n,r)=>{t[`s${r}`]=n.get(e)??null}),t}),u=e.unit?Zt(e.unit,o):null,d=s.map((e,t)=>{let n=Zt(e.name,o);return{key:`s${t}`,label:n,format:{style:`number`}}}),f=e.chartType!==`Donut`&&u?{label:u}:void 0,p=Math.max(0,...s.map(e=>e.points.length)),m=e.chartType===`Bar`&&p>en?300:240;return/* @__PURE__ */ K(`figure`,{className:`wui-chat-chart`,children:[e.title?/* @__PURE__ */ G(`figcaption`,{className:`wui-chat-rich-title`,children:/* @__PURE__ */ G(Q,{text:e.title,enabled:o})}):null,/* @__PURE__ */ G(n,{type:Qt[e.chartType],title:(e.title?Zt(e.title,o):``)||r.labels.chart,data:l,x:{key:`label`},series:d,y:f,height:m,view:i,errorText:r.labels.chartLoadFailed}),l.length>0&&/* @__PURE__ */ G(t,{variant:`link`,size:`sm`,className:`wui-chat-chart-toggle`,"aria-pressed":i===`table`,onClick:()=>a(i===`table`?`chart`:`table`),children:i===`table`?r.labels.chartShowChart:r.labels.chartShowTable})]})}var nn={Neutral:`neutral`,Positive:`success`,Caution:`warning`,Negative:`danger`},rn=/* @__PURE__ */ new Set([`Positive`,`Caution`,`Negative`]),an=3,on=5,sn=.001;function cn(e){let t=0;return e.map(e=>{let n=`${t}-${e.kind}`;return t+=e.text.length,e.kind===`sub`?/* @__PURE__ */ G(`sub`,{children:e.text},n):e.kind===`sup`?/* @__PURE__ */ G(`sup`,{children:e.text},n):/* @__PURE__ */ G(`span`,{children:e.text},n)})}function ln(e,t){let n=e.value!==0&&Math.abs(e.value)<sn?cn(F(e.value)):ye(e.value),r=rn.has(e.status)?/* @__PURE__ */ G(`span`,{className:`visually-hidden`,children:t.figureStatus(e.status)}):null;return e.unit?/* @__PURE__ */ K(W,{children:[n,` `,/* @__PURE__ */ G(`span`,{className:`wui-chat-figure-unit`,children:cn(ie(e.unit))}),r]}):/* @__PURE__ */ K(W,{children:[n,r]})}function un({part:e,turn:t}){if(e.figures.length===0)return null;let n=Math.min(on,Math.max(an,e.figures.length)),r=e.figures.map(e=>({label:/* @__PURE__ */ G(Q,{text:e.label,enabled:!0}),value:ln(e,t.labels),tone:nn[e.status]}));return/* @__PURE__ */ G(`div`,{className:`wui-chat-figures`,role:`group`,"aria-label":t.labels.figures,children:/* @__PURE__ */ G(c,{className:`wui-chat-figures-strip`,size:`sm`,columns:n,items:r})})}function dn({part:e,turn:t}){let n=/* @__PURE__ */ K(W,{children:[/* @__PURE__ */ G(`span`,{children:/* @__PURE__ */ G(a,{name:`document-text`,size:16})}),/* @__PURE__ */ G(`span`,{className:`wui-chat-file-name`,children:e.fileName}),/* @__PURE__ */ G(`span`,{className:`wui-chat-file-size`,children:I(e.length)})]});return/* @__PURE__ */ G(`div`,{className:`wui-chat-file`,children:t.openAttachment?/* @__PURE__ */ G(`button`,{className:`wui-chat-file-chip`,type:`button`,"aria-label":t.labels.fileOpen(e.fileName),onClick:()=>t.openAttachment(e),children:n}):/* @__PURE__ */ G(`span`,{className:`wui-chat-file-chip`,children:n})})}var fn=/* @__PURE__ */ new Set([`Requested`,`Waiting`,`Joined`,`Left`,`Ended`]),pn=/* @__PURE__ */ new Set([`Requested`,`Waiting`,`Joined`]);function mn({part:e,turn:t}){if(!fn.has(e.state)||t.handoffSettled===!0&&(e.state===`Requested`||e.state===`Waiting`))return null;let{labels:n}=t,r=e.agent?.displayName||null,i=e.agent?.avatarUrl||null,a=e.state.toLowerCase(),o=t.isLast&&(e.state===`Requested`||e.state===`Waiting`);return/* @__PURE__ */ K(`div`,{className:`wui-chat-handoff wui-chat-handoff--${a}${o?` wui-chat-handoff--live`:``}`,role:t.isLast&&pn.has(e.state)?`status`:void 0,children:[e.state===`Requested`&&/* @__PURE__ */ K(W,{children:[/* @__PURE__ */ K(`span`,{className:`wui-chat-handoff-pulses`,"aria-hidden":`true`,children:[/* @__PURE__ */ G(`span`,{className:`wui-chat-handoff-pulse`}),/* @__PURE__ */ G(`span`,{className:`wui-chat-handoff-pulse`}),/* @__PURE__ */ G(`span`,{className:`wui-chat-handoff-pulse`})]}),/* @__PURE__ */ G(`p`,{className:`wui-chat-handoff-text`,children:n.handoffRequested})]}),e.state===`Waiting`&&/* @__PURE__ */ K(W,{children:[typeof e.queuePosition!=`number`&&/* @__PURE__ */ K(W,{children:[/* @__PURE__ */ K(`span`,{className:`wui-chat-handoff-pulses`,"aria-hidden":`true`,children:[/* @__PURE__ */ G(`span`,{className:`wui-chat-handoff-pulse`}),/* @__PURE__ */ G(`span`,{className:`wui-chat-handoff-pulse`}),/* @__PURE__ */ G(`span`,{className:`wui-chat-handoff-pulse`})]}),/* @__PURE__ */ G(`p`,{className:`wui-chat-handoff-text`,children:n.handoffWaiting})]}),typeof e.queuePosition==`number`&&/* @__PURE__ */ G(`p`,{className:`wui-chat-handoff-queue`,children:n.handoffQueued(e.queuePosition)}),/* @__PURE__ */ G(`p`,{className:`wui-chat-handoff-note`,children:n.handoffQueuedText})]}),e.state===`Joined`&&/* @__PURE__ */ K(W,{children:[i?/* @__PURE__ */ G(`img`,{className:`wui-chat-handoff-avatar`,src:i,alt:``,"aria-hidden":`true`,width:32,height:32}):/* @__PURE__ */ G(`span`,{className:`wui-chat-handoff-avatar`,"aria-hidden":`true`,children:Ke(r)}),/* @__PURE__ */ G(`span`,{className:`wui-chat-handoff-online`,"aria-hidden":`true`}),/* @__PURE__ */ G(`p`,{className:`wui-chat-handoff-text`,children:n.handoffJoined(r??n.handoffAgentFallback)}),/* @__PURE__ */ G(`p`,{className:`wui-chat-handoff-text`,children:n.handoffJoinedText(r??n.handoffAgentFallback)})]}),e.state===`Left`&&/* @__PURE__ */ K(W,{children:[/* @__PURE__ */ G(`p`,{className:`wui-chat-handoff-text`,children:n.handoffLeft(r??n.handoffAgentFallback)}),/* @__PURE__ */ G(`p`,{className:`wui-chat-handoff-text`,children:n.handoffLeftText})]}),e.state===`Ended`&&/* @__PURE__ */ K(W,{children:[/* @__PURE__ */ G(`p`,{className:`wui-chat-handoff-text`,children:n.handoffEnded}),/* @__PURE__ */ G(`p`,{className:`wui-chat-handoff-text`,children:n.handoffEndedText})]})]})}function hn({part:e,loadAttachmentUrl:n,turn:r}){let[i,a]=x({status:`loading`,url:null}),s=b(0),c=m(e=>{let t=++s.current;a({status:`loading`,url:null}),n(e).then(e=>{s.current===t&&a({status:`ready`,url:e})},()=>{s.current===t&&a({status:`failed`,url:null})})},[n]);return g(()=>(c(e.attachmentId),()=>{s.current++}),[c,e.attachmentId]),i.status===`loading`?/* @__PURE__ */ K(`div`,{className:`wui-chat-image-loading`,role:`status`,children:[/* @__PURE__ */ G(`span`,{className:`visually-hidden`,children:r.labels.imageLoading}),/* @__PURE__ */ G(u,{height:160,radius:8})]}):i.status===`failed`?/* @__PURE__ */ K(W,{children:[/* @__PURE__ */ G(`p`,{className:`wui-chat-image-error`,role:`status`,children:r.labels.imageFailed}),/* @__PURE__ */ G(t,{variant:`soft`,tone:`primary`,size:`sm`,onClick:()=>c(e.attachmentId),children:r.labels.retry})]}):/* @__PURE__ */ G(o,{className:`wui-chat-image-view`,label:r.labels.imageViewer,items:[{key:e.attachmentId,src:i.url,alt:e.alt,name:e.alt}],download:!1})}function gn({part:e,turn:t}){let n=e.width&&e.height?{aspectRatio:`${e.width} / ${e.height}`}:void 0;return typeof t.loadAttachmentUrl==`function`?/* @__PURE__ */ G(`figure`,{className:`wui-chat-image`,style:n,children:/* @__PURE__ */ G(hn,{part:e,loadAttachmentUrl:t.loadAttachmentUrl,turn:t},e.attachmentId)}):/* @__PURE__ */ G(`figure`,{className:`wui-chat-image`,style:n,children:/* @__PURE__ */ G(`span`,{className:`wui-chat-image-alt`,children:e.alt})})}var _n=/* @__PURE__ */ new Set([`ActionLimitReached`,`ConversationTooLong`]),vn={AssistantUnavailable:`danger`},yn={info:`info`,warning:`alert-triangle`,danger:`alert-circle`};function bn({part:e}){let t=vn[e.code]??(_n.has(e.code)?`warning`:`info`);return/* @__PURE__ */ K(`div`,{className:`wui-chat-notice wui-chat-notice--${t}`,role:t===`danger`?`alert`:`status`,children:[/* @__PURE__ */ G(`span`,{className:`wui-chat-notice-icon`,"aria-hidden":`true`,children:/* @__PURE__ */ G(a,{name:yn[t],size:16})}),/* @__PURE__ */ G(`span`,{className:`wui-chat-notice-text`,children:e.text})]})}var xn=[`Email`,`Phone`,`Name`,`Company`,`Text`,`LongText`,`Choice`,`MultiChoice`,`TimeSlot`,`File`,`Consent`],Sn={Email:{type:`email`,autoComplete:`email`},Phone:{type:`tel`,autoComplete:`tel`},Name:{type:`text`,autoComplete:`name`},Company:{type:`text`,autoComplete:`organization`},Text:{type:`text`,autoComplete:void 0}},Cn=new Intl.DateTimeFormat(void 0,{weekday:`short`,day:`numeric`,month:`short`,hour:`numeric`,minute:`2-digit`});function wn(e,t){return e.state===`Answered`?e.answeredSummary||t.inputAnswered:e.state===`Skipped`?t.inputSkipped:t.inputExpired}function Tn(e){return e.type===`Consent`?!1:e.type===`MultiChoice`?[]:``}function En(e){return Object.fromEntries(e.map(e=>[e.key,Tn(e)]))}function Dn(e,t){return e.secret?t:t.trim()}function On(e,t,n){return e.required?e.type===`Consent`?t?null:n.inputConsentRequired:e.type===`MultiChoice`?t.length>0?null:n.inputRequired:Dn(e,t)?null:n.inputRequired:null}function kn(e,t){return e.type===`Consent`?t?`true`:`false`:e.type===`MultiChoice`?JSON.stringify((e.options??[]).map(e=>e.id).filter(e=>t.includes(e))):e.type===`Choice`||e.type===`TimeSlot`?t:Dn(e,t)}function An({field:e,value:t,error:n,file:r,disabled:i,id:a,labels:o,onChange:s,onFile:c,onRemove:l,controlRef:u}){let d=`${a}-error`,f=d,p=n?`true`:void 0,m=e.required||void 0,h=/* @__PURE__ */ G(`p`,{className:`wui-chat-field-error`,id:d,role:`alert`,hidden:!n,children:n}),g=e.required?null:/* @__PURE__ */ G(`span`,{className:`wui-chat-field-hint`,children:o.inputOptional});if(e.type===`Choice`){let n=`${a}-label`;return/* @__PURE__ */ K(`div`,{className:`wui-chat-field`,"data-key":e.key,children:[/* @__PURE__ */ G(`span`,{className:`form-label`,id:n,children:e.label}),g,/* @__PURE__ */ G(`div`,{role:`radiogroup`,"aria-labelledby":n,"aria-invalid":p,"aria-describedby":f,children:(e.options??[]).map((n,r)=>{let o=`${a}-${n.id}`;return/* @__PURE__ */ K(`div`,{className:`form-check`,children:[/* @__PURE__ */ G(`input`,{className:`form-check-input`,type:`radio`,id:o,name:e.key,value:n.id,checked:t===n.id,disabled:i,onChange:()=>s(n.id),ref:r===0?u:void 0}),/* @__PURE__ */ G(`label`,{className:`form-check-label`,htmlFor:o,children:n.label})]},n.id)})}),h]})}if(e.type===`MultiChoice`){let n=`${a}-label`;return/* @__PURE__ */ K(`div`,{className:`wui-chat-field`,"data-key":e.key,children:[/* @__PURE__ */ G(`span`,{className:`form-label`,id:n,children:e.label}),g,/* @__PURE__ */ G(`div`,{className:`wui-chat-input-choices`,role:`group`,"aria-labelledby":n,"aria-invalid":p,"aria-describedby":f,children:(e.options??[]).map((n,r)=>{let o=`${a}-${n.id}`;return/* @__PURE__ */ K(`div`,{className:`form-check`,children:[/* @__PURE__ */ G(`input`,{className:`form-check-input`,type:`checkbox`,id:o,name:e.key,value:n.id,checked:t.includes(n.id),disabled:i,onChange:e=>s(e.target.checked?[...t,n.id]:t.filter(e=>e!==n.id)),ref:r===0?u:void 0}),/* @__PURE__ */ G(`label`,{className:`form-check-label`,htmlFor:o,children:n.label})]},n.id)})}),h]})}if(e.type===`TimeSlot`){let n=`${a}-label`;return/* @__PURE__ */ K(`div`,{className:`wui-chat-field`,"data-key":e.key,children:[/* @__PURE__ */ G(`span`,{className:`form-label`,id:n,children:e.label}),g,/* @__PURE__ */ G(`div`,{className:`wui-chat-input-slots d-flex flex-wrap gap-2`,role:`radiogroup`,"aria-labelledby":n,"aria-invalid":p,"aria-describedby":f,children:(e.slots??[]).map((n,r)=>{let o=`${a}-${n.id}`;return/* @__PURE__ */ K(`div`,{className:`wui-chat-input-slot`,children:[/* @__PURE__ */ G(`input`,{className:`btn-check`,type:`radio`,id:o,name:e.key,value:n.id,checked:t===n.id,disabled:i,onChange:()=>s(n.id),ref:r===0?u:void 0}),/* @__PURE__ */ G(`label`,{className:`btn btn-soft-primary wui-chat-input-slot`,htmlFor:o,children:Cn.format(new Date(n.startDateTimeUtc))})]},n.id)})}),h]})}if(e.type===`File`){let t=r?.status===`uploading`;return/* @__PURE__ */ K(`div`,{className:`wui-chat-field`,"data-key":e.key,children:[/* @__PURE__ */ G(`label`,{className:`form-label`,htmlFor:a,children:e.label}),g,/* @__PURE__ */ G(`span`,{className:t?`wui-chat-input-file-status`:`visually-hidden`,"aria-live":`polite`,children:t?o.attachmentUploading:``}),r?/* @__PURE__ */ K(`div`,{className:`wui-chat-input-file`,children:[/* @__PURE__ */ G(`span`,{className:`wui-chat-input-file-name`,children:r.name}),/* @__PURE__ */ G(`button`,{className:`btn btn-link`,type:`button`,disabled:i,onClick:l,ref:u,children:o.inputRemoveFile(r.name)})]}):/* @__PURE__ */ G(`input`,{className:`form-control wui-chat-input-control`,type:`file`,id:a,name:e.key,accept:e.accept?.join(`,`),disabled:i,"aria-label":o.inputChooseFile,"aria-required":m,"aria-invalid":p,"aria-describedby":f,onChange:e=>{let t=e.target.files?.[0];t&&c(t)},ref:u}),h]})}if(e.type===`Consent`)return/* @__PURE__ */ K(`div`,{className:`wui-chat-field`,"data-key":e.key,children:[/* @__PURE__ */ K(`div`,{className:`form-check`,children:[/* @__PURE__ */ G(`input`,{className:`form-check-input`,type:`checkbox`,id:a,name:e.key,checked:t,disabled:i,"aria-invalid":p,"aria-describedby":f,onChange:e=>s(e.target.checked),ref:u}),/* @__PURE__ */ G(`label`,{className:`form-check-label`,htmlFor:a,children:e.consentText||e.label})]}),h]});let _=Sn[e.type],v=e.type===`LongText`&&!e.secret?/* @__PURE__ */ G(`textarea`,{className:`form-control wui-chat-input-control`,id:a,name:e.key,rows:3,value:t,placeholder:e.placeholder??void 0,maxLength:e.maxLength??void 0,disabled:i,"aria-required":m,"aria-invalid":p,"aria-describedby":f,onChange:e=>s(e.target.value),ref:u}):/* @__PURE__ */ G(`input`,{className:`form-control wui-chat-input-control`,id:a,name:e.key,type:e.secret?`password`:_.type,autoComplete:e.secret?`off`:_.autoComplete,value:t,placeholder:e.placeholder??void 0,maxLength:e.maxLength??void 0,disabled:i,"aria-required":m,"aria-invalid":p,"aria-describedby":f,onChange:e=>s(e.target.value),ref:u});return/* @__PURE__ */ K(`div`,{className:`wui-chat-field`,"data-key":e.key,children:[/* @__PURE__ */ G(`label`,{className:`form-label`,htmlFor:a,children:e.label}),g,v,h]})}function jn({part:e,turn:t}){let{labels:n,features:r}=t,i=_(),[a,o]=x(()=>En(e.fields)),[s,c]=x({}),[l,u]=x(null),[d,f]=x(!1),[p,m]=x(null),[h,v]=x({}),y=b({}),S=b({});g(()=>{p&&y.current[p.key]?.focus()},[p]);let C=e.fields.length===1?e.fields[0]:null,w=r.LeadShortcuts&&C!==null&&!C.required,T=r.LeadShortcuts&&e.cancellable,E=Object.values(h).some(e=>e.status===`uploading`);function D(t){return e.fields.find(e=>t[e.key])?.key??e.fields[0]?.key}function O(e,t){o(n=>({...n,[e]:t}))}async function k(e,r){let i={};S.current[e]=i,v(t=>({...t,[e]:{status:`uploading`,name:r.name}})),O(e,``),c(t=>({...t,[e]:void 0}));let a;try{a=await t.uploadInputFile(r)}catch{if(S.current[e]!==i)return;v(t=>({...t,[e]:{status:`failed`,name:r.name}})),c(t=>({...t,[e]:n.attachmentFailed}));return}S.current[e]===i&&(O(e,a),v(t=>({...t,[e]:{status:`ready`,name:r.name}})),c(t=>({...t,[e]:void 0})))}function A(e){S.current[e]=null,O(e,``),v(t=>Object.fromEntries(Object.entries(t).filter(([t])=>t!==e))),c(t=>({...t,[e]:void 0}))}async function j(r){if(r.preventDefault(),E){let e=Object.keys(h).find(e=>h[e]?.status===`uploading`);c(t=>({...t,[e]:n.attachmentUploading})),m({key:e});return}let i={};for(let t of e.fields){let e=t.type===`File`&&h[t.key]?.status===`failed`?n.attachmentFailed:On(t,a[t.key],n);e&&(i[t.key]=e)}if(u(null),c(i),Object.keys(i).length>0){m({key:D(i)});return}f(!0);let o=Object.fromEntries(e.fields.map(e=>[e.key,kn(e,a[e.key])])),s;try{s=await t.answerInput(e.requestId,o)}catch{s={ok:!1,errors:{},message:n.errorGeneric}}if(s.ok)return;let l=Object.entries(s.errors).filter(([t])=>!e.fields.some(e=>e.key===t)).map(([,e])=>e),d=[s.message,...l].filter(Boolean);c(s.errors),u(d.length>0?d.join(` `):null),f(!1),m({key:D(s.errors)})}return/* @__PURE__ */ K(`form`,{className:`wui-chat-input-form`,noValidate:!0,"aria-label":e.title||e.submitLabel,onSubmit:j,children:[e.title&&/* @__PURE__ */ G(`h3`,{className:`wui-chat-input-title`,children:e.title}),e.fields.map(e=>/* @__PURE__ */ G(An,{field:e,value:a[e.key],error:s[e.key],file:h[e.key],disabled:d,id:`${i}-${e.key}`,labels:n,onChange:t=>O(e.key,t),onFile:t=>k(e.key,t),onRemove:()=>A(e.key),controlRef:t=>{y.current[e.key]=t}},e.key)),/* @__PURE__ */ G(`p`,{className:`wui-chat-input-error`,role:`status`,hidden:!l,children:l}),/* @__PURE__ */ K(`div`,{className:`d-flex flex-wrap gap-2`,children:[/* @__PURE__ */ G(`button`,{className:`btn btn-primary`,type:`submit`,"data-wui":`AppButton`,disabled:d,children:d?n.inputSubmitting:e.submitLabel}),w&&/* @__PURE__ */ G(`button`,{className:`btn btn-soft-primary`,type:`button`,"data-wui":`AppButton`,disabled:d,onClick:()=>t.skipInput(e.requestId),children:n.skip}),T&&/* @__PURE__ */ G(`button`,{className:`btn btn-link`,type:`button`,disabled:d,onClick:()=>t.cancelLead(),children:n.cancel})]}),e.allowTyped&&/* @__PURE__ */ G(`p`,{className:`wui-chat-input-typed`,children:n.typeAnswer})]})}function Mn({part:e,message:t,turn:n}){if(e.fields.some(e=>!xn.includes(e.type)))return/* @__PURE__ */ G(bn,{part:{kind:`Notice`,code:`NeedsNewerApp`,text:n.labels.needsNewerApp},message:t,turn:n});let r=`wui-chat-input-request wui-chat-input-request--${e.state.toLowerCase()}`;return/* @__PURE__ */ G(`div`,{className:r,children:e.state===`Open`?/* @__PURE__ */ G(jn,{part:e,turn:n},e.requestId):/* @__PURE__ */ G(`p`,{className:`wui-chat-input-summary`,children:wn(e,n.labels)})})}var Nn=p({resolveLink:null,linkComponent:null});function Pn(){return h(Nn)}var Fn={Primary:`wui-chat-quick-reply--primary`,Cta:`wui-chat-quick-reply--cta`};function In(e,t){return e.action===`Navigate`?!!t.features.LinkHandoff:e.action!==`Open`||!!e.target&&!!t.openTarget}function Ln(e,t){return[`wui-chat-quick-reply`,Fn[e.variant],t].filter(Boolean).join(` `)}function Rn(e,t,n){return L(e.target,t.handoffHosts)?n?n(e.target):e.target:null}function zn(e){return e.icon?/* @__PURE__ */ G(`span`,{className:`wui-chat-quick-reply-icon`,"aria-hidden":`true`,children:/* @__PURE__ */ G(a,{name:e.icon,size:16})}):null}function Bn(e,t,n,r){return/* @__PURE__ */ K(`button`,{type:`button`,className:r,style:n,onClick:n=>{e.action===`Open`?t.openTarget(e.target):(t.chooseQuickReply(e),n.currentTarget.closest(`.wui-chat`)?.querySelector(`.wui-chat-input`)?.focus())},children:[zn(e),/* @__PURE__ */ G(`span`,{className:`wui-chat-quick-reply-label`,children:e.label})]},e.id)}function Vn({part:e,turn:t}){let{resolveLink:n}=Pn();if(!t.features.SuggestedReplies||!t.isLast||t.busy||e.replies.length===0)return null;let r=e.placement===`Composer`?`wui-chat-quick-replies wui-chat-quick-replies--composer`:`wui-chat-quick-replies`,i=e.replies.filter(e=>In(e,t));if(i.length===0)return null;let a=t.openTarget??(e=>globalThis.location.assign(e)),o=e.placement===`Composer`?void 0:i.find(e=>e.id===C&&e.action===`Send`);return/* @__PURE__ */ K(`div`,{className:o?`${r} wui-chat-quick-replies--offer`:r,role:`group`,"aria-label":t.labels.quickReplies,children:[o&&/* @__PURE__ */ K(`div`,{className:`wui-chat-offer`,children:[/* @__PURE__ */ G(`div`,{className:`wui-chat-offer-title`,children:o.label}),Bn(o,t,{"--wui-chat-i":0},Ln({...o,variant:`Primary`},`wui-chat-offer-action`))]}),i.map((e,r)=>{if(e===o)return null;let i={"--wui-chat-i":r};if(e.action===`Navigate`){let r=Rn(e,t,n);return r===null?/* @__PURE__ */ G(`span`,{className:`wui-chat-quick-reply-label`,style:i,children:e.label},e.id):typeof t.beginHandoff==`function`?/* @__PURE__ */ K(`button`,{type:`button`,disabled:t.handoffPause,className:Ln(e,t.handoffPause?`wui-chat-quick-reply--quiet`:void 0),style:i,onClick:()=>t.beginHandoff(e,()=>a(r)),children:[zn(e),/* @__PURE__ */ G(`span`,{className:`wui-chat-quick-reply-label`,children:t.handoffPause?t.labels.handoffMoment:e.label})]},e.id):null}return Bn(e,t,i,Ln(e,o?`wui-chat-quick-reply--quiet`:void 0))})]})}var Hn=/* @__PURE__ */ new Set([`Integer`,`Decimal`,`MoneyMinor`,`Percent`]);function Un(e){return e.value===null||e.value===void 0||e.value===``?_e:e.type===`Date`?q(e.value,{pattern:`day`}):e.type===`DateTimeUtc`?ve(e.value):N(e.value,e.type,null)}function Wn({part:e,turn:n}){let r=_(),a=n.features.FigureText,o=e.fields.map(e=>({label:/* @__PURE__ */ G(Q,{text:e.label,enabled:a}),value:/* @__PURE__ */ G(`span`,{className:Hn.has(e.type)?`wui-chat-num`:void 0,children:/* @__PURE__ */ G(Q,{text:Un(e),enabled:a})})})),s=!!e.target&&typeof n.openRecord==`function`;return/* @__PURE__ */ K(`article`,{className:`wui-chat-record`,"aria-labelledby":r,children:[/* @__PURE__ */ K(`header`,{className:`wui-chat-record-head`,children:[/* @__PURE__ */ G(`h3`,{className:`wui-chat-record-title`,id:r,children:/* @__PURE__ */ G(Q,{text:e.title,enabled:a})}),e.subtitle?/* @__PURE__ */ G(`p`,{className:`wui-chat-record-subtitle`,children:/* @__PURE__ */ G(Q,{text:e.subtitle,enabled:a})}):null]}),e.fields.length>0?/* @__PURE__ */ G(i,{className:`wui-chat-record-fields`,columns:1,size:`sm`,layout:`summary`,items:o}):null,s?/* @__PURE__ */ G(`div`,{className:`wui-chat-record-actions`,children:/* @__PURE__ */ G(t,{className:`wui-chat-record-open`,size:`sm`,type:`button`,"aria-label":n.labels.recordOpenFor(B(e.title)),onClick:()=>n.openRecord(e),children:n.labels.recordOpen})}):null]})}var Gn=/^https?:\/\//i;function Kn({source:e}){return/* @__PURE__ */ K(W,{children:[/* @__PURE__ */ G(`span`,{className:`wui-chat-source-marker`,children:e.marker}),/* @__PURE__ */ G(`span`,{className:`wui-chat-source-title`,children:e.title})]})}function qn({part:e,turn:t}){return!t.features.Sources||e.sources.length===0?null:/* @__PURE__ */ K(`div`,{className:`wui-chat-sources`,children:[/* @__PURE__ */ G(`p`,{className:`wui-chat-sources-label`,children:t.labels.sources}),/* @__PURE__ */ G(`ul`,{className:`wui-chat-sources-list`,"aria-label":t.labels.sources,children:e.sources.map(e=>/* @__PURE__ */ G(`li`,{children:Gn.test(e.url??``)?/* @__PURE__ */ G(`a`,{className:`wui-chat-source`,href:e.url,target:`_blank`,rel:`noopener noreferrer`,"aria-label":t.labels.openSource(e.title),"data-marker":e.marker,children:/* @__PURE__ */ G(Kn,{source:e})}):/* @__PURE__ */ G(`span`,{className:`wui-chat-source`,tabIndex:-1,"data-marker":e.marker,children:/* @__PURE__ */ G(Kn,{source:e})})},e.marker))})]})}var Jn=/* @__PURE__ */ new Set([`Integer`,`Decimal`,`MoneyMinor`,`Percent`]),Yn=50,Xn=25;function Zn(e){return e.id}function Qn(e,t,n,r){return e==null?null:t.type===`Text`&&e!==``?/* @__PURE__ */ G(Q,{text:e,enabled:r}):N(e,t.type,n)}function $n({part:e,turn:n}){let[i,a]=x(!1),o=n.features.FigureText,s=e.columns.map((e,t)=>({key:`c${t}`,label:/* @__PURE__ */ G(Q,{text:e.label,enabled:o}),...Jn.has(e.type)?{align:`num`}:{}})),c=e.rows.map((t,n)=>{let r={id:n};return e.columns.forEach((n,i)=>{r[`c${i}`]=Qn(t[i],n,e.currency,o)}),r}),l=i?c:c.slice(0,Xn),u=l.length>Yn;return/* @__PURE__ */ K(`div`,{className:`wui-chat-table`,children:[e.title?/* @__PURE__ */ G(`p`,{className:`wui-chat-rich-title`,children:/* @__PURE__ */ G(Q,{text:e.title,enabled:o})}):null,/* @__PURE__ */ G(r,{density:`cozy`,ariaLabel:e.title?Zt(e.title,o):n.labels.table,columns:s,rows:l,rowKey:Zn,empty:n.labels.tableEmpty,maxHeight:u?360:void 0,virtual:u}),!i&&c.length>Xn&&/* @__PURE__ */ G(t,{variant:`soft`,tone:`primary`,size:`sm`,className:`wui-chat-table-more`,onClick:()=>a(!0),children:n.labels.tableShowAll(c.length)})]})}var er=/* @__PURE__ */ new Set([`Visitor`,`Customer`]),tr=/^\d+$/;function nr({part:e,message:t,turn:n}){let{resolveLink:r,linkComponent:i}=Pn(),a=n.features.FigureText,o=n.features.Sources===!0;if(er.has(t.author.kind))return/* @__PURE__ */ G(`div`,{className:t.restored?`wui-chat-bubble`:`wui-chat-bubble wui-chat-part-enter`,children:/* @__PURE__ */ G(Q,{text:e.text,enabled:a})});let c=n.handoffHosts,l=e=>L(e,c)?e:r?r(e):null,u=o&&n.openCitation?e=>n.openCitation(Number(e)):void 0,d=o?n.isCitation??(e=>tr.test(e)):()=>!1;return/* @__PURE__ */ G(s,{value:e.text,links:`app`,headings:`text`,className:t.restored?`wui-chat-text`:`wui-chat-text wui-chat-part-enter`,resolveLink:l,linkComponent:i||void 0,isCitation:d,onOpenCitation:u})}function rr({part:n,turn:r}){let{labels:i}=r,o=i.ticketStatus(n.status);return/* @__PURE__ */ K(`div`,{className:`wui-chat-ticket`,children:[/* @__PURE__ */ G(`span`,{className:`wui-chat-ticket-icon`,"aria-hidden":`true`,children:/* @__PURE__ */ G(a,{name:`tag`,size:20})}),/* @__PURE__ */ K(`div`,{className:`wui-chat-ticket-body`,children:[/* @__PURE__ */ K(`div`,{className:`wui-chat-ticket-head`,children:[/* @__PURE__ */ G(`strong`,{className:`wui-chat-ticket-number`,children:i.ticketAria(n.number)}),o&&/* @__PURE__ */ G(e,{className:`wui-chat-ticket-status`,tone:qe(n.status),children:o})]}),/* @__PURE__ */ G(`p`,{className:`wui-chat-ticket-subject`,children:n.subject})]}),r.openTicket&&/* @__PURE__ */ G(t,{variant:`outline`,size:`sm`,className:`wui-chat-ticket-open`,onClick:()=>r.openTicket(n),children:i.ticketView})]})}var ir=40,$=null;function ar({part:e,turn:t}){let[n,r]=x(!1),[i,o]=x(!1),[s,c]=x(!1),[l,u]=x(!1),[d,f]=x(0),p=b(null),h=b(null),_=b(!1),v=y(()=>H(`${e.attachmentId}|${e.durationMs}`,ir).map((e,t)=>({id:`bar-${t}`,position:t,height:e})),[e.attachmentId,e.durationMs]),S=m(()=>{p.current?.pause(),$===S&&($=null),o(!1)},[]);if(g(()=>(_.current=!0,()=>{_.current=!1,p.current?.pause(),h.current&&URL.revokeObjectURL(h.current),$===S&&($=null)}),[S]),!t.features.VoiceClips)return e.transcript?/* @__PURE__ */ G(`p`,{className:`wui-chat-clip-transcript`,children:e.transcript}):null;async function C(){if(i)S();else{r(!0),c(!1);try{if(!p.current){let n=await t.readAttachment(e.attachmentId);if(!_.current)return;h.current=URL.createObjectURL(new Blob([n]));let r=new Audio(h.current);r.addEventListener(`timeupdate`,()=>f(r.currentTime)),r.addEventListener(`ended`,()=>{o(!1),f(0),r.currentTime=0,$===S&&($=null)}),r.addEventListener(`error`,()=>{c(!0),o(!1)}),p.current=r}$?.(),await p.current.play(),$=S,o(!0)}catch{c(!0)}finally{_.current&&r(!1)}}}let w=e.durationMs/1e3,T=Math.floor((w>0?Math.min(1,d/w):0)*ir);return/* @__PURE__ */ K(`div`,{className:`wui-chat-clip`,role:`group`,"aria-label":t.labels.voiceClip,children:[/* @__PURE__ */ K(`div`,{className:`wui-chat-clip-row`,children:[/* @__PURE__ */ G(`button`,{type:`button`,className:`wui-chat-clip-play`,"aria-label":i?t.labels.voiceClipPause:t.labels.voiceClipPlay,"aria-busy":n,disabled:n,onClick:C,children:/* @__PURE__ */ G(a,{name:i?`pause`:`play`,size:16,"aria-hidden":`true`})}),/* @__PURE__ */ G(`div`,{className:`wui-chat-clip-wave`,"aria-hidden":`true`,children:v.map(({id:e,position:t,height:n})=>/* @__PURE__ */ G(`span`,{className:t<T?`wui-chat-clip-bar wui-chat-clip-bar--played`:`wui-chat-clip-bar`,style:{"--wui-chat-bar-height":`${Math.round(n*100)}%`}},e))}),/* @__PURE__ */ G(`span`,{className:`wui-chat-clip-time`,children:t.labels.voiceClipTime(P(d),P(Math.max(1,Math.round(w))))})]}),s&&/* @__PURE__ */ G(`p`,{className:`wui-chat-clip-error`,role:`status`,children:t.labels.voiceClipFailed}),e.transcript?/* @__PURE__ */ K(W,{children:[/* @__PURE__ */ G(`button`,{type:`button`,className:`wui-chat-clip-toggle`,"aria-expanded":l,onClick:()=>u(!l),children:l?t.labels.voiceClipHideTranscript:t.labels.voiceClipShowTranscript}),l&&/* @__PURE__ */ G(`p`,{className:`wui-chat-clip-transcript`,children:e.transcript})]}):null]})}var or={Text:nr,Sources:qn,QuickReplies:Vn,InputRequest:Mn,Action:Xt,Notice:bn,Table:$n,Chart:tn,Figures:un,RecordCard:Wn,Image:gn,File:dn,Ticket:rr,Handoff:mn,VoiceClip:ar},sr=48,cr={Visitor:`you`,Customer:`you`,Agent:`agent`,Assistant:`assistant`,Script:`assistant`,System:`assistant`},lr={kind:`Notice`,code:`NeedsNewerApp`};function ur(e,t){let n=e.author.kind;return e.author.displayName&&n!==`Visitor`&&n!==`Customer`?e.author.displayName:t[cr[n]??`assistant`]}function dr(e,t){for(let n=e.length-1;n>=0;--n)if(t(e[n]))return n;return-1}function fr(e,t){let n=/* @__PURE__ */ new Map,r=[];for(let i of e){let e=t(i),a=n.get(e)??0;n.set(e,a+1),r.push({key:`${e}#${a}`,item:i})}return r}function pr({chat:e,labels:n,renderers:r,layoutParts:i,loader:a,motion:o,onOpenAttachment:s,onOpenTarget:c,onOpenTicket:l,onNavigate:u}){let d=b(null),f=b(!0),p=b(/* @__PURE__ */ new Map),m={...or,...r},h=u??e.onNavigate,_=e.pending?.authorKind,v=_===`Agent`||_===`Customer`?`None`:a===`Orb`?`Orb`:`Assistant`,y=e.messages.at(-1),x=e.messages.find(e=>!(e.streaming&&e.parts.length===0)),S=e.greeting&&x&&(x.author.kind===`Visitor`||x.author.kind===`Customer`)?{id:`greeting`,author:{kind:`Assistant`,displayName:null},parts:[{kind:`Text`,text:e.greeting}],stored:!1,streaming:!1,restored:!1}:null,C=S?[S,...e.messages]:e.messages,w=C.filter(e=>!(e.streaming&&e.parts.length===0)),T=!e.streaming&&(e.turnError!==null||e.stopped),E=e.turnError?.code===`daily_limit`,D=typeof e.turnError?.code==`string`&&e.turnError.code.endsWith(`feature_off`),O=e.pending?.typing===!0,k=`${y?Et(y):``}|${e.thinking}|${O}|${T}`,j=dr(e.messages,e=>e.author.kind===`Visitor`&&e.stored),M=e.profile?.experience.pacing,N=e.profile?.assistant.name??``;g(()=>{if(!k)return;let e=Tt(d.current);e&&(e.scrollTop=e.scrollHeight,f.current=!0)},[k]),g(()=>{let e=d.current;if(!e||typeof ResizeObserver!=`function`)return;let t=null,n=()=>{f.current=t.scrollHeight-t.scrollTop-t.clientHeight<=sr},r=new ResizeObserver(()=>{let r=Tt(e);r!==t&&(t?.removeEventListener(`scroll`,n),t=r,t?.addEventListener(`scroll`,n,{passive:!0})),t&&f.current&&(t.scrollTop=t.scrollHeight)});return r.observe(e),()=>{t?.removeEventListener(`scroll`,n),r.disconnect()}},[]);function P(e,t){p.current.get(e)?.querySelector(`[data-marker="${t}"]`)?.focus()}function F(e,t,r,i){let a=Object.hasOwn(m,r.kind),o=a?r:{...lr,text:n.needsNewerApp},s=o.kind.toLowerCase(),c=a?m[r.kind]:m.Notice;return/* @__PURE__ */ G(`div`,{className:`wui-chat-part wui-chat-part--${s}`,children:/* @__PURE__ */ G(c,{part:o,message:e,turn:t})},i)}return/* @__PURE__ */ K(`ol`,{ref:d,className:`wui-chat-thread`,"aria-label":n.thread,"aria-live":`polite`,children:[C.map((t,r)=>{if(t.streaming&&t.parts.length===0)return null;let a=A(e.session,{messageId:t.id,labels:n,openAttachment:s??(t=>Ct(e.client,t)),openTarget:c??wt,...l?{openTicket:l}:{},openCitation:e=>P(t.id,e),onNavigate:h}),o=t===S,u=S?r-1:r,d=w[w.indexOf(t)-1],f=t.author.kind===`Agent`&&d?.author.kind===`Agent`&&(d.author.displayName??``)===(t.author.displayName??``),m=i?i(t):null;return/* @__PURE__ */ K(`li`,{ref:e=>{e?p.current.set(t.id,e):p.current.delete(t.id)},className:`wui-chat-message wui-chat-message--${t.author.kind.toLowerCase()}`,"aria-busy":t.streaming?`true`:void 0,"data-restored":t.restored?``:void 0,children:[/* @__PURE__ */ G(`span`,{className:`wui-chat-author visually-hidden`,children:`${ur(t,n)}: `}),f?null:/* @__PURE__ */ G(pt,{author:t.author,labels:n}),/* @__PURE__ */ G(`div`,{className:`wui-chat-message-body`,children:m?fr(m,e=>Array.isArray(e)?`group`:`part`).map(({key:e,item:n})=>/* @__PURE__ */ G(`div`,{className:`wui-chat-part-group`,children:fr(Array.isArray(n)?n:[n],e=>e.kind).map(({key:e,item:n})=>F(t,a,n,e))},e)):fr(t.parts,e=>e.kind).map(({key:e,item:n})=>F(t,a,n,e))}),o?null:/* @__PURE__ */ G(`div`,{className:`wui-chat-message-actions`,children:/* @__PURE__ */ G(kt,{chat:e,message:t,labels:n,isLast:t===y,isLastVisitor:!o&&u===j})})]},t.id)}),/* @__PURE__ */ G(ft,{chat:e,labels:n}),O&&/* @__PURE__ */ G(`li`,{className:`wui-chat-message wui-chat-message--assistant wui-chat-message--loading`,children:/* @__PURE__ */ G(`div`,{className:`wui-chat-loader-slot`,children:/* @__PURE__ */ G(Ht,{motion:o,mark:v})})}),e.thinking&&/* @__PURE__ */ G(`li`,{className:`wui-chat-message wui-chat-message--assistant wui-chat-message--loading`,children:/* @__PURE__ */ G(`div`,{className:`wui-chat-loader-slot`,children:/* @__PURE__ */ G(Vt,{style:a,steps:e.steps,phrases:M?.thinkingPhrases??[],intervalMs:M?.phraseIntervalMs??2500,announce:n.preparingAnswer(N),motion:o})})}),T&&/* @__PURE__ */ K(`li`,{className:`wui-chat-message wui-chat-message--system wui-chat-message--error`,children:[E?/* @__PURE__ */ K(`p`,{className:`wui-chat-error wui-chat-error--info`,role:`status`,children:[e.turnError.message,e.turnError.resetsDateTimeUtc?` ${n.dailyLimitRefresh(nt(e.turnError.resetsDateTimeUtc))}`:``]}):/* @__PURE__ */ G(`p`,{className:`wui-chat-error`,role:`alert`,children:e.turnError?.message??n.stopped}),e.features.Retry&&!E&&!D&&/* @__PURE__ */ G(`div`,{className:`wui-chat-message-actions`,children:/* @__PURE__ */ G(t,{className:`wui-chat-action-btn`,size:`sm`,variant:`ghost`,onClick:()=>e.retry(),children:n.retry})})]})]})}var mr=e=>e===`Assistant`||e===`Script`||e===`Agent`;function hr(e,t,n){if(t){e.wasLoading=!0;for(let t of n)e.seen.add(t.id);return[]}if(e.wasLoading||!e.seeded){e.wasLoading=!1,e.seeded=!0;for(let t of n)e.seen.add(t.id);return[]}let r=[];for(let t of n)e.seen.has(t.id)||(e.seen.add(t.id),r.push(t));return r}function gr(e){let t=e.features.Sounds?e.profile?.experience.sound??null:null,n=b(null),r=b(e);r.current=e;let i=b(e.open),a=b({seen:/* @__PURE__ */ new Set,seeded:!1,wasLoading:!1}),o=t!==null&&(t.open||t.sent||t.reply||t.vibrate);g(()=>{if(!o)return;let e=oe(t,xt);return n.current=e,e.setMuted(r.current.muted),()=>{e.destroy(),n.current=null}},[o,t]);let{open:s,loading:c,messages:l,muted:u}=e;g(()=>{n.current?.setMuted(u)},[u]),g(()=>{let e=n.current,o=i.current;i.current=s;let u=hr(a.current,c,l);if(e){s&&!o&&e.play(`open`);for(let n of u){if(n.restored||n.parts.some(e=>e.kind===`Notice`))continue;let i=n.author.kind;i===`Visitor`?n.stored||e.play(`sent`):mr(i)&&(e.play(`reply`),t.vibrate&&pe(t.vibrateMs,r.current.muted))}}},[s,c,l,t])}function _r({chat:e,labels:t,layout:n,onClose:r,panelId:i,inputRef:o,ariaLabelOverride:s,renderers:c,layoutParts:l,loader:u,motion:d,onOpenAttachment:f,onOpenTarget:p,onOpenTicket:m,onNavigate:h,resolveLink:g=null,linkComponent:_=null,onSwitch:v,open:b=!0,renderEmpty:S}){let[C,w]=x(`chat`),T=y(()=>({resolveLink:g,linkComponent:_}),[g,_]);gr(e);let{features:E}=e,D=e.profile,O=C===`history`&&E.History===!0,k=e.messages.length>0,A=n===`launcher`||n===`docked`,j=D?.experience.sound,M=!!(E.Sounds&&j?.muteControl),N=A?`dialog`:`region`,P=s??D?.assistant.name??t.panelTitle,F=E.PanelSwitch===!0,I=n===`full-page`||n===`embedded`||k,L=F&&typeof v==`function`&&(n===`docked`||n===`full-page`),ee=n===`full-page`&&F&&typeof r==`function`;function te(){w(`chat`),r?.()}function ne(){if(e.profileError)return/* @__PURE__ */ G(`p`,{className:`wui-chat-profile-error`,role:`alert`,children:e.profileError.message});if(!D&&(n===`full-page`||n===`embedded`)||e.loading)return/* @__PURE__ */ G(`p`,{role:`status`,"aria-busy":`true`,children:t.loadingConversation});if(e.loadError)return/* @__PURE__ */ G(`p`,{className:`wui-chat-profile-error`,role:`alert`,children:e.loadError.message});if(!k){let n=/* @__PURE__ */ K(W,{children:[/* @__PURE__ */ G(dt,{chat:e,labels:t,onOpenTicket:m}),E.History&&/* @__PURE__ */ G(ct,{chat:e,labels:t,open:b})]});return S?S({chat:e,labels:t,open:b,defaultEmpty:n}):n}return/* @__PURE__ */ G(Nn.Provider,{value:T,children:/* @__PURE__ */ G(pr,{chat:e,labels:t,renderers:c,layoutParts:l,loader:u,motion:d,onOpenAttachment:f,onOpenTarget:p,onOpenTicket:m,onNavigate:h})})}return/* @__PURE__ */ K(`section`,{id:i,className:`wui-chat-panel`,role:N,"aria-label":P,children:[/* @__PURE__ */ K(`header`,{className:`wui-chat-header`,children:[/* @__PURE__ */ G(`span`,{className:`wui-chat-orb`,"aria-hidden":`true`}),/* @__PURE__ */ K(`div`,{className:`wui-chat-header-text`,children:[/* @__PURE__ */ G(`strong`,{className:`wui-chat-title`,children:D?.assistant.name??``}),/* @__PURE__ */ G(`span`,{className:`wui-chat-status`,children:Ye(e,t)??t.headerStatus})]}),/* @__PURE__ */ K(`div`,{className:`wui-chat-header-actions`,children:[!O&&/* @__PURE__ */ G(Be,{chat:e,labels:t}),E.History&&(O?/* @__PURE__ */ G(`button`,{type:`button`,className:`wui-chat-icon-btn`,"aria-label":t.backToChat,title:t.backToChat,onClick:()=>w(`chat`),children:/* @__PURE__ */ G(a,{name:`arrow-left`,size:18,"aria-hidden":`true`})}):/* @__PURE__ */ G(`button`,{type:`button`,className:`wui-chat-icon-btn`,"aria-label":t.history,title:t.history,onClick:()=>w(`history`),children:/* @__PURE__ */ G(a,{name:`history`,size:18,"aria-hidden":`true`})})),M&&/* @__PURE__ */ G(`button`,{type:`button`,className:`wui-chat-icon-btn`,"aria-label":e.muted?t.unmuteSounds:t.muteSounds,title:e.muted?t.unmuteSounds:t.muteSounds,onClick:()=>e.session.setMuted(!e.muted),children:/* @__PURE__ */ G(a,{name:e.muted?`volume-mute`:`volume-high`,size:18,"aria-hidden":`true`})}),!O&&I&&/* @__PURE__ */ G(`button`,{type:`button`,className:`wui-chat-icon-btn`,"aria-label":t.newChat,title:t.newChat,disabled:e.streaming||e.thinking,onClick:()=>e.newConversation(),children:/* @__PURE__ */ G(a,{name:`plus`,size:18,"aria-hidden":`true`})}),L&&/* @__PURE__ */ G(`button`,{type:`button`,className:`wui-chat-icon-btn wui-chat-icon-btn--switch`,"aria-label":n===`docked`?t.openFullScreen:t.openSidePanel,title:n===`docked`?t.openFullScreen:t.openSidePanel,disabled:e.streaming||e.thinking,onClick:()=>v(),children:/* @__PURE__ */ G(a,{name:n===`docked`?`maximize-4`:`panel-left-open`,size:18,"aria-hidden":`true`})}),(A||ee)&&/* @__PURE__ */ G(`button`,{type:`button`,className:`wui-chat-icon-btn`,"aria-label":t.close,title:t.close,onClick:te,children:/* @__PURE__ */ G(a,{name:`x`,size:18,"aria-hidden":`true`})})]})]}),/* @__PURE__ */ G(`div`,{className:`wui-chat-body`,children:O?/* @__PURE__ */ G(We,{chat:e,labels:t,onOpen:()=>w(`chat`)}):ne()}),!O&&/* @__PURE__ */ K(`div`,{className:`wui-chat-foot`,children:[/* @__PURE__ */ G(Ze,{chat:e,labels:t}),/* @__PURE__ */ G(Me,{chat:e,labels:t,maxLength:D?.limits.maxMessageLength??4e3,inputRef:o}),/* @__PURE__ */ G(Ve,{chat:e,labels:t})]})]})}function vr(e,t){let n=b(!1);g(()=>{n.current||(n.current=!0,typeof t?.conversationId==`string`&&t.conversationId!==``&&e.openConversation(t.conversationId),typeof t?.draft==`string`&&t.draft!==``&&e.session.open({draft:t.draft}))},[e,t])}function yr(e,t){let[n,r]=x(!1);return g(()=>{let n=he(e,t??null);r(n.reduced);let i=n.subscribe(()=>r(n.reduced));return()=>{i(),n.destroy()}},[e,t]),n}function br({chat:e,labels:t,renderers:n,layoutParts:r,loader:i,motion:a=`On`,onOpenAttachment:o,onOpenTarget:s,onNavigate:c,resolveLink:l,linkComponent:u,className:d,style:f,theme:p,look:m,onOpenSidePanel:h,onClose:g,renderEmpty:_,handoff:v}){let y=b(null);vr(e,v??null);let x=e.features.PanelSwitch===!0&&typeof h==`function`?()=>{let t={conversationId:e.conversationId,draft:y.current?.value??``,from:`full-page`,to:`docked`};de(()=>h(t),{target:`docked`}).catch(e=>globalThis.reportError?.(e))}:void 0;return/* @__PURE__ */ G(xr,{layout:`full-page`,chat:e,labelOverrides:t,renderers:n,layoutParts:r,loader:i,motion:a,onOpenAttachment:o,onOpenTarget:s,onNavigate:c,resolveLink:l,linkComponent:u,className:d,style:f,theme:p,look:m,inputRef:y,onSwitch:x,onClose:g,renderEmpty:_})}function xr({layout:e,chat:t,labelOverrides:n,renderers:r,layoutParts:i,loader:a,motion:o,onOpenAttachment:s,onOpenTarget:c,onNavigate:l,resolveLink:u=null,linkComponent:d=null,className:f,style:p,theme:m,look:h,inputRef:g,onSwitch:_,onClose:v,renderEmpty:b}){let x=y(()=>te(n),[n]),S=yr(y(()=>ne(h),[h]),t.profile?.experience??null),C=o===`Reduced`||S?`Reduced`:`On`;if(t.profile!==null&&!t.features.VisitorChat)return null;let w=[`wui-chat`,`wui-chat--${e}`,Dt(C),f].filter(Boolean).join(` `);return/* @__PURE__ */ G(`div`,{className:w,style:p,"data-state":`open`,"data-theme":m===`auto`?void 0:m,children:/* @__PURE__ */ G(_r,{chat:t,labels:x,layout:e,panelId:void 0,renderers:r,layoutParts:i,loader:a,motion:C,onOpenAttachment:s,onOpenTarget:c,onNavigate:l,resolveLink:u,linkComponent:d,inputRef:g,onSwitch:_,onClose:v,renderEmpty:b})})}function Sr(e){return/* @__PURE__ */ G(xr,{...e,layout:`embedded`})}var Cr=`a[href], button:not([disabled]), input:not([disabled]), [tabindex]:not([tabindex="-1"])`;function wr(e){let t=b(null);return g(()=>{let n=document.activeElement;return t.current?.querySelector(Cr)?.focus({preventScroll:!0}),()=>(e.current??n)?.focus?.({preventScroll:!0})},[e]),g(()=>{let e=t.current;if(!e||typeof ResizeObserver>`u`)return;let n=0,r=new ResizeObserver(()=>{cancelAnimationFrame(n),n=requestAnimationFrame(()=>window.dispatchEvent(new Event(`scroll`)))});return r.observe(e),()=>{cancelAnimationFrame(n),r.disconnect()}},[]),t}function Tr({x:e,labels:n,renderAnswer:r,renderFoot:i,askDraft:a,chat:o,close:s,triggerRef:c}){let l=wr(c),{state:u,answer:d,pillVisible:f,resetsDateTimeUtc:p}=e,m=null;if((u===`thinking`||u===`slow`)&&f)m=/* @__PURE__ */ K(`div`,{className:`wui-chat-explain-pill`,role:`status`,children:[/* @__PURE__ */ G(`span`,{className:`wui-chat-explain-pill-dot`,"aria-hidden":`true`}),/* @__PURE__ */ G(`span`,{children:u===`slow`?n.explainSlow:n.thinking})]});else if(u===`answered`)m=/* @__PURE__ */ G(`div`,{className:`wui-chat-explain-answer`,children:r({answer:d,labels:n,close:s})});else if(u===`empty`)m=/* @__PURE__ */ G(`p`,{className:`wui-chat-explain-note`,children:n.explainEmpty});else if(u===`capacity`){let e=nt(p);m=/* @__PURE__ */ G(`p`,{className:`wui-chat-explain-notice wui-chat-explain-notice--info`,role:`status`,children:e?n.explainCapacity(e):n.explainCapacityNoDate})}else u===`error`&&(m=/* @__PURE__ */ K(`div`,{className:`wui-chat-explain-notice wui-chat-explain-notice--error`,role:`alert`,children:[/* @__PURE__ */ G(`p`,{children:n.explainError}),/* @__PURE__ */ G(t,{className:`wui-chat-action-btn`,size:`sm`,variant:`ghost`,onClick:()=>e.ask(),children:n.explainRetry})]}));let h=typeof a==`string`&&a!==``&&typeof o.session?.open==`function`;return/* @__PURE__ */ K(`div`,{ref:l,className:`wui-chat-explain`,children:[m,/* @__PURE__ */ K(`div`,{className:`wui-chat-explain-foot`,children:[i?.({close:s}),h&&/* @__PURE__ */ G(t,{className:`wui-chat-explain-more`,size:`sm`,variant:`ghost`,onClick:()=>{s(),o.session.open({draft:a})},children:n.explainAskMore}),/* @__PURE__ */ G(`p`,{className:`wui-chat-explain-note`,children:n.explainNotCounted})]})]})}function Er({chat:e,request:t,renderAnswer:n,label:r,renderFoot:i,askDraft:o,labels:s,placement:c=`auto`,className:u,triggerContent:f}){let p=y(()=>te(s),[s]),[m,h]=x(!1),_=tt({request:t,enabled:e.features.Explain===!0}),v=b(null),S=b(!1);if(g(()=>{if(!m)return;let e=e=>{S.current=!!e.target?.closest?.(`.wui-chat-panel`)};return document.addEventListener(`pointerdown`,e,!0),()=>document.removeEventListener(`pointerdown`,e,!0)},[m]),!e.features.Explain)return null;function C(e){!e&&(S.current||document.querySelector(`.wui-chat--docked[data-open=true]`))?S.current=!1:(h(e),e?_.ask():_.reset())}function w(){h(!1),_.reset()}let T=/* @__PURE__ */ K(`button`,{type:`button`,className:[`wui-chat-explain-trigger`,m?`wui-chat-explain-trigger--open`:null].filter(Boolean).join(` `),"aria-haspopup":`dialog`,"aria-label":p.explainTriggerLabel(r),disabled:_.offline,onClick:e=>{v.current=e.currentTarget},children:[/* @__PURE__ */ G(a,{name:`magic-star`,size:14,"aria-hidden":`true`}),f??p.explainTrigger]});return _.offline?/* @__PURE__ */ G(d,{content:p.explainOffline,children:/* @__PURE__ */ G(`span`,{className:`wui-chat-explain-offline`,children:T})}):/* @__PURE__ */ G(l,{trigger:T,title:r,placement:c,open:m,onOpenChange:C,role:`dialog`,className:[`wui-chat-explain-pop`,u].filter(Boolean).join(` `),children:/* @__PURE__ */ G(Tr,{x:_,labels:p,renderAnswer:n,renderFoot:i,askDraft:o,chat:e,close:w,triggerRef:v})})}function Dr({chat:e,labels:t,enabled:n,onActivate:r}){let i=e.profile?z(e.profile,e.features):null,[o,s]=x(!1),[c,l]=x(!1),[u,d]=x(!1),f=(i?.delaySeconds??0)*1e3;return g(()=>{if(!n||!i||c){s(!1);return}if(u)return;let e=setTimeout(()=>{s(!0),d(!0)},f);return()=>clearTimeout(e)},[n,i,f,c,u]),!o||!i||c?null:/* @__PURE__ */ K(`div`,{className:`wui-chat-nudge`,role:`status`,children:[/* @__PURE__ */ G(`button`,{type:`button`,className:`wui-chat-nudge-text`,onClick:r,children:i.text}),/* @__PURE__ */ G(`button`,{type:`button`,className:`wui-chat-nudge-close`,"aria-label":t.nudgeDismiss,onClick:()=>l(!0),children:/* @__PURE__ */ G(a,{name:`x`,size:14,"aria-hidden":`true`})})]})}function Or(e,t,n,r){g(()=>{let i=e.current;if(!r||!i||!n)return;let a=U(t,n,i);return()=>a.destroy()},[e,t,n,r])}var kr=620,Ar=300,jr=`wchat:peeked`,Mr=576,Nr=200;function Pr(e){return e.replace(/([a-z0-9])([A-Z])/g,`$1-$2`).toLowerCase()}function Fr(e){return e?.querySelector(`:scope > .wui-chat-panel`)??null}function Ir(e){let[t,n]=x(()=>globalThis.innerWidth<=e);return g(()=>{let t=()=>n(globalThis.innerWidth<=e);return t(),globalThis.addEventListener(`resize`,t),()=>globalThis.removeEventListener(`resize`,t)},[e]),t}function Lr({chat:e,layout:t,labels:n,renderers:r,layoutParts:i,loader:o,motion:s=`On`,onOpenAttachment:c,onOpenTarget:l,onNavigate:u,resolveLink:d=null,linkComponent:f=null,className:p,style:h,theme:v,icon:S=`chat`,look:C,open:w,defaultOpen:T=!1,onOpenChange:E,position:D=`end`,offsetX:O=24,offsetY:k=24,panelId:A,switchConfig:j=null,renderEmpty:M}){let N=_(),P=A??N,F=y(()=>te(n),[n]),I=y(()=>ne(C),[C]),L=e.profile,ee=e.features,R=w!==void 0,z=R?w:e.open,re=yr(I,L?.experience??null),ie=s===`Reduced`||re?`Reduced`:`On`,B=L!==null&&ee.VisitorChat,V=t===`launcher`||t===`docked`,H=Ir(I.phone.maxWidthPx),U=L?.experience.launcher??null,ae=I.launcher.style===`Pill`?`pill`:`round`,oe=I.launcher.labelReveal===`Expand`?`expand`:`bubble`,se=I.launcher.idle===`None`?`none`:Pr(I.launcher.idle),pe=I.launcher.entrance===`None`?null:Pr(I.launcher.entrance),me=U?.hideWhileOpen===!0,he=U?.peek===!0,W=U?.peekSeconds??3,ge=e.messages.length>0,_e=b(null),q=b(null),ve=b(null),ye=b(null),be=b(!1),xe=b(z),Se=b(z),Ce=b(!1),we=b(E);we.current=E;let[Te,Ee]=x(z?`open`:`closed`),[De,J]=x(null),[Oe,ke]=x(null),Y=De??(pe&&!H?`entering`:`idle`);Or(_e,I.avoid,U,t===`launcher`&&B);let Ae=m(e=>{xe.current!==e&&(xe.current=e,we.current?.(e))},[]),X=m((t,n)=>{be.current=t,Ae(t),R||(t?e.session.open({trigger:`manual`}):e.session.close(n))},[R,e.session,Ae]);g(()=>{R&&(w&&!e.open&&e.session.open({trigger:`manual`}),!w&&e.open&&e.session.close(`button`))},[R,w,e.open,e.session]),g(()=>{!R&&T&&e.session.open({trigger:`manual`})},[R,T,e.session]),g(()=>{Ae(e.open)},[e.open,Ae]),g(()=>{if(z){Ee(e=>e===`open`?e:`opening`);let e=setTimeout(()=>Ee(`open`),kr);return()=>clearTimeout(e)}Ee(e=>e===`closed`?e:`closing`);let e=setTimeout(()=>Ee(`closed`),Ar);return()=>clearTimeout(e)},[z]),g(()=>{Se.current!==z&&(Se.current=z,ke(z?`wui-chat-launcher--opening`:`wui-chat-launcher--closing`))},[z]),g(()=>{if(Te!==`opening`)return;let e=Fr(q.current),t=ve.current;if(!e||!t)return;let n=t.getBoundingClientRect(),r=e.getBoundingClientRect();e.style.transformOrigin=`${n.left+n.width/2-r.left}px ${n.top+n.height/2-r.top}px`},[Te]),g(()=>{if(!me){J(e=>e===`hidden`?`idle`:e);return}if(z){J(`hidden`);return}let e=Fr(q.current)?.contains(document.activeElement)??!1,t=setTimeout(()=>{Ce.current=e,J(`idle`)},Nr);return()=>clearTimeout(t)},[z,me]),g(()=>{Y===`idle`&&Ce.current&&(Ce.current=!1,ue(ve.current))},[Y]);let je=b(!1);g(()=>{let e=je.current;je.current=z,z||!e||me||ue(ve.current)},[z,me]),g(()=>{z&&J(e=>e===`peeking`?`idle`:e)},[z]),g(()=>{B&&Y===`idle`&&he&&!re&&!z&&(globalThis.innerWidth<Mr||globalThis.sessionStorage.getItem(jr)!==null||(globalThis.sessionStorage.setItem(jr,`1`),J(`peeking`)))},[B,Y,he,re,z]),g(()=>{if(Y!==`peeking`)return;let e=setTimeout(()=>J(e=>e===`peeking`?`idle`:e),W*1e3);return()=>clearTimeout(e)},[Y,W]);let Me=b(X);Me.current=X,g(()=>{if(!z||!V)return;let e=e=>{e.key===`Escape`&&Me.current(!1,`escape`)};return document.addEventListener(`keydown`,e),()=>document.removeEventListener(`keydown`,e)},[z,V]),g(()=>{let e=Fr(q.current);if(!B||!V||!e)return;let t=t=>fe(e,t);return e.addEventListener(`keydown`,t),()=>e.removeEventListener(`keydown`,t)},[B,V]),g(()=>{if(!z||H||!be.current)return;let e=setTimeout(()=>ye.current?.focus(),400);return()=>clearTimeout(e)},[z,H]),g(()=>{let e=Fr(q.current);if(!B||!z||!H||!V||!e)return;let t=ce(e,I);return()=>t.destroy()},[B,z,H,V,I]),g(()=>{let e=q.current?.querySelector(`.wui-chat-thread`);if(B&&z&&H&&V&&ge&&e)return le(e)},[B,z,H,V,ge]),g(()=>{if(t!==`docked`||!z||typeof document>`u`)return;let e=document.documentElement,n=document.getElementById(P);e.dataset.wchatDocked=``;let r=null;if(n){let t=()=>e.style.setProperty(`--wchat-docked-width`,`${n.getBoundingClientRect().width}px`);t(),typeof ResizeObserver<`u`&&(r=new ResizeObserver(t),r.observe(n))}return()=>{r?.disconnect(),e.removeAttribute(`data-wchat-docked`),e.style.removeProperty(`--wchat-docked-width`)}},[t,z,P]);let Ne=j?.preload,Pe=b(!1);if(g(()=>{if(z&&!Pe.current){Pe.current=!0;try{Promise.resolve(Ne?.()).catch(()=>void 0)}catch{}}},[z,Ne]),!B)return null;let Z=j?()=>{let n={conversationId:e.conversationId,draft:ye.current?.value??``,from:t,to:j.target};de(()=>(X(!1,`button`),j.onSwitch(n)),{target:j.target}).catch(e=>globalThis.reportError?.(e))}:void 0,Fe=[`wui-chat`,`wui-chat--${t}`,`wui-chat--${D}`,Dt(ie),V&&H?`wui-chat--phone`:null,I.phone.mode===`Sheet`?`wui-chat--sheet`:null,p].filter(Boolean).join(` `),Ie={"--wui-chat-offset-x":`${O}px`,"--wui-chat-offset-y":`${k}px`,"--wui-chat-width":`${I.panel.widthPx}px`,"--wui-chat-panel-max-height":`${I.panel.maxHeightPx}px`,"--wui-chat-bottom-gap":`${I.panel.bottomGapPx}px`,"--wui-chat-sheet-height":`${I.phone.sheetHeightDvh}dvh`,"--wui-chat-sheet-max-height":`${I.phone.sheetMaxHeightPx}px`,...h},Le=[`wui-chat-launcher-wrap`,Y===`entering`&&pe?`wui-chat-launcher--entrance-${pe}`:null,Y===`idle`&&se!==`none`&&(se!==`ring`||ae===`pill`)?`wui-chat-launcher--idle-${se}`:null].filter(Boolean).join(` `),Re=[`wui-chat-launcher`,`wui-chat-launcher--${ae}`,ae===`pill`&&I.launcher.compact?`wui-chat-launcher--compact`:null,`wui-chat-launcher--reveal-${oe}`,Oe].filter(Boolean).join(` `),ze=t===`launcher`&&!z&&ee.Nudges;return/* @__PURE__ */ K(`div`,{ref:q,className:Fe,style:Ie,"data-state":Te,"data-open":z?`true`:`false`,"data-theme":v===`auto`?void 0:v,children:[/* @__PURE__ */ K(`div`,{ref:_e,className:Le,"data-launcher":Y,inert:Y===`hidden`,onAnimationEnd:e=>{e.target===e.currentTarget&&Y===`entering`&&J(`idle`)},children:[/* @__PURE__ */ G(Dr,{chat:e,labels:F,enabled:ze,onActivate:()=>X(!0,`manual`)}),/* @__PURE__ */ K(`button`,{ref:ve,type:`button`,className:Re,"aria-haspopup":`dialog`,"aria-expanded":z,"aria-controls":P,"aria-label":z?F.launcherClose:F.launcher,onClick:()=>X(!z,`launcher`),onAnimationEnd:e=>{e.target===e.currentTarget&&ke(null)},children:[/* @__PURE__ */ G(`span`,{className:`wui-chat-launcher-icon`,"aria-hidden":`true`,children:/* @__PURE__ */ G(a,{name:S,size:24,"aria-hidden":`true`})}),/* @__PURE__ */ G(`span`,{className:`wui-chat-launcher-close`,"aria-hidden":`true`,children:/* @__PURE__ */ G(a,{name:`x`,size:20,"aria-hidden":`true`})}),/* @__PURE__ */ G(`span`,{className:`wui-chat-launcher-label`,children:F.launcher})]}),/* @__PURE__ */ G(`span`,{className:`wui-chat-launcher-bubble`,"aria-hidden":`true`,children:U?.hoverLabel||F.launcher})]}),/* @__PURE__ */ G(_r,{chat:e,labels:F,layout:t,panelId:P,inputRef:ye,onClose:()=>X(!1,`button`),onSwitch:Z,open:z,renderEmpty:M,renderers:r,layoutParts:i,loader:o,motion:ie,onOpenAttachment:c,onOpenTarget:l,onNavigate:u,resolveLink:d,linkComponent:f})]})}function Rr({enabled:e,settings:t,look:n,session:r,isOpen:i,panelId:a}){let o=b(i);o.current=i,g(()=>{if(!e||!t)return;let i=me(t,n,{open:()=>r.open({trigger:`auto`}),isOpen:()=>o.current,panelRect:()=>document.getElementById(a)?.getBoundingClientRect()??null});return()=>i.cancel()},[e,t,n,r,a])}function zr(e){let{chat:t,look:n}=e,r=_(),i=y(()=>ne(n),[n]);return Rr({enabled:t.features.AutoOpen&&t.profile!==null,settings:t.profile?.experience.autoOpen??null,look:i,session:t.session,isOpen:t.open,panelId:r}),/* @__PURE__ */ G(Lr,{...e,layout:`launcher`,panelId:r})}function Br({onOpenFullScreen:e,preloadFullPage:t,...n}){let r=n.chat.features.PanelSwitch===!0&&typeof e==`function`?{onSwitch:e,target:`full-page`,preload:t}:null;return/* @__PURE__ */ G(Lr,{...n,layout:`docked`,switchConfig:r})}var Vr=`https://www.google.com/recaptcha/api.js?render=`,Hr=/* @__PURE__ */ new Map;function Ur(e){let t=Hr.get(e);if(t)return t;let n=new Promise((t,n)=>{if(globalThis.grecaptcha?.execute){t(globalThis.grecaptcha);return}let r=document.createElement(`script`);r.src=Vr+encodeURIComponent(e),r.async=!0,r.addEventListener(`load`,()=>t(globalThis.grecaptcha)),r.addEventListener(`error`,()=>{Hr.delete(e),n(/* @__PURE__ */ Error(`The reCAPTCHA script did not load.`))}),document.head.append(r)});return Hr.set(e,n),n}async function Wr(e,t){let n=await Ur(e);await new Promise(e=>n.ready(e));let r=await n.execute(e,{action:t});if(!r)throw Object.assign(/* @__PURE__ */ Error(`reCAPTCHA returned no token.`),{code:`captcha_unavailable`});return r}var Gr=e=>{if(typeof requestAnimationFrame==`function`){let t=requestAnimationFrame(()=>e());return()=>cancelAnimationFrame(t)}let t=setTimeout(e,16);return()=>clearTimeout(t)},Kr=ne(),qr=()=>()=>void 0,Jr=Object.freeze({profile:null,profileError:null,features:Object.freeze(j()),conversationId:null,conversationState:`Open`,title:null,continuesConversationId:null,messages:[],thinking:!1,steps:[],streaming:!1,loading:!1,loadError:null,turnError:null,stopped:!1,messagesLeftToday:null,editing:null,attachments:[],lastConversation:null,open:!1,muted:!1,greeting:null,starters:[],pending:null,agent:null,agentTyping:null,live:`Off`,handoffPending:!1,handoffPause:!1,openTickets:[],draft:null}),Yr=new Proxy({},{get:(e,t)=>{if(!(typeof t==`symbol`||t===`client`||t===`toJSON`||t.startsWith(`$$`))){if(t===`getState`)return()=>Jr;if(t===`subscribe`)return qr;if(t!==`then`)return()=>Promise.resolve()}}});function Xr(e){let{client:t,screen:n,layout:r,narrow:i,conversationId:a,behaviour:o,attribution:s,prefs:c,pageContext:l,getCaptchaToken:u,onEvent:d,onError:f,onNavigate:p}=e,h=b(l);h.current=l;let _=b(u);_.current=u;let v=b(d);v.current=d;let C=b(f);C.current=f;let w=b(a);w.current=a;let T=b(o);T.current=o;let D=b(s);D.current=s;let O=b(c);O.current=c;let k=JSON.stringify(i??{}),A=b(null),j=b(!1),M=b(null),[N,P]=x(null);g(()=>{M.current=null;let e=E(t,{screen:n,layout:r,narrow:JSON.parse(k),conversationId:w.current??null,pageContext:()=>h.current,behaviour:()=>{let e=A.current;return e?.getState().features.BehaviourStarters?T.current?T.current():(M.current||=ae(e.getState().profile?.start.behaviour?.servicePathPrefixes??[]),M.current()):null},attribution:()=>D.current?.()??null,prefs:O.current??xt,schedule:Gr,reducedMotion:()=>j.current,getCaptchaToken:async e=>{if(_.current)return _.current(e);let t=A.current?.getState().profile?.captcha;return t?.siteKey?Wr(t.siteKey,e):null},onEvent:(e,t)=>v.current?.(e,t),onError:e=>C.current?.(e)});return A.current=e,P({client:t,screen:n,layout:r,narrowKey:k,session:e}),()=>{A.current=null,e.dispose()}},[t,n,r,k]);let F=N!==null&&N.client===t&&N.screen===n&&N.layout===r&&N.narrowKey===k?N.session:Yr,I=S(F.subscribe,F.getState);j.current=yr(Kr,I.profile?.experience??null);let L=y(()=>({load:()=>F.load(),submit:e=>F.submit(e),chooseQuickReply:e=>F.chooseQuickReply(e),answerInput:(e,t)=>F.answerInput(e,t),confirmAction:e=>F.confirmAction(e),rejectAction:(e,t)=>F.rejectAction(e,t),stop:()=>F.stop(),retry:()=>F.retry(),regenerate:()=>F.regenerate(),notifyTyping:()=>F.notifyTyping(),requestHandoff:e=>F.requestHandoff(e),startEdit:e=>F.startEdit(e),cancelEdit:()=>F.cancelEdit(),attach:e=>F.attach(e),removeAttachment:e=>F.removeAttachment(e),openConversation:e=>F.openConversation(e),resumeLast:()=>F.resumeLast(),newConversation:()=>F.newConversation(),rate:(e,t,n)=>F.rate(e,t,n),reset:()=>F.reset()}),[F]),ee=m((e,t)=>v.current?.(e,t),[]);return{...I,...L,session:F,client:t,emit:ee,onNavigate:p}}export{Me as ChatComposer,Be as ChatConversationActions,Sr as ChatEmbed,Er as ChatExplain,Ve as ChatFooter,zr as ChatLauncher,Vt as ChatLoader,ut as ChatOpenTickets,br as ChatPage,Br as ChatPanel,ct as ChatPastChats,yt as ChatReadAloudButton,pr as ChatThread,or as defaultRenderers,nt as formatResetTime,Xr as useChat,J as useChatDictation,tt as useChatExplain,vr as useChatHandoff,ht as useChatReadAloud,ze as useTranscriptActions};
14
+ `;function Z(e,t,n){let r=e.createElement(t);return n!==void 0&&(r.textContent=n),r}function Ie(e,t){if(t.kind===`paragraph`)return Z(e,`p`,t.text);if(t.kind===`list`){let n=Z(e,t.ordered?`ol`:`ul`);for(let r of t.items)n.append(Z(e,`li`,r));return n}let n=Z(e,`table`);if(t.title!==null&&n.append(Z(e,`caption`,t.title)),t.head.length>0){let r=Z(e,`thead`),i=Z(e,`tr`);for(let n of t.head)i.append(Z(e,`th`,n));r.append(i),n.append(r)}let r=Z(e,`tbody`);for(let n of t.rows){let t=Z(e,`tr`);for(let r of n)t.append(Z(e,`td`,r));r.append(t)}return n.append(r),n}function Le(e,t){if(typeof e.CSSStyleSheet==`function`&&`adoptedStyleSheets`in t){let n=new e.CSSStyleSheet;n.replaceSync(Fe),t.adoptedStyleSheets=[n];return}let n=Z(t,`style`,Fe);t.head.append(n)}function Re(e,t={}){let n=t.lang||document.documentElement.lang||`en`,r=document.createElement(`iframe`);r.title=`Print`,r.setAttribute(`aria-hidden`,`true`),r.tabIndex=-1;let i=r.style;i.position=`fixed`,i.right=`0`,i.bottom=`0`,i.width=`0`,i.height=`0`,i.border=`0`,document.body.append(r);let a=r.contentWindow,o=r.contentDocument;if(!a||!o)return r.remove(),!1;o.open(),o.write(`<!doctype html><title></title>`),o.close(),o.title=e.title,o.documentElement.lang=n,Le(a,o),o.body.append(Z(o,`h1`,e.title));let s=t.printedOn??e.dateText;if(s!=null){let e=Z(o,`p`,s);e.className=`date`,o.body.append(e)}for(let t of e.entries){let e=Z(o,`section`);e.append(Z(o,`h2`,t.speaker));for(let n of t.blocks)e.append(Ie(o,n));o.body.append(e)}let c=()=>{r.isConnected&&r.remove(),clearTimeout(l)};a.addEventListener(`afterprint`,c);let l=setTimeout(c,Pe);return a.focus(),a.print(),!0}var ze=3e3;function Be(e,t){let[n,r]=x(null),i=b(null),a=b(!1);g(()=>(a.current=!0,()=>{a.current=!1,clearTimeout(i.current)}),[]);function o(e){a.current&&(clearTimeout(i.current),r(e),i.current=setTimeout(()=>r(null),ze))}let s={labels:t,title:e.title,figureText:e.features.FigureText},c=e.features.Share&&typeof navigator<`u`&&typeof navigator.share==`function`,l=e.features.Print&&typeof document<`u`;async function u(e,n){let r=T(e,s);if(r.entries.length===0)return;let i={title:r.title,text:oe(r,{heading:n,speakers:n})};if(typeof navigator.canShare==`function`&&!navigator.canShare(i))o(t.shareFailed);else try{await navigator.share(i)}catch(e){e?.name!==`AbortError`&&o(t.shareFailed)}}function d(e){let n=T(e,s);n.entries.length!==0&&(Re(n,{printedOn:t.printedOn(M((/* @__PURE__ */ new Date()).toISOString()))})||o(t.printFailed))}return{canShare:c,canPrint:l,notice:n,shareReply:e=>u([e],!1),printReply:e=>d([e]),shareConversation:()=>u(e.messages,!0),printConversation:()=>d(e.messages)}}function Ve({chat:e,labels:t}){let n=Be(e,t),r=e.streaming||e.thinking,i=e.messages.some(e=>e.stored&&(e.author.kind===`Assistant`||e.author.kind===`Agent`||e.author.kind===`Script`)&&re(e.parts)!==``);return r||e.loading||e.conversationId===null||!i||!n.canShare&&!n.canPrint?null:/* @__PURE__ */ K(W,{children:[n.canShare&&/* @__PURE__ */ G(`button`,{type:`button`,className:`wui-chat-icon-btn`,"aria-label":t.shareConversation,title:t.shareConversation,onClick:()=>n.shareConversation(),children:/* @__PURE__ */ G(a,{name:`share`,size:18,"aria-hidden":`true`})}),n.canPrint&&/* @__PURE__ */ G(`button`,{type:`button`,className:`wui-chat-icon-btn`,"aria-label":t.printConversation,title:t.printConversation,onClick:()=>n.printConversation(),children:/* @__PURE__ */ G(a,{name:`printer`,size:18,"aria-hidden":`true`})}),n.notice!==null&&/* @__PURE__ */ G(`span`,{className:`wui-chat-action-notice`,role:`status`,children:n.notice})]})}function He({chat:e,labels:t}){let n=e.profile;if(!n)return null;let r=n.footer.disclaimer||t.disclaimer,i=n.footer.privacyText,a=n.footer.privacyUrl,o=n.footer.assuranceText,s=z(n);return!r&&!i&&!a&&!o&&!s?null:/* @__PURE__ */ K(`p`,{className:`wui-chat-footer`,children:[r&&/* @__PURE__ */ G(`span`,{className:`wui-chat-footer-text`,children:r}),(i||a)&&/* @__PURE__ */ K(`span`,{className:`wui-chat-footer-privacy`,children:[i,i&&a&&` `,a&&/* @__PURE__ */ G(`a`,{className:`wui-chat-footer-link`,href:a,children:t.footerPrivacy})]}),o&&/* @__PURE__ */ G(`span`,{className:`wui-chat-footer-text`,children:o}),s&&/* @__PURE__ */ K(`span`,{className:`wui-chat-footer-captcha`,children:[t.captchaNote,` `,/* @__PURE__ */ G(`a`,{className:`wui-chat-footer-link`,href:`https://policies.google.com/privacy`,target:`_blank`,rel:`noopener noreferrer`,children:t.captchaPrivacy}),` `,/* @__PURE__ */ G(`a`,{className:`wui-chat-footer-link`,href:`https://policies.google.com/terms`,target:`_blank`,rel:`noopener noreferrer`,children:t.captchaTerms})]})]})}var Ue=Object.freeze({items:[],totalCount:null,loading:!1,error:null,hasMore:!1}),We=()=>()=>{};function Ge({chat:e,labels:n,onOpen:r}){let[i,o]=x(null),s=i!==null&&i.client===e.client?i.list:null,c=m(e=>s?s.subscribe(e):We(),[s]),l=m(()=>s?s.getState():Ue,[s]),u=S(c,l),[d,f]=x(null),[p,h]=x(``),[_,v]=x(!1),[y,C]=x(null),[w,T]=x(!1),E=b(null),O=b(!1),[k,A]=x(!1);g(()=>{let t=D({client:e.client});return o({client:e.client,list:t}),t.load(),()=>t.dispose()},[e.client]),g(()=>{d!==null&&E.current?.focus()},[d]);function j(e){f(e.publicId),h(e.title||``),v(!1)}async function N(e){if(!(O.current||p.trim()===``)){O.current=!0,A(!0);try{await s.rename(e,p),f(null)}catch{v(!0)}finally{O.current=!1,A(!1)}}}async function P(t){if(!O.current){O.current=!0,A(!0);try{await s.remove(t),C(null),T(!1),t===e.conversationId&&e.newConversation()}catch{T(!0)}finally{O.current=!1,A(!1)}}}let F=!u.loading&&u.error===null&&u.totalCount!==null&&u.items.length===0;return/* @__PURE__ */ K(`div`,{className:`wui-chat-history`,children:[u.error&&/* @__PURE__ */ K(`p`,{className:`wui-chat-history-error`,role:`alert`,children:[n.loadFailed,` `,/* @__PURE__ */ G(t,{className:`wui-chat-action-btn`,size:`sm`,variant:`ghost`,onClick:()=>s.load(),children:n.retry})]}),u.loading&&u.items.length===0&&/* @__PURE__ */ G(`p`,{className:`wui-chat-history-empty`,role:`status`,children:n.loadingConversation}),F&&/* @__PURE__ */ K(`p`,{className:`wui-chat-history-empty`,children:[/* @__PURE__ */ G(`span`,{children:n.historyEmptyTitle}),` `,/* @__PURE__ */ G(`span`,{children:n.historyEmptyText})]}),u.items.length>0&&/* @__PURE__ */ G(`ul`,{className:`wui-chat-history-list`,"aria-label":n.history,children:u.items.map(i=>d===i.publicId?/* @__PURE__ */ K(`li`,{className:`wui-chat-history-row wui-chat-history-row--editing`,children:[/* @__PURE__ */ G(`input`,{ref:E,className:`wui-chat-history-input`,"aria-label":n.conversationTitle,maxLength:120,value:p,onChange:e=>h(e.target.value),onKeyDown:e=>{e.key===`Enter`&&N(i.publicId),e.key===`Escape`&&(e.preventDefault(),e.stopPropagation(),f(null))}}),/* @__PURE__ */ G(t,{className:`wui-chat-action-btn`,size:`sm`,disabled:k||p.trim()===``,onClick:()=>N(i.publicId),children:n.renameSave}),/* @__PURE__ */ G(t,{className:`wui-chat-action-btn`,size:`sm`,variant:`ghost`,onClick:()=>f(null),children:n.cancel}),_&&/* @__PURE__ */ G(`p`,{className:`wui-chat-history-error`,role:`alert`,children:n.renameFailed})]},i.publicId):y===i.publicId?/* @__PURE__ */ K(`li`,{className:`wui-chat-history-row wui-chat-history-row--confirm`,children:[/* @__PURE__ */ G(`p`,{children:n.deleteConfirmTitle}),/* @__PURE__ */ G(`p`,{children:n.deleteConfirmMessage}),/* @__PURE__ */ G(t,{className:`wui-chat-action-btn`,size:`sm`,tone:`danger`,disabled:k,onClick:()=>P(i.publicId),children:n.deleteConfirm}),/* @__PURE__ */ G(t,{className:`wui-chat-action-btn`,size:`sm`,variant:`ghost`,onClick:()=>C(null),children:n.cancel}),w&&/* @__PURE__ */ G(`p`,{className:`wui-chat-history-error`,role:`alert`,children:n.deleteFailed})]},i.publicId):/* @__PURE__ */ K(`li`,{className:`wui-chat-history-row`,children:[/* @__PURE__ */ K(`button`,{type:`button`,className:`wui-chat-history-open`,onClick:()=>{e.openConversation(i.publicId),r()},children:[/* @__PURE__ */ G(`span`,{className:`wui-chat-history-title`,children:i.title||n.untitled}),/* @__PURE__ */ G(`span`,{className:`wui-chat-history-time`,children:M(i.lastActivityDateTimeUtc)})]}),e.features.Rename&&/* @__PURE__ */ G(`button`,{type:`button`,className:`wui-chat-icon-btn`,"aria-label":n.rename,title:n.rename,onClick:()=>j(i),children:/* @__PURE__ */ G(a,{name:`pencil`,size:18,"aria-hidden":`true`})}),e.features.Delete&&/* @__PURE__ */ G(`button`,{type:`button`,className:`wui-chat-icon-btn`,"aria-label":n.deleteChat,title:n.deleteChat,onClick:()=>{T(!1),C(i.publicId)},children:/* @__PURE__ */ G(a,{name:`trash`,size:18,"aria-hidden":`true`})})]},i.publicId))}),!u.loading&&u.hasMore&&/* @__PURE__ */ G(t,{className:`wui-chat-action-btn`,size:`sm`,variant:`soft`,onClick:()=>s.loadMore(),children:n.loadMore})]})}var Ke=/* @__PURE__ */ new Map([[`Open`,`info`],[`InProgress`,`info`],[`WaitingOnCustomer`,`warning`],[`Resolved`,`success`]]);function qe(e){let t=(e??``).trim().split(/\s+/).filter(Boolean);if(t.length===0)return`?`;let n=Array.from(t[0])[0];return t.length===1?n.toUpperCase():`${n}${Array.from(t.at(-1))[0]}`.toUpperCase()}function Je(e){return Ke.get(e)??`neutral`}function Ye(e){for(let t=e.length-1;t>=0;--t){let{author:n}=e[t];if(n.kind===`Agent`&&typeof n.displayName==`string`&&n.displayName.trim()!==``)return n.displayName}return null}function Xe(e,t){return e.conversationState===`WaitingForAgent`?t.statusWaitingForAgent:e.conversationState===`WithAgent`?t.statusWithAgent(Ye(e.messages)??t.handoffAgentFallback):null}function Ze(e){return e.features.HumanHandoff===!0&&e.conversationState===`Open`&&e.messages.some(e=>e.author.kind===`Visitor`||e.author.kind===`Customer`)&&!e.streaming&&!e.thinking}function Qe({chat:e,labels:n}){let[r,i]=x(!1),[a,o]=x(null),s=e.live===`Lost`,c=s?null:Xe(e,n),l=Ze(e);if(c===null&&!l&&!s)return null;async function u(){i(!0),o(null);try{await e.requestHandoff()}catch(e){o(e?.message||n.errorGeneric)}finally{i(!1)}}return/* @__PURE__ */ K(W,{children:[s&&/* @__PURE__ */ K(`p`,{className:`wui-chat-live-status`,role:`status`,children:[n.liveLost,` `,/* @__PURE__ */ G(t,{variant:`ghost`,size:`sm`,onClick:()=>e.session.resumeLive(),children:n.retry})]}),c!==null&&/* @__PURE__ */ G(`p`,{className:`wui-chat-live-status`,role:`status`,children:c}),l&&/* @__PURE__ */ K(`div`,{className:`wui-chat-live-actions`,children:[/* @__PURE__ */ G(t,{variant:`outline`,size:`sm`,leftIcon:`user`,className:`wui-chat-handoff-request`,disabled:r,onClick:u,children:n.talkToPerson}),a&&/* @__PURE__ */ G(`p`,{className:`wui-chat-live-error`,role:`alert`,children:a})]})]})}var $e=Object.freeze({state:`idle`,answer:null,pillVisible:!1,resetsDateTimeUtc:null,offline:!1}),et=()=>void 0,tt=()=>$e;function nt({request:e,enabled:t=!0}){let n=b(e);n.current=e;let[r,i]=x(null);g(()=>{let e=k({request:e=>n.current(e)});return i(e),()=>e.dispose()},[]);let a=m(e=>r?r.subscribe(e):et,[r]),o=S(a,r?r.getSnapshot:tt),s=m(()=>{t&&r?.ask()},[t,r]),c=m(()=>r?.reset(),[r]),l=t?o:$e;return{state:l.state,answer:l.answer,pillVisible:l.pillVisible,resetsDateTimeUtc:l.resetsDateTimeUtc,offline:l.offline,ask:s,reset:c}}function rt(e){if(typeof e!=`string`||e===``)return``;let t=new Date(e);return Number.isNaN(t.getTime())?``:new Intl.DateTimeFormat(void 0,{dateStyle:`medium`,timeStyle:`short`}).format(t)}var it=20,at=Object.freeze({items:[],totalCount:null,loading:!1,error:null,hasMore:!1}),ot=()=>void 0,st=()=>at;function ct(e,t){let n=Date.parse(e);if(Number.isNaN(n))return``;let r=(Date.now()-n)/1e3;if(r<60)return t.justNow;let i=new Intl.RelativeTimeFormat(void 0,{numeric:`auto`});return r<3600?i.format(-Math.floor(r/60),`minute`):r<86400?i.format(-Math.floor(r/3600),`hour`):r<604800?i.format(-Math.floor(r/86400),`day`):rt(e)}function lt({chat:e,labels:t,open:n}){let r=e.features.History===!0,i=e.client,[a,o]=x(null);g(()=>{if(!r)return;let e=D({client:i,pageSize:it});return o(e),()=>e.dispose()},[i,r]);let s=m(e=>a?a.subscribe(e):ot,[a]),c=S(s,a?a.getState:st);g(()=>{n&&a&&a.load()},[n,a]);let l=e.features.ResumeLast?e.lastConversation?.publicId:void 0,u=c.items.filter(e=>e.publicId!==l).slice(0,it);return!r||c.error||u.length===0?null:/* @__PURE__ */ G(`div`,{className:`wui-chat-empty-rows wui-chat-past`,role:`group`,"aria-label":t.history,children:u.map(n=>/* @__PURE__ */ K(`button`,{type:`button`,className:`wui-chat-empty-row`,onClick:()=>e.openConversation(n.publicId),children:[/* @__PURE__ */ G(`span`,{className:`wui-chat-empty-row-title`,children:n.title||t.earlierChat}),/* @__PURE__ */ G(`span`,{className:`wui-chat-empty-row-time`,title:rt(n.lastActivityDateTimeUtc)||void 0,children:ct(n.lastActivityDateTimeUtc,t)})]},n.publicId))})}var ut=3;function dt({chat:t,labels:n,onOpenTicket:r}){return!t.features.OpenTickets||t.openTickets.length===0?null:/* @__PURE__ */ G(`div`,{className:`wui-chat-open-tickets`,role:`group`,"aria-label":n.openTickets,children:t.openTickets.slice(0,ut).map(t=>{let i=/* @__PURE__ */ K(W,{children:[/* @__PURE__ */ G(`span`,{className:`wui-chat-empty-row-label`,children:n.ticketAria(t.number)}),/* @__PURE__ */ G(`span`,{className:`wui-chat-empty-row-title`,children:t.subject}),/* @__PURE__ */ G(e,{className:`wui-chat-empty-row-status`,tone:Je(t.status),children:n.ticketStatus(t.status)||t.status})]});return r?/* @__PURE__ */ G(`button`,{type:`button`,className:`wui-chat-empty-row`,onClick:()=>r({ticketId:t.ticketId,number:t.number}),children:i},t.ticketId):/* @__PURE__ */ G(`span`,{className:`wui-chat-empty-row`,children:i},t.ticketId)})})}var ft={Primary:`wui-chat-starter--primary`,Cta:`wui-chat-starter--cta`};function pt({chat:e,labels:t,onOpenTicket:n}){if(!e.profile)return null;let r=e.features.Starters&&!e.streaming&&e.starters.length>0,i=e.features.ResumeLast&&!e.features.History?e.lastConversation:null;return/* @__PURE__ */ K(`div`,{className:`wui-chat-empty`,role:`group`,"aria-label":t.emptyTitle,children:[/* @__PURE__ */ K(`div`,{className:`wui-chat-empty-hero`,children:[/* @__PURE__ */ G(`span`,{className:`wui-chat-orb`,"aria-hidden":`true`}),e.greeting?/* @__PURE__ */ G(`h2`,{className:`wui-chat-greeting`,children:e.greeting}):null]}),r&&/* @__PURE__ */ G(`div`,{className:`wui-chat-starters`,role:`group`,"aria-label":t.starters,children:e.starters.map((t,n)=>/* @__PURE__ */ K(`button`,{type:`button`,className:[`wui-chat-starter`,ft[t.variant]].filter(Boolean).join(` `),style:{"--wui-chat-i":n},onClick:()=>e.submit(t.message),children:[t.icon?/* @__PURE__ */ G(`span`,{className:`wui-chat-starter-icon`,"aria-hidden":`true`,children:/* @__PURE__ */ G(a,{name:t.icon,size:16})}):null,t.label]},t.id))}),i&&/* @__PURE__ */ G(`div`,{className:`wui-chat-empty-rows`,children:/* @__PURE__ */ K(`button`,{type:`button`,className:`wui-chat-empty-row`,onClick:()=>e.resumeLast(),children:[/* @__PURE__ */ G(`span`,{className:`wui-chat-empty-row-label`,children:t.resumeLast}),/* @__PURE__ */ G(`span`,{className:`wui-chat-empty-row-title`,children:i.title||t.untitled}),/* @__PURE__ */ G(`span`,{className:`wui-chat-empty-row-time`,children:M(i.lastActivityDateTimeUtc)})]})}),/* @__PURE__ */ G(dt,{chat:e,labels:t,onOpenTicket:n})]})}function mt({chat:e,labels:t}){let n=e.agentTyping;if(!n)return null;let r=typeof n==`object`&&n.displayName||Ye(e.messages)||t.agent;return/* @__PURE__ */ G(`li`,{className:`wui-chat-message wui-chat-message--agent wui-chat-message--typing`,children:/* @__PURE__ */ K(`div`,{className:`wui-chat-typing`,role:`status`,children:[/* @__PURE__ */ K(`span`,{className:`wui-chat-typing-dots`,"aria-hidden":`true`,children:[/* @__PURE__ */ G(`span`,{className:`wui-chat-typing-dot`}),/* @__PURE__ */ G(`span`,{className:`wui-chat-typing-dot`}),/* @__PURE__ */ G(`span`,{className:`wui-chat-typing-dot`})]}),/* @__PURE__ */ G(`span`,{className:`visually-hidden`,children:t.agentTyping(r)})]})})}function ht({author:e,labels:t}){if(e.kind!==`Agent`)return null;let n=typeof e.avatarUrl==`string`&&e.avatarUrl!==``?e.avatarUrl:null;return/* @__PURE__ */ K(`span`,{className:`wui-chat-author-badge`,children:[n?/* @__PURE__ */ G(`img`,{className:`wui-chat-author-avatar`,src:n,alt:``,"aria-hidden":`true`,width:24,height:24}):/* @__PURE__ */ G(`span`,{className:`wui-chat-author-avatar`,"aria-hidden":`true`,children:qe(e.displayName)}),/* @__PURE__ */ G(`span`,{className:`wui-chat-author-name`,children:e.displayName||t.agent}),/* @__PURE__ */ G(`span`,{className:`wui-chat-author-role`,children:t.agent})]})}var gt=null;function _t({speech:e,enabled:t}){let n=!!(t&&e?.readAloud),[r,i]=x(!1),[a,o]=x(!1),s=b(null),c=b(null),l=b(!1);return g(()=>(l.current=!0,()=>{l.current=!1,s.current?.abort(),s.current=null,gt===c.current&&(gt=null),c.current=null}),[]),{available:n,speaking:r,failed:a,toggle:m(t=>{if(s.current){s.current.abort();return}if(!e||t.trim()===``)return;gt?.();let n=new AbortController;s.current=n;let r=()=>n.abort();gt=r,c.current=r,i(!0),o(!1),e.speak(t,{signal:n.signal}).catch(()=>{!n.signal.aborted&&l.current&&o(!0)}).finally(()=>{s.current===n&&(s.current=null),gt===r&&(gt=null),l.current&&i(!1)})},[e])}}var vt=/* @__PURE__ */ new Set([`Assistant`,`Agent`,`Script`]),yt=6e3;function bt(e){let t=re(e).replace(/ ?\[\d+\]/g,``).replace(/\s+/g,` `).trim();if(t.length<=yt)return t;let n=t.slice(0,yt),r=n.lastIndexOf(`. `);return r===-1?n.trim():n.slice(0,r+1)}function xt({chat:e,labels:n,message:r}){let i=_t({speech:J(e),enabled:e.features.ReadAloud});if(!i.available||r.streaming||!vt.has(r.author.kind))return null;let a=r.parts.filter(e=>e.kind===`Text`),o=bt(e.features.FigureText?a.map(e=>({...e,text:ae(e.text)})):a);if(o.trim()===``)return null;let s=i.speaking?n.readAloudStop:n.readAloud;return/* @__PURE__ */ K(W,{children:[/* @__PURE__ */ G(t,{className:`wui-chat-action-btn`,size:`sm`,variant:`ghost`,leftIcon:`volume-high`,tone:i.speaking?`neutral`:void 0,"aria-pressed":i.speaking,"aria-label":s,title:s,onClick:()=>i.toggle(o)}),i.failed&&/* @__PURE__ */ G(`span`,{className:`wui-chat-action-notice`,role:`status`,children:n.readAloudFailed})]})}function St(e){return e===`wchat:muted`?globalThis.localStorage:globalThis.sessionStorage}var Ct={get(e){try{return St(e)?.getItem(e)??null}catch{return null}},set(e,t){try{St(e)?.setItem(e,t)}catch{}}};async function wt(e){try{if(navigator.clipboard?.writeText)return await navigator.clipboard.writeText(e),!0}catch{}let t=document.createElement(`textarea`);t.value=e,t.setAttribute(`readonly`,``),t.style.position=`fixed`,t.style.opacity=`0`,document.body.appendChild(t),t.select();try{return document.execCommand(`copy`)}catch{return!1}finally{t.remove()}}async function Tt(e,t){try{let n=await e.getAttachment(t.attachmentId),r=URL.createObjectURL(new Blob([n],{type:t.contentType}));return window.open(r,`_blank`,`noopener`),setTimeout(()=>URL.revokeObjectURL(r),6e4),!0}catch(e){return globalThis.reportError?.(e),!1}}function Et(e){/^https?:\/\//i.test(e)?window.open(e,`_blank`,`noopener`):window.location.assign(e)}function Dt(e){for(let t=e?.parentElement;t&&t!==document.body;t=t.parentElement){let{overflowY:e}=getComputedStyle(t);if((e===`auto`||e===`scroll`)&&t.scrollHeight>t.clientHeight)return t}return null}function Ot(e){let t=0;for(let n of e.parts)n.kind===`Text`&&(t+=n.text.length);return`${e.id}:${e.parts.length}:${t}`}function kt(e){return e===`Reduced`?`wui-chat--reduced`:``}var At={Up:`check`,Down:`x`};function jt({chat:e,message:n,labels:r,isLast:i,isLastVisitor:a}){let{features:o}=e,[s,c]=x(!1),[l,u]=x(!1),[d,f]=x(!1),p=Be(e,r),m=e.streaming||e.thinking;if(g(()=>{if(!s)return;let e=setTimeout(()=>c(!1),2e3);return()=>clearTimeout(e)},[s]),n.streaming)return null;let h=n.author.kind===`Assistant`||n.author.kind===`Agent`||n.author.kind===`Script`,_=h?re(n.parts):``,v=h&&_!==``&&o.Copy,y=h&&_!==``&&o.ReadAloud,b=h&&_!==``&&o.Share&&p.canShare,S=h&&_!==``&&o.Print&&p.canPrint,C=i&&n.author.kind===`Assistant`&&!e.streaming&&!e.thinking&&o.Regenerate&&e.messages.some(e=>e.author.kind===`Visitor`&&e.stored),w=a&&o.Edit&&!m,T=o.Rating&&n.stored&&(n.author.kind===`Assistant`||n.author.kind===`Agent`);if(!v&&!y&&!b&&!S&&!C&&!w&&!T)return null;async function E(t){u(!1);try{await e.rate(n.id,t),f(!0)}catch{u(!0)}}return/* @__PURE__ */ K(W,{children:[v&&/* @__PURE__ */ G(t,{className:`wui-chat-action-btn`,size:`sm`,variant:`ghost`,leftIcon:`copy`,onClick:async()=>{let e=await wt(_);c(e)},children:s?r.copied:r.copy}),y&&/* @__PURE__ */ G(xt,{chat:e,labels:r,message:n}),b&&/* @__PURE__ */ G(t,{className:`wui-chat-action-btn`,size:`sm`,variant:`ghost`,leftIcon:`share`,disabled:m,onClick:()=>p.shareReply(n),children:r.share}),S&&/* @__PURE__ */ G(t,{className:`wui-chat-action-btn`,size:`sm`,variant:`ghost`,leftIcon:`printer`,disabled:m,onClick:()=>p.printReply(n),children:r.print}),C&&/* @__PURE__ */ G(t,{className:`wui-chat-action-btn`,size:`sm`,variant:`ghost`,leftIcon:`refresh`,onClick:()=>e.regenerate(),children:r.regenerate}),w&&/* @__PURE__ */ G(t,{className:`wui-chat-action-btn`,size:`sm`,variant:`ghost`,leftIcon:`pencil`,onClick:()=>e.startEdit(n.id),children:r.edit}),T&&/* @__PURE__ */ K(`div`,{className:`wui-chat-rating`,role:`group`,"aria-label":`${r.rateUp} / ${r.rateDown}`,children:[[`Up`,`Down`].map(e=>/* @__PURE__ */ G(t,{className:`wui-chat-action-btn`,size:`sm`,variant:`ghost`,leftIcon:At[e],tone:n.rating===e?`neutral`:void 0,"aria-pressed":n.rating===e,"aria-label":e===`Up`?r.rateUp:r.rateDown,onClick:()=>E(e)},e)),l&&/* @__PURE__ */ G(`span`,{role:`status`,children:r.ratingFailed}),d&&!l&&/* @__PURE__ */ G(`span`,{role:`status`,children:r.rated})]}),p.notice!==null&&/* @__PURE__ */ G(`span`,{className:`wui-chat-action-notice`,role:`status`,children:p.notice})]})}function Mt({view:e}){return/* @__PURE__ */ K(`div`,{className:`wui-chat-loader-orb`,children:[/* @__PURE__ */ K(`span`,{className:`wui-chat-loader-orb-mark`,children:[/* @__PURE__ */ G(`span`,{className:`wui-chat-loader-orb-glow`,"aria-hidden":`true`}),/* @__PURE__ */ G(`span`,{className:`wui-chat-loader-orb-disc`,"aria-hidden":`true`})]}),/* @__PURE__ */ G(`span`,{className:`wui-chat-loader-orb-label`,children:e.label})]})}var Nt=150;function Pt({view:e,motion:t}){let n=t===`Reduced`,[r,i]=x(()=>({id:0,label:e.label,previous:null}));e.label!==r.label&&i({id:r.id+1,label:e.label,previous:{id:r.id,label:r.label}}),g(()=>{if(!r.previous)return;let e=setTimeout(()=>i(e=>({...e,previous:null})),Nt);return()=>clearTimeout(e)},[r.previous]);let a=n?null:r.previous;return/* @__PURE__ */ K(`div`,{className:`wui-chat-loader-phrases`,children:[/* @__PURE__ */ G(`span`,{className:`wui-chat-loader-phrases-orb`,"aria-hidden":`true`}),/* @__PURE__ */ K(`span`,{className:`wui-chat-loader-phrases-stage`,children:[a&&/* @__PURE__ */ G(`span`,{className:`wui-chat-loader-phrases-text wui-chat-loader-phrases-text--out`,children:a.label},`out-${a.id}`),/* @__PURE__ */ G(`span`,{className:`wui-chat-loader-phrases-text wui-chat-loader-phrases-text--in`,children:r.label},`in-${r.id}`)]})]})}var Ft=[`92%`,`78%`,`85%`,`40%`];function It({view:e}){return/* @__PURE__ */ K(`div`,{className:`wui-chat-loader-skeleton`,children:[/* @__PURE__ */ G(`div`,{className:`wui-chat-loader-skeleton-label`,children:e.label}),/* @__PURE__ */ K(`div`,{className:`wui-chat-loader-skeleton-body`,children:[Ft.map(e=>/* @__PURE__ */ G(`span`,{className:`wui-chat-loader-skeleton-line`,"aria-hidden":`true`,style:{width:e}},e)),/* @__PURE__ */ G(`span`,{className:`wui-chat-loader-skeleton-table`,"aria-hidden":`true`})]})]})}function Lt(e,t){return e<t?`done`:e===t?`active`:`pending`}function Rt(e){let t=/* @__PURE__ */ new Map;return e.map(e=>{let n=(t.get(e)??0)+1;return t.set(e,n),{key:`${e}\u0000${n}`,text:e}})}function zt({state:e}){return e===`done`?/* @__PURE__ */ G(`svg`,{viewBox:`0 0 16 16`,className:`wui-chat-loader-steps-check`,"aria-hidden":`true`,children:/* @__PURE__ */ G(`path`,{d:`M3 8.5 6.5 12 13 4.5`,pathLength:1})}):e===`active`?/* @__PURE__ */ G(`span`,{className:`wui-chat-loader-steps-ring`,"aria-hidden":`true`}):/* @__PURE__ */ G(`span`,{className:`wui-chat-loader-steps-dot`,"aria-hidden":`true`})}function Bt({view:e}){return/* @__PURE__ */ G(`div`,{className:`wui-chat-loader-steps`,children:/* @__PURE__ */ G(`ol`,{className:`wui-chat-loader-steps-list`,children:Rt(e.steps).map(({key:t,text:n},r)=>{let i=Lt(r,e.activeIndex);return/* @__PURE__ */ K(`li`,{className:`wui-chat-loader-steps-item`,"data-state":i,children:[/* @__PURE__ */ G(`span`,{className:`wui-chat-loader-steps-icon`,"aria-hidden":`true`,children:/* @__PURE__ */ G(zt,{state:i})}),/* @__PURE__ */ G(`span`,{className:`wui-chat-loader-steps-text`,children:n})]},t)})})})}var Vt=500;function Ht({style:e,view:t,motion:n}){return e===`Phrases`?/* @__PURE__ */ G(Pt,{view:t,motion:n}):G(e===`Orb`?Mt:e===`Skeleton`?It:Bt,{view:t})}function Ut({style:e=`Steps`,steps:t=[],phrases:n,intervalMs:r,announce:i,motion:a=`On`}){let o=a===`Reduced`,[s,c]=x({style:e,count:0}),[l,u]=x(!1);if(g(()=>{if(o)return;let t=setInterval(()=>c(t=>({style:e,count:t.count+1})),r);return()=>clearInterval(t)},[e,r,o]),g(()=>{let e=setTimeout(()=>u(!0),Vt);return()=>clearTimeout(e)},[]),!w.includes(e))throw Error(`ChatLoader style must be one of ${w.join(`, `)}, got "${e}".`);if(!(r>0))throw Error(`ChatLoader needs intervalMs, a positive number of milliseconds.`);s.style!==e&&c({style:e,count:0});let d=o?0:s.count,f=ee(e,t,n,d);return/* @__PURE__ */ K(`div`,{className:o?`wui-chat-loader wui-chat-loader--reduced`:`wui-chat-loader`,role:`status`,"aria-label":f.label,children:[/* @__PURE__ */ G(`div`,{className:`wui-chat-loader-body`,children:/* @__PURE__ */ G(Ht,{style:e,view:f,motion:a})}),/* @__PURE__ */ G(`span`,{className:`visually-hidden`,"aria-live":`polite`,children:l?i:``})]})}function Wt({motion:e,mark:t}){return/* @__PURE__ */ K(`div`,{className:e===`Reduced`?`wui-chat-loader-typing wui-chat-loader--reduced`:`wui-chat-loader-typing`,"aria-hidden":`true`,children:[t===`None`?null:/* @__PURE__ */ G(`span`,{className:`wui-chat-loader-typing-orb`,"aria-hidden":`true`}),/* @__PURE__ */ K(`span`,{className:`wui-chat-loader-typing-dots`,"aria-hidden":`true`,children:[/* @__PURE__ */ G(`span`,{className:`wui-chat-loader-typing-dot`,"aria-hidden":`true`}),/* @__PURE__ */ G(`span`,{className:`wui-chat-loader-typing-dot`,"aria-hidden":`true`}),/* @__PURE__ */ G(`span`,{className:`wui-chat-loader-typing-dot`,"aria-hidden":`true`})]})]})}var Gt=`ChatLeadCapture`,Kt=/^https?:\/\//i,qt={strong:`strong`,em:`em`,strike:`s`};function Jt(e,t={next:0}){return e.map(e=>{let n=t.next++;if(e.type===`text`||e.type===`citation`)return e.text;if(e.type===`link`){let r=Jt(e.children,t);return Kt.test(e.href)?/* @__PURE__ */ G(`a`,{href:e.href,target:`_blank`,rel:`noopener noreferrer`,children:r},n):/* @__PURE__ */ G(f,{children:r},n)}if(e.type in qt){let r=qt[e.type];return/* @__PURE__ */ G(r,{children:Jt(e.children,t)},n)}return e.type===`code`?/* @__PURE__ */ G(`code`,{children:e.text},n):null})}function Yt(e,t){return e.state===`Repeat`?e.decidedDateTimeUtc?t.actionRepeat(M(e.decidedDateTimeUtc)):t.actionDone:{Confirmed:t.actionConfirmed,Done:t.actionDone,Rejected:t.actionRejected,Expired:t.actionExpired,Failed:t.actionFailed}[e.state]}function Xt(e){let t=e.indexOf(`: `);return t<0?{term:e,detail:null}:{term:e.slice(0,t),detail:e.slice(t+2)}}function Zt(e,t){return{id:e,label:t,action:`Send`,target:null,navigateAfterMs:null,icon:null,variant:null}}function Qt({part:e,turn:t}){let{labels:n,features:r}=t,i=r.LeadRecap&&e.actionKind===Gt,a=e.state===`Pending`,o=e.editFields??[],s=i&&o.length>0,c=i&&e.confirmLabel||n.actionConfirm,l=i&&e.rejectLabel||n.actionDismiss,[u,d]=x(null),[f,p]=x(null),[m,h]=x(!1),v=_(),y=b(null),S=b(null),C=u!==null;g(()=>{m&&S.current?.querySelector(`[role="menuitem"]`)?.focus()},[m]);async function w(e,t){p(null),d(e);try{await t()}catch(e){p(e?.message||n.actionFailed),d(null)}}function T(e){h(!1),y.current?.focus(),t.chooseQuickReply(Zt(`lead.edit:${e.id}`,e.label))}function E(e){let t=[...e.currentTarget.querySelectorAll(`[role="menuitem"]`)],n=t.indexOf(e.target);e.key===`Escape`?(e.preventDefault(),h(!1),y.current?.focus()):e.key===`ArrowDown`?(e.preventDefault(),t[(n+1)%t.length]?.focus()):e.key===`ArrowUp`?(e.preventDefault(),t[n<=0?t.length-1:n-1]?.focus()):e.key===`Home`?(e.preventDefault(),t[0]?.focus()):e.key===`End`?(e.preventDefault(),t[t.length-1]?.focus()):e.key===`Tab`&&h(!1)}return/* @__PURE__ */ K(`div`,{className:`wui-chat-action wui-chat-action--${e.state.toLowerCase()}`,children:[/* @__PURE__ */ G(`strong`,{className:`wui-chat-action-title`,children:e.title}),e.lines.length>0&&(i?/* @__PURE__ */ G(`dl`,{className:`wui-chat-action-lines`,children:e.lines.map(e=>{let{term:t,detail:n}=Xt(e);return/* @__PURE__ */ K(`div`,{className:`wui-chat-action-line`,children:[/* @__PURE__ */ G(`dt`,{children:t}),n!==null&&/* @__PURE__ */ G(`dd`,{children:n})]},e)})}):/* @__PURE__ */ G(`ul`,{className:`wui-chat-action-lines`,children:e.lines.map(e=>/* @__PURE__ */ G(`li`,{children:e},e))})),i&&e.consentText&&/* @__PURE__ */ G(`p`,{className:`wui-chat-action-consent`,children:Jt(_e(e.consentText))}),e.note&&/* @__PURE__ */ G(`p`,{className:`wui-chat-action-note`,children:e.note}),!a&&/* @__PURE__ */ K(`p`,{className:`wui-chat-action-status wui-chat-action-status--${e.state.toLowerCase()}`,children:[Yt(e,n),e.state===`Done`&&e.decidedDateTimeUtc&&/* @__PURE__ */ K(W,{children:[` `,/* @__PURE__ */ G(`time`,{dateTime:e.decidedDateTimeUtc,children:M(e.decidedDateTimeUtc)})]})]}),(a||s)&&/* @__PURE__ */ K(`div`,{className:`wui-chat-action-buttons`,children:[a&&/* @__PURE__ */ K(W,{children:[/* @__PURE__ */ G(`button`,{className:`btn btn-primary btn-sm`,type:`button`,disabled:C,onClick:()=>w(`confirm`,()=>t.confirmAction(e.actionId)),children:u===`confirm`?n.actionWorking:c}),/* @__PURE__ */ G(`button`,{className:`btn btn-soft-primary btn-sm`,type:`button`,disabled:C,onClick:()=>w(`reject`,()=>t.rejectAction(e.actionId)),children:l})]}),s&&/* @__PURE__ */ G(`button`,{ref:y,className:`btn btn-soft-primary btn-sm wui-chat-action-edit`,type:`button`,"aria-haspopup":`menu`,"aria-expanded":m,"aria-controls":m?v:void 0,disabled:!a||C,onClick:()=>h(e=>!e),children:n.editSomething})]}),s&&m&&/* @__PURE__ */ G(`ul`,{id:v,ref:S,className:`list-group wui-chat-action-menu`,role:`menu`,"aria-label":n.editSomething,onKeyDown:E,children:o.map(e=>/* @__PURE__ */ G(`li`,{role:`none`,children:/* @__PURE__ */ G(`button`,{className:`list-group-item list-group-item-action wui-chat-action-menu-item`,type:`button`,role:`menuitem`,tabIndex:-1,onClick:()=>T(e),children:e.label})},e.id))}),f&&/* @__PURE__ */ G(`p`,{className:`wui-chat-action-error`,role:`alert`,children:f})]})}function Q({text:e,enabled:t}){if(!t||typeof e!=`string`)return e;let n=0;return/* @__PURE__ */ G(W,{children:ie(e).map(e=>{let t=`${n}-${e.kind}`;return n+=e.text.length,e.kind===`sub`?/* @__PURE__ */ G(`sub`,{children:e.text},t):e.kind===`sup`?/* @__PURE__ */ G(`sup`,{children:e.text},t):/* @__PURE__ */ G(f,{children:e.text},t)})})}function $t(e,t){return t&&typeof e==`string`?ae(e):e}var en={Bar:`column`,Line:`line`,Donut:`donut`},tn=8,nn=4;function rn({part:e,turn:r}){let[i,a]=x(`chart`),o=r.features.FigureText,s=e.chartType===`Donut`?e.series.slice(0,1):e.series.slice(0,tn),c=s.map(e=>new Map(e.points.map(e=>[e.label,e.value]))),l=[...new Set(s.flatMap(e=>e.points.map(e=>e.label)))].map(e=>{let t={label:$t(e,o)};return c.forEach((n,r)=>{t[`s${r}`]=n.get(e)??null}),t}),u=e.unit?$t(e.unit,o):null,d=s.map((e,t)=>{let n=$t(e.name,o);return{key:`s${t}`,label:n,format:{style:`number`}}}),f=e.chartType!==`Donut`&&u?{label:u}:void 0,p=Math.max(0,...s.map(e=>e.points.length)),m=e.chartType===`Bar`&&p>nn?300:240;return/* @__PURE__ */ K(`figure`,{className:`wui-chat-chart`,children:[e.title?/* @__PURE__ */ G(`figcaption`,{className:`wui-chat-rich-title`,children:/* @__PURE__ */ G(Q,{text:e.title,enabled:o})}):null,/* @__PURE__ */ G(n,{type:en[e.chartType],title:(e.title?$t(e.title,o):``)||r.labels.chart,data:l,x:{key:`label`},series:d,y:f,height:m,view:i,errorText:r.labels.chartLoadFailed}),l.length>0&&/* @__PURE__ */ G(t,{variant:`link`,size:`sm`,className:`wui-chat-chart-toggle`,"aria-pressed":i===`table`,onClick:()=>a(i===`table`?`chart`:`table`),children:i===`table`?r.labels.chartShowChart:r.labels.chartShowTable})]})}var an={Neutral:`neutral`,Positive:`success`,Caution:`warning`,Negative:`danger`},on=/* @__PURE__ */ new Set([`Positive`,`Caution`,`Negative`]),sn=3,cn=5,ln=.001;function un(e){let t=0;return e.map(e=>{let n=`${t}-${e.kind}`;return t+=e.text.length,e.kind===`sub`?/* @__PURE__ */ G(`sub`,{children:e.text},n):e.kind===`sup`?/* @__PURE__ */ G(`sup`,{children:e.text},n):/* @__PURE__ */ G(`span`,{children:e.text},n)})}function dn(e,t){let n=e.value!==0&&Math.abs(e.value)<ln?un(F(e.value)):q(e.value),r=on.has(e.status)?/* @__PURE__ */ G(`span`,{className:`visually-hidden`,children:t.figureStatus(e.status)}):null;return e.unit?/* @__PURE__ */ K(W,{children:[n,` `,/* @__PURE__ */ G(`span`,{className:`wui-chat-figure-unit`,children:un(ie(e.unit))}),r]}):/* @__PURE__ */ K(W,{children:[n,r]})}function fn({part:e,turn:t}){if(e.figures.length===0)return null;let n=Math.min(cn,Math.max(sn,e.figures.length)),r=e.figures.map(e=>({label:/* @__PURE__ */ G(Q,{text:e.label,enabled:!0}),value:dn(e,t.labels),tone:an[e.status]}));return/* @__PURE__ */ G(`div`,{className:`wui-chat-figures`,role:`group`,"aria-label":t.labels.figures,children:/* @__PURE__ */ G(c,{className:`wui-chat-figures-strip`,size:`sm`,columns:n,items:r})})}function pn({part:e,turn:t}){let n=/* @__PURE__ */ K(W,{children:[/* @__PURE__ */ G(`span`,{children:/* @__PURE__ */ G(a,{name:`document-text`,size:16})}),/* @__PURE__ */ G(`span`,{className:`wui-chat-file-name`,children:e.fileName}),/* @__PURE__ */ G(`span`,{className:`wui-chat-file-size`,children:I(e.length)})]});return/* @__PURE__ */ G(`div`,{className:`wui-chat-file`,children:t.openAttachment?/* @__PURE__ */ G(`button`,{className:`wui-chat-file-chip`,type:`button`,"aria-label":t.labels.fileOpen(e.fileName),onClick:()=>t.openAttachment(e),children:n}):/* @__PURE__ */ G(`span`,{className:`wui-chat-file-chip`,children:n})})}var mn=/* @__PURE__ */ new Set([`Requested`,`Waiting`,`Joined`,`Left`,`Ended`]),hn=/* @__PURE__ */ new Set([`Requested`,`Waiting`,`Joined`]);function gn({part:e,turn:t}){if(!mn.has(e.state)||t.handoffSettled===!0&&(e.state===`Requested`||e.state===`Waiting`))return null;let{labels:n}=t,r=e.agent?.displayName||null,i=e.agent?.avatarUrl||null,a=e.state.toLowerCase(),o=t.isLast&&(e.state===`Requested`||e.state===`Waiting`);return/* @__PURE__ */ K(`div`,{className:`wui-chat-handoff wui-chat-handoff--${a}${o?` wui-chat-handoff--live`:``}`,role:t.isLast&&hn.has(e.state)?`status`:void 0,children:[e.state===`Requested`&&/* @__PURE__ */ K(W,{children:[/* @__PURE__ */ K(`span`,{className:`wui-chat-handoff-pulses`,"aria-hidden":`true`,children:[/* @__PURE__ */ G(`span`,{className:`wui-chat-handoff-pulse`}),/* @__PURE__ */ G(`span`,{className:`wui-chat-handoff-pulse`}),/* @__PURE__ */ G(`span`,{className:`wui-chat-handoff-pulse`})]}),/* @__PURE__ */ G(`p`,{className:`wui-chat-handoff-text`,children:n.handoffRequested})]}),e.state===`Waiting`&&/* @__PURE__ */ K(W,{children:[typeof e.queuePosition!=`number`&&/* @__PURE__ */ K(W,{children:[/* @__PURE__ */ K(`span`,{className:`wui-chat-handoff-pulses`,"aria-hidden":`true`,children:[/* @__PURE__ */ G(`span`,{className:`wui-chat-handoff-pulse`}),/* @__PURE__ */ G(`span`,{className:`wui-chat-handoff-pulse`}),/* @__PURE__ */ G(`span`,{className:`wui-chat-handoff-pulse`})]}),/* @__PURE__ */ G(`p`,{className:`wui-chat-handoff-text`,children:n.handoffWaiting})]}),typeof e.queuePosition==`number`&&/* @__PURE__ */ G(`p`,{className:`wui-chat-handoff-queue`,children:n.handoffQueued(e.queuePosition)}),/* @__PURE__ */ G(`p`,{className:`wui-chat-handoff-note`,children:n.handoffQueuedText})]}),e.state===`Joined`&&/* @__PURE__ */ K(W,{children:[i?/* @__PURE__ */ G(`img`,{className:`wui-chat-handoff-avatar`,src:i,alt:``,"aria-hidden":`true`,width:32,height:32}):/* @__PURE__ */ G(`span`,{className:`wui-chat-handoff-avatar`,"aria-hidden":`true`,children:qe(r)}),/* @__PURE__ */ G(`span`,{className:`wui-chat-handoff-online`,"aria-hidden":`true`}),/* @__PURE__ */ G(`p`,{className:`wui-chat-handoff-text`,children:n.handoffJoined(r??n.handoffAgentFallback)}),/* @__PURE__ */ G(`p`,{className:`wui-chat-handoff-text`,children:n.handoffJoinedText(r??n.handoffAgentFallback)})]}),e.state===`Left`&&/* @__PURE__ */ K(W,{children:[/* @__PURE__ */ G(`p`,{className:`wui-chat-handoff-text`,children:n.handoffLeft(r??n.handoffAgentFallback)}),/* @__PURE__ */ G(`p`,{className:`wui-chat-handoff-text`,children:n.handoffLeftText})]}),e.state===`Ended`&&/* @__PURE__ */ K(W,{children:[/* @__PURE__ */ G(`p`,{className:`wui-chat-handoff-text`,children:n.handoffEnded}),/* @__PURE__ */ G(`p`,{className:`wui-chat-handoff-text`,children:n.handoffEndedText})]})]})}function _n({part:e,loadAttachmentUrl:n,turn:r}){let[i,a]=x({status:`loading`,url:null}),s=b(0),c=m(e=>{let t=++s.current;a({status:`loading`,url:null}),n(e).then(e=>{s.current===t&&a({status:`ready`,url:e})},()=>{s.current===t&&a({status:`failed`,url:null})})},[n]);return g(()=>(c(e.attachmentId),()=>{s.current++}),[c,e.attachmentId]),i.status===`loading`?/* @__PURE__ */ K(`div`,{className:`wui-chat-image-loading`,role:`status`,children:[/* @__PURE__ */ G(`span`,{className:`visually-hidden`,children:r.labels.imageLoading}),/* @__PURE__ */ G(u,{height:160,radius:8})]}):i.status===`failed`?/* @__PURE__ */ K(W,{children:[/* @__PURE__ */ G(`p`,{className:`wui-chat-image-error`,role:`status`,children:r.labels.imageFailed}),/* @__PURE__ */ G(t,{variant:`soft`,tone:`primary`,size:`sm`,onClick:()=>c(e.attachmentId),children:r.labels.retry})]}):/* @__PURE__ */ G(o,{className:`wui-chat-image-view`,label:r.labels.imageViewer,items:[{key:e.attachmentId,src:i.url,alt:e.alt,name:e.alt}],download:!1})}function vn({part:e,turn:t}){let n=e.width&&e.height?{aspectRatio:`${e.width} / ${e.height}`}:void 0;return typeof t.loadAttachmentUrl==`function`?/* @__PURE__ */ G(`figure`,{className:`wui-chat-image`,style:n,children:/* @__PURE__ */ G(_n,{part:e,loadAttachmentUrl:t.loadAttachmentUrl,turn:t},e.attachmentId)}):/* @__PURE__ */ G(`figure`,{className:`wui-chat-image`,style:n,children:/* @__PURE__ */ G(`span`,{className:`wui-chat-image-alt`,children:e.alt})})}var yn=/* @__PURE__ */ new Set([`ActionLimitReached`,`ConversationTooLong`]),bn={AssistantUnavailable:`danger`},xn={info:`info`,warning:`alert-triangle`,danger:`alert-circle`};function Sn({part:e}){let t=bn[e.code]??(yn.has(e.code)?`warning`:`info`);return/* @__PURE__ */ K(`div`,{className:`wui-chat-notice wui-chat-notice--${t}`,role:t===`danger`?`alert`:`status`,children:[/* @__PURE__ */ G(`span`,{className:`wui-chat-notice-icon`,"aria-hidden":`true`,children:/* @__PURE__ */ G(a,{name:xn[t],size:16})}),/* @__PURE__ */ G(`span`,{className:`wui-chat-notice-text`,children:e.text})]})}var Cn=[`Email`,`Phone`,`Name`,`Company`,`Text`,`LongText`,`Choice`,`MultiChoice`,`TimeSlot`,`File`,`Consent`],wn={Email:{type:`email`,autoComplete:`email`},Phone:{type:`tel`,autoComplete:`tel`},Name:{type:`text`,autoComplete:`name`},Company:{type:`text`,autoComplete:`organization`},Text:{type:`text`,autoComplete:void 0}},Tn=new Intl.DateTimeFormat(void 0,{weekday:`short`,day:`numeric`,month:`short`,hour:`numeric`,minute:`2-digit`});function En(e,t){return e.state===`Answered`?e.answeredSummary||t.inputAnswered:e.state===`Skipped`?t.inputSkipped:t.inputExpired}function Dn(e){return e.type===`Consent`?!1:e.type===`MultiChoice`?[]:``}function On(e){return Object.fromEntries(e.map(e=>[e.key,Dn(e)]))}function kn(e,t){return e.secret?t:t.trim()}function An(e,t,n){return e.required?e.type===`Consent`?t?null:n.inputConsentRequired:e.type===`MultiChoice`?t.length>0?null:n.inputRequired:kn(e,t)?null:n.inputRequired:null}function jn(e,t){return e.type===`Consent`?t?`true`:`false`:e.type===`MultiChoice`?JSON.stringify((e.options??[]).map(e=>e.id).filter(e=>t.includes(e))):e.type===`Choice`||e.type===`TimeSlot`?t:kn(e,t)}function Mn({field:e,value:t,error:n,file:r,disabled:i,id:a,labels:o,onChange:s,onFile:c,onRemove:l,controlRef:u}){let d=`${a}-error`,f=d,p=n?`true`:void 0,m=e.required||void 0,h=/* @__PURE__ */ G(`p`,{className:`wui-chat-field-error`,id:d,role:`alert`,hidden:!n,children:n}),g=e.required?null:/* @__PURE__ */ G(`span`,{className:`wui-chat-field-hint`,children:o.inputOptional});if(e.type===`Choice`){let n=`${a}-label`;return/* @__PURE__ */ K(`div`,{className:`wui-chat-field`,"data-key":e.key,children:[/* @__PURE__ */ G(`span`,{className:`form-label`,id:n,children:e.label}),g,/* @__PURE__ */ G(`div`,{role:`radiogroup`,"aria-labelledby":n,"aria-invalid":p,"aria-describedby":f,children:(e.options??[]).map((n,r)=>{let o=`${a}-${n.id}`;return/* @__PURE__ */ K(`div`,{className:`form-check`,children:[/* @__PURE__ */ G(`input`,{className:`form-check-input`,type:`radio`,id:o,name:e.key,value:n.id,checked:t===n.id,disabled:i,onChange:()=>s(n.id),ref:r===0?u:void 0}),/* @__PURE__ */ G(`label`,{className:`form-check-label`,htmlFor:o,children:n.label})]},n.id)})}),h]})}if(e.type===`MultiChoice`){let n=`${a}-label`;return/* @__PURE__ */ K(`div`,{className:`wui-chat-field`,"data-key":e.key,children:[/* @__PURE__ */ G(`span`,{className:`form-label`,id:n,children:e.label}),g,/* @__PURE__ */ G(`div`,{className:`wui-chat-input-choices`,role:`group`,"aria-labelledby":n,"aria-invalid":p,"aria-describedby":f,children:(e.options??[]).map((n,r)=>{let o=`${a}-${n.id}`;return/* @__PURE__ */ K(`div`,{className:`form-check`,children:[/* @__PURE__ */ G(`input`,{className:`form-check-input`,type:`checkbox`,id:o,name:e.key,value:n.id,checked:t.includes(n.id),disabled:i,onChange:e=>s(e.target.checked?[...t,n.id]:t.filter(e=>e!==n.id)),ref:r===0?u:void 0}),/* @__PURE__ */ G(`label`,{className:`form-check-label`,htmlFor:o,children:n.label})]},n.id)})}),h]})}if(e.type===`TimeSlot`){let n=`${a}-label`;return/* @__PURE__ */ K(`div`,{className:`wui-chat-field`,"data-key":e.key,children:[/* @__PURE__ */ G(`span`,{className:`form-label`,id:n,children:e.label}),g,/* @__PURE__ */ G(`div`,{className:`wui-chat-input-slots d-flex flex-wrap gap-2`,role:`radiogroup`,"aria-labelledby":n,"aria-invalid":p,"aria-describedby":f,children:(e.slots??[]).map((n,r)=>{let o=`${a}-${n.id}`;return/* @__PURE__ */ K(`div`,{className:`wui-chat-input-slot`,children:[/* @__PURE__ */ G(`input`,{className:`btn-check`,type:`radio`,id:o,name:e.key,value:n.id,checked:t===n.id,disabled:i,onChange:()=>s(n.id),ref:r===0?u:void 0}),/* @__PURE__ */ G(`label`,{className:`btn btn-soft-primary wui-chat-input-slot`,htmlFor:o,children:Tn.format(new Date(n.startDateTimeUtc))})]},n.id)})}),h]})}if(e.type===`File`){let t=r?.status===`uploading`;return/* @__PURE__ */ K(`div`,{className:`wui-chat-field`,"data-key":e.key,children:[/* @__PURE__ */ G(`label`,{className:`form-label`,htmlFor:a,children:e.label}),g,/* @__PURE__ */ G(`span`,{className:t?`wui-chat-input-file-status`:`visually-hidden`,"aria-live":`polite`,children:t?o.attachmentUploading:``}),r?/* @__PURE__ */ K(`div`,{className:`wui-chat-input-file`,children:[/* @__PURE__ */ G(`span`,{className:`wui-chat-input-file-name`,children:r.name}),/* @__PURE__ */ G(`button`,{className:`btn btn-link`,type:`button`,disabled:i,onClick:l,ref:u,children:o.inputRemoveFile(r.name)})]}):/* @__PURE__ */ G(`input`,{className:`form-control wui-chat-input-control`,type:`file`,id:a,name:e.key,accept:e.accept?.join(`,`),disabled:i,"aria-label":o.inputChooseFile,"aria-required":m,"aria-invalid":p,"aria-describedby":f,onChange:e=>{let t=e.target.files?.[0];t&&c(t)},ref:u}),h]})}if(e.type===`Consent`)return/* @__PURE__ */ K(`div`,{className:`wui-chat-field`,"data-key":e.key,children:[/* @__PURE__ */ K(`div`,{className:`form-check`,children:[/* @__PURE__ */ G(`input`,{className:`form-check-input`,type:`checkbox`,id:a,name:e.key,checked:t,disabled:i,"aria-invalid":p,"aria-describedby":f,onChange:e=>s(e.target.checked),ref:u}),/* @__PURE__ */ G(`label`,{className:`form-check-label`,htmlFor:a,children:e.consentText||e.label})]}),h]});let _=wn[e.type],v=e.type===`LongText`&&!e.secret?/* @__PURE__ */ G(`textarea`,{className:`form-control wui-chat-input-control`,id:a,name:e.key,rows:3,value:t,placeholder:e.placeholder??void 0,maxLength:e.maxLength??void 0,disabled:i,"aria-required":m,"aria-invalid":p,"aria-describedby":f,onChange:e=>s(e.target.value),ref:u}):/* @__PURE__ */ G(`input`,{className:`form-control wui-chat-input-control`,id:a,name:e.key,type:e.secret?`password`:_.type,autoComplete:e.secret?`off`:_.autoComplete,value:t,placeholder:e.placeholder??void 0,maxLength:e.maxLength??void 0,disabled:i,"aria-required":m,"aria-invalid":p,"aria-describedby":f,onChange:e=>s(e.target.value),ref:u});return/* @__PURE__ */ K(`div`,{className:`wui-chat-field`,"data-key":e.key,children:[/* @__PURE__ */ G(`label`,{className:`form-label`,htmlFor:a,children:e.label}),g,v,h]})}function Nn({part:e,turn:t}){let{labels:n,features:r}=t,i=_(),[a,o]=x(()=>On(e.fields)),[s,c]=x({}),[l,u]=x(null),[d,f]=x(!1),[p,m]=x(null),[h,v]=x({}),y=b({}),S=b({});g(()=>{p&&y.current[p.key]?.focus()},[p]);let C=e.fields.length===1?e.fields[0]:null,w=r.LeadShortcuts&&C!==null&&!C.required,T=r.LeadShortcuts&&e.cancellable,E=Object.values(h).some(e=>e.status===`uploading`);function D(t){return e.fields.find(e=>t[e.key])?.key??e.fields[0]?.key}function O(e,t){o(n=>({...n,[e]:t}))}async function k(e,r){let i={};S.current[e]=i,v(t=>({...t,[e]:{status:`uploading`,name:r.name}})),O(e,``),c(t=>({...t,[e]:void 0}));let a;try{a=await t.uploadInputFile(r)}catch{if(S.current[e]!==i)return;v(t=>({...t,[e]:{status:`failed`,name:r.name}})),c(t=>({...t,[e]:n.attachmentFailed}));return}S.current[e]===i&&(O(e,a),v(t=>({...t,[e]:{status:`ready`,name:r.name}})),c(t=>({...t,[e]:void 0})))}function A(e){S.current[e]=null,O(e,``),v(t=>Object.fromEntries(Object.entries(t).filter(([t])=>t!==e))),c(t=>({...t,[e]:void 0}))}async function j(r){if(r.preventDefault(),E){let e=Object.keys(h).find(e=>h[e]?.status===`uploading`);c(t=>({...t,[e]:n.attachmentUploading})),m({key:e});return}let i={};for(let t of e.fields){let e=t.type===`File`&&h[t.key]?.status===`failed`?n.attachmentFailed:An(t,a[t.key],n);e&&(i[t.key]=e)}if(u(null),c(i),Object.keys(i).length>0){m({key:D(i)});return}f(!0);let o=Object.fromEntries(e.fields.map(e=>[e.key,jn(e,a[e.key])])),s;try{s=await t.answerInput(e.requestId,o)}catch{s={ok:!1,errors:{},message:n.errorGeneric}}if(s.ok)return;let l=Object.entries(s.errors).filter(([t])=>!e.fields.some(e=>e.key===t)).map(([,e])=>e),d=[s.message,...l].filter(Boolean);c(s.errors),u(d.length>0?d.join(` `):null),f(!1),m({key:D(s.errors)})}return/* @__PURE__ */ K(`form`,{className:`wui-chat-input-form`,noValidate:!0,"aria-label":e.title||e.submitLabel,onSubmit:j,children:[e.title&&/* @__PURE__ */ G(`h3`,{className:`wui-chat-input-title`,children:e.title}),e.fields.map(e=>/* @__PURE__ */ G(Mn,{field:e,value:a[e.key],error:s[e.key],file:h[e.key],disabled:d,id:`${i}-${e.key}`,labels:n,onChange:t=>O(e.key,t),onFile:t=>k(e.key,t),onRemove:()=>A(e.key),controlRef:t=>{y.current[e.key]=t}},e.key)),/* @__PURE__ */ G(`p`,{className:`wui-chat-input-error`,role:`status`,hidden:!l,children:l}),/* @__PURE__ */ K(`div`,{className:`d-flex flex-wrap gap-2`,children:[/* @__PURE__ */ G(`button`,{className:`btn btn-primary`,type:`submit`,"data-wui":`AppButton`,disabled:d,children:d?n.inputSubmitting:e.submitLabel}),w&&/* @__PURE__ */ G(`button`,{className:`btn btn-soft-primary`,type:`button`,"data-wui":`AppButton`,disabled:d,onClick:()=>t.skipInput(e.requestId),children:n.skip}),T&&/* @__PURE__ */ G(`button`,{className:`btn btn-link`,type:`button`,disabled:d,onClick:()=>t.cancelLead(),children:n.cancel})]}),e.allowTyped&&/* @__PURE__ */ G(`p`,{className:`wui-chat-input-typed`,children:n.typeAnswer})]})}function Pn({part:e,message:t,turn:n}){if(e.fields.some(e=>!Cn.includes(e.type)))return/* @__PURE__ */ G(Sn,{part:{kind:`Notice`,code:`NeedsNewerApp`,text:n.labels.needsNewerApp},message:t,turn:n});let r=`wui-chat-input-request wui-chat-input-request--${e.state.toLowerCase()}`;return/* @__PURE__ */ G(`div`,{className:r,children:e.state===`Open`?/* @__PURE__ */ G(Nn,{part:e,turn:n},e.requestId):/* @__PURE__ */ G(`p`,{className:`wui-chat-input-summary`,children:En(e,n.labels)})})}var Fn=p({resolveLink:null,linkComponent:null});function In(){return h(Fn)}var Ln={Primary:`wui-chat-quick-reply--primary`,Cta:`wui-chat-quick-reply--cta`};function Rn(e,t){return e.action===`Navigate`?!!t.features.LinkHandoff:e.action!==`Open`||!!e.target&&!!t.openTarget}function zn(e,t){return[`wui-chat-quick-reply`,Ln[e.variant],t].filter(Boolean).join(` `)}function Bn(e,t,n){return L(e.target,t.handoffHosts)?n?n(e.target):e.target:null}function Vn(e){return e.icon?/* @__PURE__ */ G(`span`,{className:`wui-chat-quick-reply-icon`,"aria-hidden":`true`,children:/* @__PURE__ */ G(a,{name:e.icon,size:16})}):null}function Hn(e,t,n,r){return/* @__PURE__ */ K(`button`,{type:`button`,className:r,style:n,onClick:n=>{e.action===`Open`?t.openTarget(e.target):(t.chooseQuickReply(e),n.currentTarget.closest(`.wui-chat`)?.querySelector(`.wui-chat-input`)?.focus())},children:[Vn(e),/* @__PURE__ */ G(`span`,{className:`wui-chat-quick-reply-label`,children:e.label})]},e.id)}function Un({part:e,turn:t}){let{resolveLink:n}=In();if(!t.features.SuggestedReplies||!t.isLast||t.busy||e.replies.length===0)return null;let r=e.placement===`Composer`?`wui-chat-quick-replies wui-chat-quick-replies--composer`:`wui-chat-quick-replies`,i=e.replies.filter(e=>Rn(e,t));if(i.length===0)return null;let a=t.openTarget??(e=>globalThis.location.assign(e)),o=e.placement===`Composer`?void 0:i.find(e=>e.id===C&&e.action===`Send`);return/* @__PURE__ */ K(`div`,{className:o?`${r} wui-chat-quick-replies--offer`:r,role:`group`,"aria-label":t.labels.quickReplies,children:[o&&/* @__PURE__ */ K(`div`,{className:`wui-chat-offer`,children:[/* @__PURE__ */ G(`div`,{className:`wui-chat-offer-title`,children:o.label}),Hn(o,t,{"--wui-chat-i":0},zn({...o,variant:`Primary`},`wui-chat-offer-action`))]}),i.map((e,r)=>{if(e===o)return null;let i={"--wui-chat-i":r};if(e.action===`Navigate`){let r=Bn(e,t,n);return r===null?/* @__PURE__ */ G(`span`,{className:`wui-chat-quick-reply-label`,style:i,children:e.label},e.id):typeof t.beginHandoff==`function`?/* @__PURE__ */ K(`button`,{type:`button`,disabled:t.handoffPause,className:zn(e,t.handoffPause?`wui-chat-quick-reply--quiet`:void 0),style:i,onClick:()=>t.beginHandoff(e,()=>a(r)),children:[Vn(e),/* @__PURE__ */ G(`span`,{className:`wui-chat-quick-reply-label`,children:t.handoffPause?t.labels.handoffMoment:e.label})]},e.id):null}return Hn(e,t,i,zn(e,o?`wui-chat-quick-reply--quiet`:void 0))})]})}var Wn=/* @__PURE__ */ new Set([`Integer`,`Decimal`,`MoneyMinor`,`Percent`]);function Gn(e){return e.value===null||e.value===void 0||e.value===``?ve:e.type===`Date`?ye(e.value,{pattern:`day`}):e.type===`DateTimeUtc`?be(e.value):N(e.value,e.type,null)}function Kn({part:e,turn:n}){let r=_(),a=n.features.FigureText,o=e.fields.map(e=>({label:/* @__PURE__ */ G(Q,{text:e.label,enabled:a}),value:/* @__PURE__ */ G(`span`,{className:Wn.has(e.type)?`wui-chat-num`:void 0,children:/* @__PURE__ */ G(Q,{text:Gn(e),enabled:a})})})),s=!!e.target&&typeof n.openRecord==`function`;return/* @__PURE__ */ K(`article`,{className:`wui-chat-record`,"aria-labelledby":r,children:[/* @__PURE__ */ K(`header`,{className:`wui-chat-record-head`,children:[/* @__PURE__ */ G(`h3`,{className:`wui-chat-record-title`,id:r,children:/* @__PURE__ */ G(Q,{text:e.title,enabled:a})}),e.subtitle?/* @__PURE__ */ G(`p`,{className:`wui-chat-record-subtitle`,children:/* @__PURE__ */ G(Q,{text:e.subtitle,enabled:a})}):null]}),e.fields.length>0?/* @__PURE__ */ G(i,{className:`wui-chat-record-fields`,columns:1,size:`sm`,layout:`summary`,items:o}):null,s?/* @__PURE__ */ G(`div`,{className:`wui-chat-record-actions`,children:/* @__PURE__ */ G(t,{className:`wui-chat-record-open`,size:`sm`,type:`button`,"aria-label":n.labels.recordOpenFor(ae(e.title)),onClick:()=>n.openRecord(e),children:n.labels.recordOpen})}):null]})}var qn=/^https?:\/\//i;function Jn({source:e}){return/* @__PURE__ */ K(W,{children:[/* @__PURE__ */ G(`span`,{className:`wui-chat-source-marker`,children:e.marker}),/* @__PURE__ */ G(`span`,{className:`wui-chat-source-title`,children:e.title})]})}function Yn({part:e,turn:t}){return!t.features.Sources||e.sources.length===0?null:/* @__PURE__ */ K(`div`,{className:`wui-chat-sources`,children:[/* @__PURE__ */ G(`p`,{className:`wui-chat-sources-label`,children:t.labels.sources}),/* @__PURE__ */ G(`ul`,{className:`wui-chat-sources-list`,"aria-label":t.labels.sources,children:e.sources.map(e=>/* @__PURE__ */ G(`li`,{children:qn.test(e.url??``)?/* @__PURE__ */ G(`a`,{className:`wui-chat-source`,href:e.url,target:`_blank`,rel:`noopener noreferrer`,"aria-label":t.labels.openSource(e.title),"data-marker":e.marker,children:/* @__PURE__ */ G(Jn,{source:e})}):/* @__PURE__ */ G(`span`,{className:`wui-chat-source`,tabIndex:-1,"data-marker":e.marker,children:/* @__PURE__ */ G(Jn,{source:e})})},e.marker))})]})}var Xn=/* @__PURE__ */ new Set([`Integer`,`Decimal`,`MoneyMinor`,`Percent`]),Zn=50,Qn=25;function $n(e){return e.id}function er(e,t,n,r){return e==null?null:t.type===`Text`&&e!==``?/* @__PURE__ */ G(Q,{text:e,enabled:r}):N(e,t.type,n)}function tr({part:e,turn:n}){let[i,a]=x(!1),o=n.features.FigureText,s=e.columns.map((e,t)=>({key:`c${t}`,label:/* @__PURE__ */ G(Q,{text:e.label,enabled:o}),...Xn.has(e.type)?{align:`num`}:{}})),c=e.rows.map((t,n)=>{let r={id:n};return e.columns.forEach((n,i)=>{r[`c${i}`]=er(t[i],n,e.currency,o)}),r}),l=i?c:c.slice(0,Qn),u=l.length>Zn;return/* @__PURE__ */ K(`div`,{className:`wui-chat-table`,children:[e.title?/* @__PURE__ */ G(`p`,{className:`wui-chat-rich-title`,children:/* @__PURE__ */ G(Q,{text:e.title,enabled:o})}):null,/* @__PURE__ */ G(r,{density:`cozy`,ariaLabel:e.title?$t(e.title,o):n.labels.table,columns:s,rows:l,rowKey:$n,empty:n.labels.tableEmpty,maxHeight:u?360:void 0,virtual:u}),!i&&c.length>Qn&&/* @__PURE__ */ G(t,{variant:`soft`,tone:`primary`,size:`sm`,className:`wui-chat-table-more`,onClick:()=>a(!0),children:n.labels.tableShowAll(c.length)})]})}var nr=/* @__PURE__ */ new Set([`Visitor`,`Customer`]),rr=/^\d+$/;function ir({part:e,message:t,turn:n}){let{resolveLink:r,linkComponent:i}=In(),a=n.features.FigureText,o=n.features.Sources===!0;if(nr.has(t.author.kind))return/* @__PURE__ */ G(`div`,{className:t.restored?`wui-chat-bubble`:`wui-chat-bubble wui-chat-part-enter`,children:/* @__PURE__ */ G(Q,{text:e.text,enabled:a})});let c=n.handoffHosts,l=e=>L(e,c)?e:r?r(e):null,u=o&&n.openCitation?e=>n.openCitation(Number(e)):void 0,d=o?n.isCitation??(e=>rr.test(e)):()=>!1;return/* @__PURE__ */ G(s,{value:e.text,links:`app`,headings:`text`,className:t.restored?`wui-chat-text`:`wui-chat-text wui-chat-part-enter`,resolveLink:l,linkComponent:i||void 0,isCitation:d,onOpenCitation:u})}function ar({part:n,turn:r}){let{labels:i}=r,o=i.ticketStatus(n.status);return/* @__PURE__ */ K(`div`,{className:`wui-chat-ticket`,children:[/* @__PURE__ */ G(`span`,{className:`wui-chat-ticket-icon`,"aria-hidden":`true`,children:/* @__PURE__ */ G(a,{name:`tag`,size:20})}),/* @__PURE__ */ K(`div`,{className:`wui-chat-ticket-body`,children:[/* @__PURE__ */ K(`div`,{className:`wui-chat-ticket-head`,children:[/* @__PURE__ */ G(`strong`,{className:`wui-chat-ticket-number`,children:i.ticketAria(n.number)}),o&&/* @__PURE__ */ G(e,{className:`wui-chat-ticket-status`,tone:Je(n.status),children:o})]}),/* @__PURE__ */ G(`p`,{className:`wui-chat-ticket-subject`,children:n.subject})]}),r.openTicket&&/* @__PURE__ */ G(t,{variant:`outline`,size:`sm`,className:`wui-chat-ticket-open`,onClick:()=>r.openTicket(n),children:i.ticketView})]})}var or=40,$=null;function sr({part:e,turn:t}){let[n,r]=x(!1),[i,o]=x(!1),[s,c]=x(!1),[l,u]=x(!1),[d,f]=x(0),p=b(null),h=b(null),_=b(!1),v=y(()=>B(`${e.attachmentId}|${e.durationMs}`,or).map((e,t)=>({id:`bar-${t}`,position:t,height:e})),[e.attachmentId,e.durationMs]),S=m(()=>{p.current?.pause(),$===S&&($=null),o(!1)},[]);if(g(()=>(_.current=!0,()=>{_.current=!1,p.current?.pause(),h.current&&URL.revokeObjectURL(h.current),$===S&&($=null)}),[S]),!t.features.VoiceClips)return e.transcript?/* @__PURE__ */ G(`p`,{className:`wui-chat-clip-transcript`,children:e.transcript}):null;async function C(){if(i)S();else{r(!0),c(!1);try{if(!p.current){let n=await t.readAttachment(e.attachmentId);if(!_.current)return;h.current=URL.createObjectURL(new Blob([n]));let r=new Audio(h.current);r.addEventListener(`timeupdate`,()=>f(r.currentTime)),r.addEventListener(`ended`,()=>{o(!1),f(0),r.currentTime=0,$===S&&($=null)}),r.addEventListener(`error`,()=>{c(!0),o(!1)}),p.current=r}$?.(),await p.current.play(),$=S,o(!0)}catch{c(!0)}finally{_.current&&r(!1)}}}let w=e.durationMs/1e3,T=Math.floor((w>0?Math.min(1,d/w):0)*or);return/* @__PURE__ */ K(`div`,{className:`wui-chat-clip`,role:`group`,"aria-label":t.labels.voiceClip,children:[/* @__PURE__ */ K(`div`,{className:`wui-chat-clip-row`,children:[/* @__PURE__ */ G(`button`,{type:`button`,className:`wui-chat-clip-play`,"aria-label":i?t.labels.voiceClipPause:t.labels.voiceClipPlay,"aria-busy":n,disabled:n,onClick:C,children:/* @__PURE__ */ G(a,{name:i?`pause`:`play`,size:16,"aria-hidden":`true`})}),/* @__PURE__ */ G(`div`,{className:`wui-chat-clip-wave`,"aria-hidden":`true`,children:v.map(({id:e,position:t,height:n})=>/* @__PURE__ */ G(`span`,{className:t<T?`wui-chat-clip-bar wui-chat-clip-bar--played`:`wui-chat-clip-bar`,style:{"--wui-chat-bar-height":`${Math.round(n*100)}%`}},e))}),/* @__PURE__ */ G(`span`,{className:`wui-chat-clip-time`,children:t.labels.voiceClipTime(P(d),P(Math.max(1,Math.round(w))))})]}),s&&/* @__PURE__ */ G(`p`,{className:`wui-chat-clip-error`,role:`status`,children:t.labels.voiceClipFailed}),e.transcript?/* @__PURE__ */ K(W,{children:[/* @__PURE__ */ G(`button`,{type:`button`,className:`wui-chat-clip-toggle`,"aria-expanded":l,onClick:()=>u(!l),children:l?t.labels.voiceClipHideTranscript:t.labels.voiceClipShowTranscript}),l&&/* @__PURE__ */ G(`p`,{className:`wui-chat-clip-transcript`,children:e.transcript})]}):null]})}var cr={Text:ir,Sources:Yn,QuickReplies:Un,InputRequest:Pn,Action:Qt,Notice:Sn,Table:tr,Chart:rn,Figures:fn,RecordCard:Kn,Image:vn,File:pn,Ticket:ar,Handoff:gn,VoiceClip:sr},lr=48,ur={Visitor:`you`,Customer:`you`,Agent:`agent`,Assistant:`assistant`,Script:`assistant`,System:`assistant`},dr={kind:`Notice`,code:`NeedsNewerApp`};function fr(e,t){let n=e.author.kind;return e.author.displayName&&n!==`Visitor`&&n!==`Customer`?e.author.displayName:t[ur[n]??`assistant`]}function pr(e,t){for(let n=e.length-1;n>=0;--n)if(t(e[n]))return n;return-1}function mr(e,t){let n=/* @__PURE__ */ new Map,r=[];for(let i of e){let e=t(i),a=n.get(e)??0;n.set(e,a+1),r.push({key:`${e}#${a}`,item:i})}return r}function hr({chat:e,labels:n,renderers:r,layoutParts:i,loader:a,motion:o,onOpenAttachment:s,onOpenTarget:c,onOpenTicket:l,onNavigate:u}){let d=b(null),f=b(!0),p=b(/* @__PURE__ */ new Map),m={...cr,...r},h=u??e.onNavigate,_=e.pending?.authorKind,v=_===`Agent`||_===`Customer`?`None`:a===`Orb`?`Orb`:`Assistant`,y=e.messages.at(-1),x=e.messages.find(e=>!(e.streaming&&e.parts.length===0)),S=e.greeting&&x&&(x.author.kind===`Visitor`||x.author.kind===`Customer`)?{id:`greeting`,author:{kind:`Assistant`,displayName:null},parts:[{kind:`Text`,text:e.greeting}],stored:!1,streaming:!1,restored:!1}:null,C=S?[S,...e.messages]:e.messages,w=C.filter(e=>!(e.streaming&&e.parts.length===0)),T=!e.streaming&&(e.turnError!==null||e.stopped),E=e.turnError?.code===`daily_limit`,D=typeof e.turnError?.code==`string`&&e.turnError.code.endsWith(`feature_off`),O=e.pending?.typing===!0,k=`${y?Ot(y):``}|${e.thinking}|${O}|${T}`,j=pr(e.messages,e=>e.author.kind===`Visitor`&&e.stored),M=e.profile?.experience.pacing,N=e.profile?.assistant.name??``;g(()=>{if(!k)return;let e=Dt(d.current);e&&(e.scrollTop=e.scrollHeight,f.current=!0)},[k]),g(()=>{let e=d.current;if(!e||typeof ResizeObserver!=`function`)return;let t=null,n=()=>{f.current=t.scrollHeight-t.scrollTop-t.clientHeight<=lr},r=new ResizeObserver(()=>{let r=Dt(e);r!==t&&(t?.removeEventListener(`scroll`,n),t=r,t?.addEventListener(`scroll`,n,{passive:!0})),t&&f.current&&(t.scrollTop=t.scrollHeight)});return r.observe(e),()=>{t?.removeEventListener(`scroll`,n),r.disconnect()}},[]);function P(e,t){p.current.get(e)?.querySelector(`[data-marker="${t}"]`)?.focus()}function F(e,t,r,i){let a=Object.hasOwn(m,r.kind),o=a?r:{...dr,text:n.needsNewerApp},s=o.kind.toLowerCase(),c=a?m[r.kind]:m.Notice;return/* @__PURE__ */ G(`div`,{className:`wui-chat-part wui-chat-part--${s}`,children:/* @__PURE__ */ G(c,{part:o,message:e,turn:t})},i)}return/* @__PURE__ */ K(`ol`,{ref:d,className:`wui-chat-thread`,"aria-label":n.thread,"aria-live":`polite`,children:[C.map((t,r)=>{if(t.streaming&&t.parts.length===0)return null;let a=A(e.session,{messageId:t.id,labels:n,openAttachment:s??(t=>Tt(e.client,t)),openTarget:c??Et,...l?{openTicket:l}:{},openCitation:e=>P(t.id,e),onNavigate:h}),o=t===S,u=S?r-1:r,d=w[w.indexOf(t)-1],f=t.author.kind===`Agent`&&d?.author.kind===`Agent`&&(d.author.displayName??``)===(t.author.displayName??``),m=i?i(t):null;return/* @__PURE__ */ K(`li`,{ref:e=>{e?p.current.set(t.id,e):p.current.delete(t.id)},className:`wui-chat-message wui-chat-message--${t.author.kind.toLowerCase()}`,"aria-busy":t.streaming?`true`:void 0,"data-restored":t.restored?``:void 0,children:[/* @__PURE__ */ G(`span`,{className:`wui-chat-author visually-hidden`,children:`${fr(t,n)}: `}),f?null:/* @__PURE__ */ G(ht,{author:t.author,labels:n}),/* @__PURE__ */ G(`div`,{className:`wui-chat-message-body`,children:m?mr(m,e=>Array.isArray(e)?`group`:`part`).map(({key:e,item:n})=>/* @__PURE__ */ G(`div`,{className:`wui-chat-part-group`,children:mr(Array.isArray(n)?n:[n],e=>e.kind).map(({key:e,item:n})=>F(t,a,n,e))},e)):mr(t.parts,e=>e.kind).map(({key:e,item:n})=>F(t,a,n,e))}),o?null:/* @__PURE__ */ G(`div`,{className:`wui-chat-message-actions`,children:/* @__PURE__ */ G(jt,{chat:e,message:t,labels:n,isLast:t===y,isLastVisitor:!o&&u===j})})]},t.id)}),/* @__PURE__ */ G(mt,{chat:e,labels:n}),O&&/* @__PURE__ */ G(`li`,{className:`wui-chat-message wui-chat-message--assistant wui-chat-message--loading`,children:/* @__PURE__ */ G(`div`,{className:`wui-chat-loader-slot`,children:/* @__PURE__ */ G(Wt,{motion:o,mark:v})})}),e.thinking&&/* @__PURE__ */ G(`li`,{className:`wui-chat-message wui-chat-message--assistant wui-chat-message--loading`,children:/* @__PURE__ */ G(`div`,{className:`wui-chat-loader-slot`,children:/* @__PURE__ */ G(Ut,{style:a,steps:e.steps,phrases:M?.thinkingPhrases??[],intervalMs:M?.phraseIntervalMs??2500,announce:n.preparingAnswer(N),motion:o})})}),T&&/* @__PURE__ */ K(`li`,{className:`wui-chat-message wui-chat-message--system wui-chat-message--error`,children:[E?/* @__PURE__ */ K(`p`,{className:`wui-chat-error wui-chat-error--info`,role:`status`,children:[e.turnError.message,e.turnError.resetsDateTimeUtc?` ${n.dailyLimitRefresh(rt(e.turnError.resetsDateTimeUtc))}`:``]}):/* @__PURE__ */ G(`p`,{className:`wui-chat-error`,role:`alert`,children:e.turnError?.message??n.stopped}),e.features.Retry&&!E&&!D&&/* @__PURE__ */ G(`div`,{className:`wui-chat-message-actions`,children:/* @__PURE__ */ G(t,{className:`wui-chat-action-btn`,size:`sm`,variant:`ghost`,onClick:()=>e.retry(),children:n.retry})})]})]})}var gr=e=>e===`Assistant`||e===`Script`||e===`Agent`;function _r(e,t,n){if(t){e.wasLoading=!0;for(let t of n)e.seen.add(t.id);return[]}if(e.wasLoading||!e.seeded){e.wasLoading=!1,e.seeded=!0;for(let t of n)e.seen.add(t.id);return[]}let r=[];for(let t of n)e.seen.has(t.id)||(e.seen.add(t.id),r.push(t));return r}function vr(e){let t=e.features.Sounds?e.profile?.experience.sound??null:null,n=b(null),r=b(e);r.current=e;let i=b(e.open),a=b({seen:/* @__PURE__ */ new Set,seeded:!1,wasLoading:!1}),o=t!==null&&(t.open||t.sent||t.reply||t.vibrate);g(()=>{if(!o)return;let e=U(t,Ct);return n.current=e,e.setMuted(r.current.muted),()=>{e.destroy(),n.current=null}},[o,t]);let{open:s,loading:c,messages:l,muted:u}=e;g(()=>{n.current?.setMuted(u)},[u]),g(()=>{let e=n.current,o=i.current;i.current=s;let u=_r(a.current,c,l);if(e){s&&!o&&e.play(`open`);for(let n of u){if(n.restored||n.parts.some(e=>e.kind===`Notice`))continue;let i=n.author.kind;i===`Visitor`?n.stored||e.play(`sent`):gr(i)&&(e.play(`reply`),t.vibrate&&me(t.vibrateMs,r.current.muted))}}},[s,c,l,t])}function yr({chat:e,labels:t,layout:n,onClose:r,panelId:i,inputRef:o,ariaLabelOverride:s,renderers:c,layoutParts:l,loader:u,motion:d,onOpenAttachment:f,onOpenTarget:p,onOpenTicket:m,onNavigate:h,resolveLink:g=null,linkComponent:_=null,onSwitch:v,open:b=!0,renderEmpty:S,sendIcon:C=`arrow-up`}){let[w,T]=x(`chat`),E=y(()=>({resolveLink:g,linkComponent:_}),[g,_]);vr(e);let{features:D}=e,O=e.profile,k=w===`history`&&D.History===!0,A=e.messages.length>0,j=n===`launcher`||n===`docked`,M=O?.experience.sound,N=!!(D.Sounds&&M?.muteControl),P=j?`dialog`:`region`,F=s??O?.assistant.name??t.panelTitle,I=D.PanelSwitch===!0,L=n===`full-page`||n===`embedded`||A,ee=I&&typeof v==`function`&&(n===`docked`||n===`full-page`),te=n===`full-page`&&I&&typeof r==`function`;function ne(){T(`chat`),r?.()}function re(){if(e.profileError)return/* @__PURE__ */ G(`p`,{className:`wui-chat-profile-error`,role:`alert`,children:e.profileError.message});if(!O&&(n===`full-page`||n===`embedded`)||e.loading)return/* @__PURE__ */ G(`p`,{role:`status`,"aria-busy":`true`,children:t.loadingConversation});if(e.loadError)return/* @__PURE__ */ G(`p`,{className:`wui-chat-profile-error`,role:`alert`,children:e.loadError.message});if(!A){let n=/* @__PURE__ */ K(W,{children:[/* @__PURE__ */ G(pt,{chat:e,labels:t,onOpenTicket:m}),D.History&&/* @__PURE__ */ G(lt,{chat:e,labels:t,open:b})]});return S?S({chat:e,labels:t,open:b,defaultEmpty:n}):n}return/* @__PURE__ */ G(Fn.Provider,{value:E,children:/* @__PURE__ */ G(hr,{chat:e,labels:t,renderers:c,layoutParts:l,loader:u,motion:d,onOpenAttachment:f,onOpenTarget:p,onOpenTicket:m,onNavigate:h})})}return/* @__PURE__ */ K(`section`,{id:i,className:`wui-chat-panel`,role:P,"aria-label":F,children:[/* @__PURE__ */ K(`header`,{className:`wui-chat-header`,children:[/* @__PURE__ */ G(`span`,{className:`wui-chat-orb`,"aria-hidden":`true`}),/* @__PURE__ */ K(`div`,{className:`wui-chat-header-text`,children:[/* @__PURE__ */ G(`strong`,{className:`wui-chat-title`,children:O?.assistant.name??``}),/* @__PURE__ */ G(`span`,{className:`wui-chat-status`,children:Xe(e,t)??t.headerStatus})]}),/* @__PURE__ */ K(`div`,{className:`wui-chat-header-actions`,children:[!k&&/* @__PURE__ */ G(Ve,{chat:e,labels:t}),D.History&&(k?/* @__PURE__ */ G(`button`,{type:`button`,className:`wui-chat-icon-btn`,"aria-label":t.backToChat,title:t.backToChat,onClick:()=>T(`chat`),children:/* @__PURE__ */ G(a,{name:`arrow-left`,size:18,"aria-hidden":`true`})}):/* @__PURE__ */ G(`button`,{type:`button`,className:`wui-chat-icon-btn`,"aria-label":t.history,title:t.history,onClick:()=>T(`history`),children:/* @__PURE__ */ G(a,{name:`history`,size:18,"aria-hidden":`true`})})),N&&/* @__PURE__ */ G(`button`,{type:`button`,className:`wui-chat-icon-btn`,"aria-label":e.muted?t.unmuteSounds:t.muteSounds,title:e.muted?t.unmuteSounds:t.muteSounds,onClick:()=>e.session.setMuted(!e.muted),children:/* @__PURE__ */ G(a,{name:e.muted?`volume-mute`:`volume-high`,size:18,"aria-hidden":`true`})}),!k&&L&&/* @__PURE__ */ G(`button`,{type:`button`,className:`wui-chat-icon-btn`,"aria-label":t.newChat,title:t.newChat,disabled:e.streaming||e.thinking,onClick:()=>e.newConversation(),children:/* @__PURE__ */ G(a,{name:`plus`,size:18,"aria-hidden":`true`})}),ee&&/* @__PURE__ */ G(`button`,{type:`button`,className:`wui-chat-icon-btn wui-chat-icon-btn--switch`,"aria-label":n===`docked`?t.openFullScreen:t.openSidePanel,title:n===`docked`?t.openFullScreen:t.openSidePanel,disabled:e.streaming||e.thinking,onClick:()=>v(),children:/* @__PURE__ */ G(a,{name:n===`docked`?`maximize-4`:`panel-left-open`,size:18,"aria-hidden":`true`})}),(j||te)&&/* @__PURE__ */ G(`button`,{type:`button`,className:`wui-chat-icon-btn wui-chat-close-btn`,"aria-label":t.close,title:t.close,onClick:ne,children:/* @__PURE__ */ G(a,{name:`x`,size:18,"aria-hidden":`true`})})]})]}),/* @__PURE__ */ G(`div`,{className:`wui-chat-body`,children:k?/* @__PURE__ */ G(Ge,{chat:e,labels:t,onOpen:()=>T(`chat`)}):re()}),!k&&/* @__PURE__ */ K(`div`,{className:`wui-chat-foot`,children:[/* @__PURE__ */ G(Qe,{chat:e,labels:t}),/* @__PURE__ */ G(X,{chat:e,labels:t,maxLength:O?.limits.maxMessageLength??4e3,inputRef:o,sendIcon:C}),/* @__PURE__ */ G(He,{chat:e,labels:t})]})]})}function br(e,t){let n=b(!1);g(()=>{n.current||(n.current=!0,typeof t?.conversationId==`string`&&t.conversationId!==``&&e.openConversation(t.conversationId),typeof t?.draft==`string`&&t.draft!==``&&e.session.open({draft:t.draft}))},[e,t])}function xr(e,t){let[n,r]=x(!1);return g(()=>{let n=ge(e,t??null);r(n.reduced);let i=n.subscribe(()=>r(n.reduced));return()=>{i(),n.destroy()}},[e,t]),n}function Sr({chat:e,labels:t,renderers:n,layoutParts:r,loader:i,motion:a=`On`,onOpenAttachment:o,onOpenTarget:s,onNavigate:c,resolveLink:l,linkComponent:u,className:d,style:f,theme:p,look:m,onOpenSidePanel:h,onClose:g,renderEmpty:_,handoff:v}){let y=b(null);br(e,v??null);let x=e.features.PanelSwitch===!0&&typeof h==`function`?()=>{let t={conversationId:e.conversationId,draft:y.current?.value??``,from:`full-page`,to:`docked`};fe(()=>h(t),{target:`docked`}).catch(e=>globalThis.reportError?.(e))}:void 0;return/* @__PURE__ */ G(Cr,{layout:`full-page`,chat:e,labelOverrides:t,renderers:n,layoutParts:r,loader:i,motion:a,onOpenAttachment:o,onOpenTarget:s,onNavigate:c,resolveLink:l,linkComponent:u,className:d,style:f,theme:p,look:m,inputRef:y,onSwitch:x,onClose:g,renderEmpty:_})}function Cr({layout:e,chat:t,labelOverrides:n,renderers:r,layoutParts:i,loader:a,motion:o,onOpenAttachment:s,onOpenTarget:c,onNavigate:l,resolveLink:u=null,linkComponent:d=null,className:f,style:p,theme:m,look:h,inputRef:g,onSwitch:_,onClose:v,renderEmpty:b}){let x=y(()=>te(n),[n]),S=y(()=>ne(h),[h]),C=xr(S,t.profile?.experience??null),w=o===`Reduced`||C?`Reduced`:`On`;if(t.profile!==null&&!t.features.VisitorChat)return null;let T=[`wui-chat`,`wui-chat--${e}`,kt(w),S.input.sendReveal===`Always`?`wui-chat--send-always`:null,S.input.ring===!1?`wui-chat--input-ring-off`:null,S.panel.replyAvatars===!1?`wui-chat--reply-avatars-off`:null,f].filter(Boolean).join(` `),E=S.avatar?{"--wui-chat-avatar":`url(${JSON.stringify(S.avatar)})`,...p}:p;return/* @__PURE__ */ G(`div`,{className:T,style:E,"data-state":`open`,"data-theme":m===`auto`?void 0:m,children:/* @__PURE__ */ G(yr,{chat:t,labels:x,layout:e,sendIcon:S.input.sendIcon,panelId:void 0,renderers:r,layoutParts:i,loader:a,motion:w,onOpenAttachment:s,onOpenTarget:c,onNavigate:l,resolveLink:u,linkComponent:d,inputRef:g,onSwitch:_,onClose:v,renderEmpty:b})})}function wr(e){return/* @__PURE__ */ G(Cr,{...e,layout:`embedded`})}var Tr=`a[href], button:not([disabled]), input:not([disabled]), [tabindex]:not([tabindex="-1"])`;function Er(e){let t=b(null);return g(()=>{let n=document.activeElement;return t.current?.querySelector(Tr)?.focus({preventScroll:!0}),()=>(e.current??n)?.focus?.({preventScroll:!0})},[e]),g(()=>{let e=t.current;if(!e||typeof ResizeObserver>`u`)return;let n=0,r=new ResizeObserver(()=>{cancelAnimationFrame(n),n=requestAnimationFrame(()=>window.dispatchEvent(new Event(`scroll`)))});return r.observe(e),()=>{cancelAnimationFrame(n),r.disconnect()}},[]),t}function Dr({x:e,labels:n,renderAnswer:r,renderFoot:i,askDraft:a,chat:o,close:s,triggerRef:c}){let l=Er(c),{state:u,answer:d,pillVisible:f,resetsDateTimeUtc:p}=e,m=null;if((u===`thinking`||u===`slow`)&&f)m=/* @__PURE__ */ K(`div`,{className:`wui-chat-explain-pill`,role:`status`,children:[/* @__PURE__ */ G(`span`,{className:`wui-chat-explain-pill-dot`,"aria-hidden":`true`}),/* @__PURE__ */ G(`span`,{children:u===`slow`?n.explainSlow:n.thinking})]});else if(u===`answered`)m=/* @__PURE__ */ G(`div`,{className:`wui-chat-explain-answer`,children:r({answer:d,labels:n,close:s})});else if(u===`empty`)m=/* @__PURE__ */ G(`p`,{className:`wui-chat-explain-note`,children:n.explainEmpty});else if(u===`capacity`){let e=rt(p);m=/* @__PURE__ */ G(`p`,{className:`wui-chat-explain-notice wui-chat-explain-notice--info`,role:`status`,children:e?n.explainCapacity(e):n.explainCapacityNoDate})}else u===`error`&&(m=/* @__PURE__ */ K(`div`,{className:`wui-chat-explain-notice wui-chat-explain-notice--error`,role:`alert`,children:[/* @__PURE__ */ G(`p`,{children:n.explainError}),/* @__PURE__ */ G(t,{className:`wui-chat-action-btn`,size:`sm`,variant:`ghost`,onClick:()=>e.ask(),children:n.explainRetry})]}));let h=typeof a==`string`&&a!==``&&typeof o.session?.open==`function`;return/* @__PURE__ */ K(`div`,{ref:l,className:`wui-chat-explain`,children:[m,/* @__PURE__ */ K(`div`,{className:`wui-chat-explain-foot`,children:[i?.({close:s}),h&&/* @__PURE__ */ G(t,{className:`wui-chat-explain-more`,size:`sm`,variant:`ghost`,onClick:()=>{s(),o.session.open({draft:a})},children:n.explainAskMore}),/* @__PURE__ */ G(`p`,{className:`wui-chat-explain-note`,children:n.explainNotCounted})]})]})}function Or({chat:e,request:t,renderAnswer:n,label:r,renderFoot:i,askDraft:o,labels:s,placement:c=`auto`,className:u,triggerContent:f}){let p=y(()=>te(s),[s]),[m,h]=x(!1),_=nt({request:t,enabled:e.features.Explain===!0}),v=b(null),S=b(!1);if(g(()=>{if(!m)return;let e=e=>{S.current=!!e.target?.closest?.(`.wui-chat-panel`)};return document.addEventListener(`pointerdown`,e,!0),()=>document.removeEventListener(`pointerdown`,e,!0)},[m]),!e.features.Explain)return null;function C(e){!e&&(S.current||document.querySelector(`.wui-chat--docked[data-open=true]`))?S.current=!1:(h(e),e?_.ask():_.reset())}function w(){h(!1),_.reset()}let T=/* @__PURE__ */ K(`button`,{type:`button`,className:[`wui-chat-explain-trigger`,m?`wui-chat-explain-trigger--open`:null].filter(Boolean).join(` `),"aria-haspopup":`dialog`,"aria-label":p.explainTriggerLabel(r),disabled:_.offline,onClick:e=>{v.current=e.currentTarget},children:[/* @__PURE__ */ G(a,{name:`magic-star`,size:14,"aria-hidden":`true`}),f??p.explainTrigger]});return _.offline?/* @__PURE__ */ G(d,{content:p.explainOffline,children:/* @__PURE__ */ G(`span`,{className:`wui-chat-explain-offline`,children:T})}):/* @__PURE__ */ G(l,{trigger:T,title:r,placement:c,open:m,onOpenChange:C,role:`dialog`,className:[`wui-chat-explain-pop`,u].filter(Boolean).join(` `),children:/* @__PURE__ */ G(Dr,{x:_,labels:p,renderAnswer:n,renderFoot:i,askDraft:o,chat:e,close:w,triggerRef:v})})}function kr({chat:e,labels:t,enabled:n,onActivate:r}){let i=e.profile?R(e.profile,e.features):null,[o,s]=x(!1),[c,l]=x(!1),[u,d]=x(!1),f=(i?.delaySeconds??0)*1e3;return g(()=>{if(!n||!i||c){s(!1);return}if(u)return;let e=setTimeout(()=>{s(!0),d(!0)},f);return()=>clearTimeout(e)},[n,i,f,c,u]),!o||!i||c?null:/* @__PURE__ */ K(`div`,{className:`wui-chat-nudge`,role:`status`,children:[/* @__PURE__ */ G(`button`,{type:`button`,className:`wui-chat-nudge-text`,onClick:r,children:i.text}),/* @__PURE__ */ G(`button`,{type:`button`,className:`wui-chat-nudge-close`,"aria-label":t.nudgeDismiss,onClick:()=>l(!0),children:/* @__PURE__ */ G(a,{name:`x`,size:14,"aria-hidden":`true`})})]})}function Ar(e,t,n,r){g(()=>{let i=e.current;if(!r||!i||!n)return;let a=V(t,n,i);return()=>a.destroy()},[e,t,n,r])}var jr=620,Mr=300,Nr=`wchat:peeked`,Pr=576,Fr=200;function Ir(e){return e.replace(/([a-z0-9])([A-Z])/g,`$1-$2`).toLowerCase()}function Lr(e){return e?.querySelector(`:scope > .wui-chat-panel`)??null}function Rr(e){let[t,n]=x(()=>globalThis.innerWidth<=e);return g(()=>{let t=()=>n(globalThis.innerWidth<=e);return t(),globalThis.addEventListener(`resize`,t),()=>globalThis.removeEventListener(`resize`,t)},[e]),t}function zr({chat:e,layout:t,labels:n,renderers:r,layoutParts:i,loader:o,motion:s=`On`,onOpenAttachment:c,onOpenTarget:l,onNavigate:u,resolveLink:d=null,linkComponent:f=null,className:p,style:h,theme:S,icon:C=`chat`,look:w,open:T,defaultOpen:E=!1,onOpenChange:D,position:O=`end`,offsetX:k=24,offsetY:A=24,panelId:j,switchConfig:M=null,renderEmpty:N}){let P=_(),F=j??P,I=y(()=>te(n),[n]),L=y(()=>ne(w),[w]),ee=e.profile,re=e.features,R=T!==void 0,z=R?T:e.open,ie=xr(L,ee?.experience??null),ae=s===`Reduced`||ie?`Reduced`:`On`,oe=L.panel.motion===`None`?0:Mr,B=ee!==null&&re.VisitorChat,V=t===`launcher`||t===`docked`,H=Rr(L.phone.maxWidthPx),U=ee?.experience.launcher??null,se=L.launcher.style===`Pill`?`pill`:`round`,me=L.launcher.labelReveal===`Expand`?`expand`:`bubble`,he=L.launcher.idle===`None`?`none`:Ir(L.launcher.idle),ge=L.launcher.entrance===`None`?null:Ir(L.launcher.entrance),W=U?.hideWhileOpen===!0,_e=U?.peek===!0,ve=U?.peekSeconds??3,ye=e.messages.length>0,be=b(null),q=b(null),xe=b(null),Se=b(null),Ce=b(!1),we=b(z),Te=b(z),Ee=b(!1),De=b(D);De.current=D;let[Oe,ke]=x(z?`open`:`closed`),[Ae,J]=x(null),[je,Me]=x(null),Y=Ae??(ge&&!H?`entering`:`idle`);Ar(be,L.avoid,U,t===`launcher`&&B);let Ne=m(e=>{we.current!==e&&(we.current=e,De.current?.(e))},[]),X=m((t,n)=>{Ce.current=t,Ne(t),R||(t?e.session.open({trigger:`manual`}):e.session.close(n))},[R,e.session,Ne]);g(()=>{R&&(T&&!e.open&&e.session.open({trigger:`manual`}),!T&&e.open&&e.session.close(`button`))},[R,T,e.open,e.session]),g(()=>{!R&&E&&e.session.open({trigger:`manual`})},[R,E,e.session]),g(()=>{Ne(e.open)},[e.open,Ne]),g(()=>{if(z){ke(e=>e===`open`?e:`opening`);let e=setTimeout(()=>ke(`open`),jr);return()=>clearTimeout(e)}ke(e=>e===`closed`?e:`closing`);let e=setTimeout(()=>ke(`closed`),oe);return()=>clearTimeout(e)},[z,oe]),g(()=>{Te.current!==z&&(Te.current=z,Me(z?`wui-chat-launcher--opening`:`wui-chat-launcher--closing`))},[z]),v(()=>{if(Oe!==`opening`)return;let e=Lr(q.current),t=xe.current;e&&t&&le(e,t.getBoundingClientRect())},[Oe]),g(()=>{if(!W){J(e=>e===`hidden`?`idle`:e);return}if(z){J(`hidden`);return}if(Ae!==`hidden`)return;let e=Lr(q.current)?.contains(document.activeElement)??!1,t=setTimeout(()=>{Ee.current=e,J(`idle`)},Fr);return()=>clearTimeout(t)},[z,W,Ae]),g(()=>{Y===`idle`&&Ee.current&&(Ee.current=!1,de(xe.current))},[Y]);let Pe=b(!1);g(()=>{let e=Pe.current;Pe.current=z,z||!e||W||de(xe.current)},[z,W]),g(()=>{z&&J(e=>e===`peeking`?`idle`:e)},[z]),g(()=>{B&&Y===`idle`&&_e&&!ie&&!z&&(globalThis.innerWidth<Pr||globalThis.sessionStorage.getItem(Nr)!==null||(globalThis.sessionStorage.setItem(Nr,`1`),J(`peeking`)))},[B,Y,_e,ie,z]),g(()=>{if(Y!==`peeking`)return;let e=setTimeout(()=>J(e=>e===`peeking`?`idle`:e),ve*1e3);return()=>clearTimeout(e)},[Y,ve]);let Fe=b(X);Fe.current=X,g(()=>{if(!z||!V)return;let e=e=>{e.key===`Escape`&&Fe.current(!1,`escape`)};return document.addEventListener(`keydown`,e),()=>document.removeEventListener(`keydown`,e)},[z,V]),g(()=>{let e=Lr(q.current);if(!B||!V||!e)return;let t=t=>pe(e,t);return e.addEventListener(`keydown`,t),()=>e.removeEventListener(`keydown`,t)},[B,V]),g(()=>{if(!z||H||!Ce.current)return;let e=setTimeout(()=>Se.current?.focus(),400);return()=>clearTimeout(e)},[z,H]),g(()=>{let e=Lr(q.current);if(!B||!z||!H||!V||!e)return;let t=ce(e,L);return()=>t.destroy()},[B,z,H,V,L]),g(()=>{let e=q.current?.querySelector(`.wui-chat-thread`);if(B&&z&&H&&V&&ye&&e)return ue(e)},[B,z,H,V,ye]),g(()=>{if(t!==`docked`||!z||typeof document>`u`)return;let e=document.documentElement,n=document.getElementById(F);e.dataset.wchatDocked=``;let r=null;if(n){let t=()=>e.style.setProperty(`--wchat-docked-width`,`${n.getBoundingClientRect().width}px`);t(),typeof ResizeObserver<`u`&&(r=new ResizeObserver(t),r.observe(n))}return()=>{r?.disconnect(),e.removeAttribute(`data-wchat-docked`),e.style.removeProperty(`--wchat-docked-width`)}},[t,z,F]);let Z=M?.preload,Ie=b(!1);if(g(()=>{if(z&&!Ie.current){Ie.current=!0;try{Promise.resolve(Z?.()).catch(()=>void 0)}catch{}}},[z,Z]),!B)return null;let Le=M?()=>{let n={conversationId:e.conversationId,draft:Se.current?.value??``,from:t,to:M.target};fe(()=>(X(!1,`button`),M.onSwitch(n)),{target:M.target}).catch(e=>globalThis.reportError?.(e))}:void 0,Re=[`wui-chat`,`wui-chat--${t}`,`wui-chat--${O}`,kt(ae),V&&H?`wui-chat--phone`:null,L.phone.mode===`Sheet`?`wui-chat--sheet`:null,L.input.sendReveal===`Always`?`wui-chat--send-always`:null,L.input.ring===!1?`wui-chat--input-ring-off`:null,L.panel.motion===`Gentle`?`wui-chat--panel-motion-gentle`:null,L.panel.motion===`None`?`wui-chat--panel-motion-none`:null,L.panel.height===`Content`?`wui-chat--panel-height-content`:null,L.panel.replyAvatars===!1?`wui-chat--reply-avatars-off`:null,p].filter(Boolean).join(` `),ze={...L.avatar?{"--wui-chat-avatar":`url(${JSON.stringify(L.avatar)})`}:null,"--wui-chat-offset-x":`${k}px`,"--wui-chat-offset-y":`${A}px`,"--wui-chat-width":`${L.panel.widthPx}px`,"--wui-chat-panel-max-height":`${L.panel.maxHeightPx}px`,"--wui-chat-bottom-gap":`${L.panel.bottomGapPx}px`,"--wui-chat-sheet-height":`${L.phone.sheetHeightDvh}dvh`,"--wui-chat-sheet-max-height":`${L.phone.sheetMaxHeightPx}px`,...h},Be=[`wui-chat-launcher-wrap`,Y===`entering`&&ge?`wui-chat-launcher--entrance-${ge}`:null,Y===`idle`&&he!==`none`&&(he!==`ring`||se===`pill`)?`wui-chat-launcher--idle-${he}`:null].filter(Boolean).join(` `),Ve=[`wui-chat-launcher`,`wui-chat-launcher--${se}`,se===`pill`&&L.launcher.compact?`wui-chat-launcher--compact`:null,L.launcher.mark===`Avatar`?`wui-chat-launcher--mark-avatar`:null,`wui-chat-launcher--reveal-${me}`,je].filter(Boolean).join(` `),He=t===`launcher`&&!z&&re.Nudges,Ue=z?I.launcherClose:U?.hoverLabel||I.launcher;return/* @__PURE__ */ K(`div`,{ref:q,className:Re,style:ze,"data-state":Oe,"data-open":z?`true`:`false`,"data-theme":S===`auto`?void 0:S,children:[/* @__PURE__ */ K(`div`,{ref:be,className:Be,"data-launcher":Y,inert:Y===`hidden`,onAnimationEnd:e=>{e.target===e.currentTarget&&Y===`entering`&&J(`idle`)},children:[/* @__PURE__ */ G(kr,{chat:e,labels:I,enabled:He,onActivate:()=>X(!0,`manual`)}),/* @__PURE__ */ K(`button`,{ref:xe,type:`button`,className:Ve,"aria-haspopup":`dialog`,"aria-expanded":z,"aria-controls":F,"aria-label":Ue,onClick:()=>X(!z,`launcher`),onAnimationEnd:e=>{e.target===e.currentTarget&&Me(null)},children:[/* @__PURE__ */ G(`span`,{className:`wui-chat-launcher-icon`,"aria-hidden":`true`,children:/* @__PURE__ */ G(a,{name:C,size:24,"aria-hidden":`true`})}),/* @__PURE__ */ G(`span`,{className:`wui-chat-launcher-close`,"aria-hidden":`true`,children:/* @__PURE__ */ G(a,{name:`x`,size:20,"aria-hidden":`true`})}),/* @__PURE__ */ G(`span`,{className:`wui-chat-launcher-label`,children:Ue})]}),/* @__PURE__ */ G(`span`,{className:`wui-chat-launcher-bubble`,"aria-hidden":`true`,children:U?.hoverLabel||I.launcher})]}),/* @__PURE__ */ G(yr,{chat:e,labels:I,layout:t,sendIcon:L.input.sendIcon,panelId:F,inputRef:Se,onClose:()=>X(!1,`button`),onSwitch:Le,open:z,renderEmpty:N,renderers:r,layoutParts:i,loader:o,motion:ae,onOpenAttachment:c,onOpenTarget:l,onNavigate:u,resolveLink:d,linkComponent:f})]})}function Br({enabled:e,settings:t,look:n,session:r,isOpen:i,panelId:a}){let o=b(i);o.current=i,g(()=>{if(!e||!t)return;let i=he(t,n,{open:()=>r.open({trigger:`auto`}),isOpen:()=>o.current,panelRect:()=>document.getElementById(a)?.getBoundingClientRect()??null});return()=>i.cancel()},[e,t,n,r,a])}function Vr(e){let{chat:t,look:n}=e,r=_(),i=y(()=>ne(n),[n]);return Br({enabled:t.features.AutoOpen&&t.profile!==null,settings:t.profile?.experience.autoOpen??null,look:i,session:t.session,isOpen:t.open,panelId:r}),/* @__PURE__ */ G(zr,{...e,layout:`launcher`,panelId:r})}function Hr({onOpenFullScreen:e,preloadFullPage:t,...n}){let r=n.chat.features.PanelSwitch===!0&&typeof e==`function`?{onSwitch:e,target:`full-page`,preload:t}:null;return/* @__PURE__ */ G(zr,{...n,layout:`docked`,switchConfig:r})}var Ur=`https://www.google.com/recaptcha/api.js?render=`,Wr=/* @__PURE__ */ new Map;function Gr(e){let t=Wr.get(e);if(t)return t;let n=new Promise((t,n)=>{if(globalThis.grecaptcha?.execute){t(globalThis.grecaptcha);return}let r=document.createElement(`script`);r.src=Ur+encodeURIComponent(e),r.async=!0,r.addEventListener(`load`,()=>t(globalThis.grecaptcha)),r.addEventListener(`error`,()=>{Wr.delete(e),n(/* @__PURE__ */ Error(`The reCAPTCHA script did not load.`))}),document.head.append(r)});return Wr.set(e,n),n}async function Kr(e,t){let n=await Gr(e);await new Promise(e=>n.ready(e));let r=await n.execute(e,{action:t});if(!r)throw Object.assign(/* @__PURE__ */ Error(`reCAPTCHA returned no token.`),{code:`captcha_unavailable`});return r}var qr=e=>{if(typeof requestAnimationFrame==`function`){let t=requestAnimationFrame(()=>e());return()=>cancelAnimationFrame(t)}let t=setTimeout(e,16);return()=>clearTimeout(t)},Jr=ne(),Yr=()=>()=>void 0,Xr=Object.freeze({profile:null,profileError:null,features:Object.freeze(j()),conversationId:null,conversationState:`Open`,title:null,continuesConversationId:null,messages:[],thinking:!1,steps:[],streaming:!1,loading:!1,loadError:null,turnError:null,stopped:!1,messagesLeftToday:null,editing:null,attachments:[],lastConversation:null,open:!1,muted:!1,greeting:null,starters:[],pending:null,agent:null,agentTyping:null,live:`Off`,handoffPending:!1,handoffPause:!1,openTickets:[],draft:null}),Zr=new Proxy({},{get:(e,t)=>{if(!(typeof t==`symbol`||t===`client`||t===`toJSON`||t.startsWith(`$$`))){if(t===`getState`)return()=>Xr;if(t===`subscribe`)return Yr;if(t!==`then`)return()=>Promise.resolve()}}});function Qr(e){let{client:t,screen:n,layout:r,narrow:i,conversationId:a,behaviour:o,attribution:s,prefs:c,pageContext:l,getCaptchaToken:u,onEvent:d,onError:f,onNavigate:p}=e,h=b(l);h.current=l;let _=b(u);_.current=u;let v=b(d);v.current=d;let C=b(f);C.current=f;let w=b(a);w.current=a;let T=b(o);T.current=o;let D=b(s);D.current=s;let O=b(c);O.current=c;let k=JSON.stringify(i??{}),A=b(null),j=b(!1),M=b(null),[N,P]=x(null);g(()=>{M.current=null;let e=E(t,{screen:n,layout:r,narrow:JSON.parse(k),conversationId:w.current??null,pageContext:()=>h.current,behaviour:()=>{let e=A.current;return e?.getState().features.BehaviourStarters?T.current?T.current():(M.current||=H(e.getState().profile?.start.behaviour?.servicePathPrefixes??[]),M.current()):null},attribution:()=>D.current?.()??null,prefs:O.current??Ct,schedule:qr,reducedMotion:()=>j.current,getCaptchaToken:async e=>{if(_.current)return _.current(e);let t=A.current?.getState().profile?.captcha;return t?.siteKey?Kr(t.siteKey,e):null},onEvent:(e,t)=>v.current?.(e,t),onError:e=>C.current?.(e)});return A.current=e,P({client:t,screen:n,layout:r,narrowKey:k,session:e}),()=>{A.current=null,e.dispose()}},[t,n,r,k]);let F=N!==null&&N.client===t&&N.screen===n&&N.layout===r&&N.narrowKey===k?N.session:Zr,I=S(F.subscribe,F.getState);j.current=xr(Jr,I.profile?.experience??null);let L=y(()=>({load:()=>F.load(),submit:e=>F.submit(e),chooseQuickReply:e=>F.chooseQuickReply(e),answerInput:(e,t)=>F.answerInput(e,t),confirmAction:e=>F.confirmAction(e),rejectAction:(e,t)=>F.rejectAction(e,t),stop:()=>F.stop(),retry:()=>F.retry(),regenerate:()=>F.regenerate(),notifyTyping:()=>F.notifyTyping(),requestHandoff:e=>F.requestHandoff(e),startEdit:e=>F.startEdit(e),cancelEdit:()=>F.cancelEdit(),attach:e=>F.attach(e),removeAttachment:e=>F.removeAttachment(e),openConversation:e=>F.openConversation(e),resumeLast:()=>F.resumeLast(),newConversation:()=>F.newConversation(),rate:(e,t,n)=>F.rate(e,t,n),reset:()=>F.reset()}),[F]),ee=m((e,t)=>v.current?.(e,t),[]);return{...I,...L,session:F,client:t,emit:ee,onNavigate:p}}export{X as ChatComposer,Ve as ChatConversationActions,wr as ChatEmbed,Or as ChatExplain,He as ChatFooter,Vr as ChatLauncher,Ut as ChatLoader,dt as ChatOpenTickets,Sr as ChatPage,Hr as ChatPanel,lt as ChatPastChats,xt as ChatReadAloudButton,hr as ChatThread,cr as defaultRenderers,rt as formatResetTime,Qr as useChat,ke as useChatDictation,nt as useChatExplain,br as useChatHandoff,_t as useChatReadAloud,Be as useTranscriptActions};
@@ -2,9 +2,10 @@
2
2
  * The foot nodes of the chat: the allowance line, the edit banner, the attachment chips and the
3
3
  * composer form, in that order, as CONTRACT-WEBDOM draws them.
4
4
  */
5
- export default function ChatComposer({ chat, labels, maxLength, inputRef }: {
5
+ export default function ChatComposer({ chat, labels, maxLength, inputRef, sendIcon }: {
6
6
  chat: any;
7
7
  inputRef: any;
8
8
  labels: any;
9
9
  maxLength: any;
10
+ sendIcon?: string | undefined;
10
11
  }): import("react").JSX.Element;
@@ -2,7 +2,7 @@
2
2
  * The panel of every layout: header, body and foot. The past chats view replaces the body and the
3
3
  * foot until the person returns to the chat.
4
4
  */
5
- export default function ChatFrame({ chat, labels, layout, onClose, panelId, inputRef, ariaLabelOverride, renderers, layoutParts, loader, motion, onOpenAttachment, onOpenTarget, onOpenTicket, onNavigate, resolveLink, linkComponent, onSwitch, open, renderEmpty, }: {
5
+ export default function ChatFrame({ chat, labels, layout, onClose, panelId, inputRef, ariaLabelOverride, renderers, layoutParts, loader, motion, onOpenAttachment, onOpenTarget, onOpenTicket, onNavigate, resolveLink, linkComponent, onSwitch, open, renderEmpty, sendIcon, }: {
6
6
  ariaLabelOverride: any;
7
7
  chat: any;
8
8
  inputRef: any;
@@ -23,4 +23,5 @@ export default function ChatFrame({ chat, labels, layout, onClose, panelId, inpu
23
23
  renderEmpty: any;
24
24
  renderers: any;
25
25
  resolveLink?: null | undefined;
26
+ sendIcon?: string | undefined;
26
27
  }): import("react").JSX.Element;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@webority/chat-react",
3
- "version": "0.134.0",
3
+ "version": "0.135.1",
4
4
  "description": "The Webority Chat React screens: launcher, docked, full-page and embedded shells, thread, composer, one renderer per message part kind and the useChat hook, built on @webority/chat-core and @webority/ui-react.",
5
5
  "license": "SEE LICENSE IN LICENSE.txt",
6
6
  "type": "module",
@@ -26,10 +26,10 @@
26
26
  },
27
27
  "sideEffects": false,
28
28
  "peerDependencies": {
29
- "@webority/chat-core": "0.134.0",
30
- "@webority/chat-elements": "0.134.0",
31
- "@webority/markdown-core": "^0.130.3",
32
- "@webority/ui-react": "^0.130.3",
29
+ "@webority/chat-core": "0.135.1",
30
+ "@webority/chat-elements": "0.135.1",
31
+ "@webority/markdown-core": "^0.131.0",
32
+ "@webority/ui-react": "^0.131.0",
33
33
  "react": "^19.0.0",
34
34
  "react-dom": "^19.0.0"
35
35
  },
@@ -41,12 +41,12 @@
41
41
  "@types/react": "^19.2.17",
42
42
  "@vitejs/plugin-react": "^6.0.1",
43
43
  "@vitest/coverage-v8": "5.0.1",
44
- "@webority/analytics": "0.34.0",
45
- "@webority/chat-core": "0.134.0",
46
- "@webority/chat-elements": "0.134.0",
47
- "@webority/markdown-core": "0.130.3",
48
- "@webority/ui-elements": "0.130.3",
49
- "@webority/ui-react": "0.130.3",
44
+ "@webority/analytics": "0.35.0",
45
+ "@webority/chat-core": "0.135.1",
46
+ "@webority/chat-elements": "0.135.1",
47
+ "@webority/markdown-core": "0.131.0",
48
+ "@webority/ui-elements": "0.131.0",
49
+ "@webority/ui-react": "0.131.0",
50
50
  "bootstrap": "5.3.3",
51
51
  "jsdom": "30.1.1",
52
52
  "react": "19.2.8",