@xapp/chat-widget 1.108.0 → 1.108.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.
@@ -4,5 +4,5 @@ var XAppChatWidget=function(e){"use strict";var t=function(){return t=Object.ass
4
4
  Object.defineProperty(Yw,"__esModule",{value:!0}),Yw.parseRgb=Xw,Yw.invertColorHEX=ex,Yw.invertColorRgb=tx,Yw.invertColor=function(e,t){if(!e)return;return e.startsWith("#")?ex(e,t):tx(e,t)},Yw.isSupportedColor=nx,Yw.usableColorOr=function(e,t){return nx(e)?e:t},Yw.readableTextOn=function(e){if(!nx(e))return"#000000";const t=e.startsWith("#")?function(e){let t=e.slice(1);3===t.length&&(t=t[0]+t[0]+t[1]+t[1]+t[2]+t[2]);if(6!==t.length)return null;return{r:parseInt(t.slice(0,2),16),g:parseInt(t.slice(2,4),16),b:parseInt(t.slice(4,6),16)}}(e):Xw(e);if(!t)return"#000000";return Zw(t.r,t.g,t.b)?"#000000":"#FFFFFF"},Yw.darkenColor=function(e,t){if(!e)return e;let n,r,i,o,a;try{if(e.startsWith("#")){const t=e.match(/\w\w/g);t&&([n,r,i]=t.map(e=>parseInt(e,16)))}else if(e.startsWith("rgb")){const t=Xw(e);t&&({r:n,g:r,b:i,a:o}=t)}if(void 0===n||void 0===r||void 0===i)return console.error(`Unsupported color format: ${e}`),e;if(void 0!==o){const e=.3*n+.59*r+.11*i;let s=e*(1-t/100);s=Math.max(0,Math.min(255,s));const l=s/(e||1);n=Math.round(n*l),r=Math.round(r*l),i=Math.round(i*l),o+=t/100,o=Math.max(0,Math.min(1,o)),a=`rgba(${n}, ${r}, ${i}, ${o})`}else t>0?(n=Math.max(0,n-t),r=Math.max(0,r-t),i=Math.max(0,i-t)):(t=Math.abs(t),n=Math.min(255,n+t),r=Math.min(255,r+t),i=Math.min(255,i+t)),a=`#${n.toString(16).padStart(2,"0")}${r.toString(16).padStart(2,"0")}${i.toString(16).padStart(2,"0")}`}catch(t){console.error(`Unsupported color format: ${e} - Error: ${t}`)}return a},Object.defineProperty(Jw,"__esModule",{value:!0}),Jw.buildChatWidgetChannel=function(e){var t;const{appId:n,apiUrl:r,mcpUrl:i,formWidgetKey:o,phoneNumber:a}=e,s=null===(t=e.businessName)||void 0===t?void 0:t.trim(),l=(0,rx.usableColorOr)(e.primaryColor,ix);return Object.assign(Object.assign({type:"chat-widget",connection:{type:"mcp",serverUrl:`${i}/${n}`,mcp:{mode:"homeowner"}},theme:ax(l,e.secondaryColor),actionBar:ox({apiUrl:r,formWidgetKey:o,phoneNumber:a})},o?{formWidgetKey:o}:{}),s?{botName:s}:{})},Jw.buildChatTheme=ax;const rx=Yw,ix="#1AA7DC";function ox(e){const{apiUrl:t,formWidgetKey:n,phoneNumber:r}=e,i=[];return n&&i.push({id:"book",type:"schedule",label:"Book",formConfig:{api:{url:t,key:n}}}),r&&i.push({id:"call",type:"phone",label:"Call",phoneNumber:r}),i.push({id:"chat",type:"chat",label:"Chat"}),{enabled:!0,position:"right",buttons:i}}function ax(e,t){const n="RobotoRegular";return t||(t=(0,rx.readableTextOn)(e)),{zIndex:"10000",border:{color:e,radius:"10px"},carousel:{button:{color:e},subtitle:{color:"#979797",fontFamily:n,fontSize:"12px",fontStyle:"normal",fontWeight:"normal"},title:{color:"#000",fontFamily:n,fontSize:"14px",fontStyle:"normal",fontWeight:"bold"}},chatButton:{background:e,margin:{bottom:"10px",left:"10px",right:"10px",top:"10px"}},content:{background:"#ffffff"},cta:{background:"#e1e2e1",text:{color:"#333333",fontFamily:n,fontSize:"14px"}},footer:{background:e,border:{color:e,radius:"0px",width:"0px"},branding:{text:{color:"#ffffff",fontFamily:n,fontSize:"14px",fontWeight:"normal",fontStyle:"normal"}}},header:{background:e,avatarBackground:"transparent",border:{color:e,radius:"0px",width:"0px"},text:{color:t,fontFamily:n,fontSize:"16px",fontWeight:"normal",fontStyle:"normal"},subtitle:{color:t,fontFamily:n,fontSize:"10px",fontWeight:"normal",fontStyle:"normal"}},input:{background:"#ffffff",border:{radius:"20px"},text:{color:"#000000",fontFamily:n,fontSize:"14px"},placeholder:{color:"#e1e2e1",fontFamily:n,fontSize:"14px",fontWeight:"normal",fontStyle:"normal"}},textTypingStatus:{text:{color:"#bfbfbf",fontFamily:n,fontSize:"14px",fontWeight:"normal",fontStyle:"normal"}},menu:{item:{height:"24px",text:{fontSize:"14px"}}},menuButton:{color:"#ffffff"},messages:{maxWidth:"400px",mine:{bubbleColor:"#f2f2f2",text:{color:"#454545",fontFamily:n,fontSize:"18px",fontStyle:"normal",fontWeight:"normal"}},others:{bubbleColor:"#e1e2e1",text:{color:"#262726",fontFamily:n,fontSize:"18px",fontStyle:"normal",fontWeight:"normal"}},padding:{bottom:"0px",left:"20px",right:"16px",top:"16px"}},refreshButton:{color:t},minimizeButton:{color:t},cancelButton:{color:t},primaryColor:e,sendButton:{color:"#505050",width:"20px"},size:{width:"500px",height:"700px"}}}var sx={};Object.defineProperty(sx,"__esModule",{value:!0});var lx={};Object.defineProperty(lx,"__esModule",{value:!0}),lx.CHAT_WIDGET_CHANNEL=void 0,lx.CHAT_WIDGET_CHANNEL="chat-widget";var cx={};
5
5
  /*! Copyright (c) 2021, XAPPmedia */Object.defineProperty(cx,"__esModule",{value:!0});var ux={};Object.defineProperty(ux,"__esModule",{value:!0});var dx={};Object.defineProperty(dx,"__esModule",{value:!0});var fx={};Object.defineProperty(fx,"__esModule",{value:!0});var px={};Object.defineProperty(px,"__esModule",{value:!0}),px.isStaticImageMenuItem=function(e){return!!e&&!!e.imageUrl},px.isStaticTextMenuItem=function(e){return!!e&&!!e.body},px.isStandardMenuItem=function(e){return!!e&&!!e.label},px.isOpenURLMenuItem=function(e){return!!e&&!!e.url},function(e){var t=o&&o.__createBinding||(Object.create?function(e,t,n,r){void 0===r&&(r=n);var i=Object.getOwnPropertyDescriptor(t,n);i&&!("get"in i?!t.__esModule:i.writable||i.configurable)||(i={enumerable:!0,get:function(){return t[n]}}),Object.defineProperty(e,r,i)}:function(e,t,n,r){void 0===r&&(r=n),e[r]=t[n]}),n=o&&o.__exportStar||function(e,n){for(var r in e)"default"===r||Object.prototype.hasOwnProperty.call(n,r)||t(n,e,r)};Object.defineProperty(e,"__esModule",{value:!0}),
6
6
  /*! Copyright (c) 2021, XAPPmedia */
7
- n(Qw,e),n(Jw,e),n(sx,e),n(Yw,e),n(lx,e),n(cx,e),n(ux,e),n(dx,e),n(fx,e),n(px,e)}(Kw);var hx=function(){return f.jsx("svg",{width:"24",height:"24",viewBox:"0 0 24 24",fill:"currentColor",children:f.jsx("path",{d:"M19 4h-1V2h-2v2H8V2H6v2H5c-1.11 0-1.99.9-1.99 2L3 20c0 1.1.89 2 2 2h14c1.1 0 2-.9 2-2V6c0-1.1-.9-2-2-2zm0 16H5V10h14v10zm0-12H5V6h14v2zM9 14H7v-2h2v2zm4 0h-2v-2h2v2zm4 0h-2v-2h2v2zm-8 4H7v-2h2v2zm4 0h-2v-2h2v2zm4 0h-2v-2h2v2z"})})},mx=function(){return f.jsx("svg",{width:"24",height:"24",viewBox:"0 0 24 24",fill:"currentColor",children:f.jsx("path",{d:"M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76 0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71 0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71 0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76 0 5-2.24 5-5s-2.24-5-5-5z"})})},vx=function(){return f.jsx("svg",{width:"24",height:"24",viewBox:"0 0 24 24",fill:"currentColor",children:f.jsx("path",{d:"M12 2C6.48 2 2 6.48 2 12s4.48 10 10 10 10-4.48 10-10S17.52 2 12 2zm1 15h-2v-2h2v2zm0-4h-2V7h2v6z"})})},gx={chat:function(){return f.jsx("svg",{width:"24",height:"24",viewBox:"0 0 24 24",fill:"currentColor",children:f.jsx("path",{d:"M20 2H4c-1.1 0-2 .9-2 2v18l4-4h14c1.1 0 2-.9 2-2V4c0-1.1-.9-2-2-2zm0 14H6l-2 2V4h16v12z"})})},form:function(){return f.jsx("svg",{width:"24",height:"24",viewBox:"0 0 24 24",fill:"currentColor",children:f.jsx("path",{d:"M14 2H6c-1.1 0-2 .9-2 2v16c0 1.1.9 2 2 2h12c1.1 0 2-.9 2-2V8l-6-6zM6 20V4h7v5h5v11H6zm2-6h8v2H8v-2zm0-3h8v2H8v-2zm0 6h5v2H8v-2z"})})},calendar:hx,schedule:hx,phone:function(){return f.jsx("svg",{width:"24",height:"24",viewBox:"0 0 24 24",fill:"currentColor",children:f.jsx("path",{d:"M6.62 10.79c1.44 2.83 3.76 5.14 6.59 6.59l2.2-2.2c.27-.27.67-.36 1.02-.24 1.12.37 2.33.57 3.57.57.55 0 1 .45 1 1V20c0 .55-.45 1-1 1-9.39 0-17-7.61-17-17 0-.55.45-1 1-1h3.5c.55 0 1 .45 1 1 0 1.25.2 2.45.57 3.57.11.35.03.74-.25 1.02l-2.2 2.2z"})})},link:mx,url:mx,email:function(){return f.jsx("svg",{width:"24",height:"24",viewBox:"0 0 24 24",fill:"currentColor",children:f.jsx("path",{d:"M20 4H4c-1.1 0-1.99.9-1.99 2L2 18c0 1.1.9 2 2 2h16c1.1 0 2-.9 2-2V6c0-1.1-.9-2-2-2zm0 4l-8 5-8-5V6l8 5 8-5v2z"})})},help:function(){return f.jsx("svg",{width:"24",height:"24",viewBox:"0 0 24 24",fill:"currentColor",children:f.jsx("path",{d:"M12 2C6.48 2 2 6.48 2 12s4.48 10 10 10 10-4.48 10-10S17.52 2 12 2zm1 17h-2v-2h2v2zm2.07-7.75l-.9.92C13.45 12.9 13 13.5 13 15h-2v-.5c0-1.1.45-2.1 1.17-2.83l1.24-1.26c.37-.36.59-.86.59-1.41 0-1.1-.9-2-2-2s-2 .9-2 2H8c0-2.21 1.79-4 4-4s4 1.79 4 4c0 .88-.36 1.68-.93 2.25z"})})},payment:function(){return f.jsx("svg",{width:"24",height:"24",viewBox:"0 0 24 24",fill:"currentColor",children:f.jsx("path",{d:"M20 4H4c-1.11 0-1.99.89-1.99 2L2 18c0 1.11.89 2 2 2h16c1.11 0 2-.89 2-2V6c0-1.11-.89-2-2-2zm0 14H4v-6h16v6zm0-10H4V6h16v2z"})})}},yx=function(e){var t=e.type,n=e.icon,r=e.iconUrl,i=e.className;if(r)return f.jsx("div",{className:i,children:f.jsx("img",{src:r,alt:"".concat(n||t," icon")})});var o=gx[n||t]||vx;return f.jsx("div",{className:i,children:f.jsx(o,{})})},bx=["http:","https:","tel:","mailto:"];function wx(e,t,n){if(!function(e){try{var t=new URL(e,window.location.href);return bx.includes(t.protocol)}catch(e){return!1}}(e))return console.warn("[ActionBar] Blocked navigation to unsafe URL:",e),!1;if("sameWindow"===t)window.location.href=e;else if("newWindow"===t&&n){var r="width=".concat(n.width||600,",height=").concat(n.height||400);window.open(e,"_blank",r)}else window.open(e,"_blank","noopener,noreferrer");return!0}var xx={chat:"Chat",form:"Contact",schedule:"Book",phone:"Call",url:"Link",email:"Email",help:"Help",payment:"Pay"},kx=function(e){var t,n=e.button,r=e.chatActive,i=e.onChatClick,o=e.onChatMinimize,a=e.onFormClick,s=e.isMobile,l=Z.useCallback(function(){if(Kw.isActionBarChatButton(n))r?o():i();else if(Kw.isActionBarFormButton(n)||Kw.isActionBarScheduleButton(n))a(n);else if(Kw.isActionBarPhoneButton(n)){var e=n.phoneNumber.replace(/\s/g,"");window.location.href="tel:".concat(e)}else if(Kw.isActionBarUrlButton(n)){var t=n.url,s=n.target;wx(t,void 0===s?"newTab":s,n.windowOptions)}else if(Kw.isActionBarEmailButton(n)){var l=n.emailAddress,c=n.subject,u=n.body,d="mailto:".concat(l),f=[];c&&f.push("subject=".concat(encodeURIComponent(c))),u&&f.push("body=".concat(encodeURIComponent(u))),f.length>0&&(d+="?".concat(f.join("&"))),window.location.href=d}else if(Kw.isActionBarHelpButton(n)){t=n.url;var p=n.target;wx(t,void 0===p?"newTab":p)}else if(Kw.isActionBarPaymentButton(n)){t=n.url;var h=n.target;wx(t,void 0===h?"newTab":h)}},[n,r,i,o,a]),c=n.visibility||"all";if("mobile-only"===c&&!s)return null;if("desktop-only"===c&&s)return null;var u=n.label||xx[n.type]||n.type,d=null!==(t=n.tabIndex)&&void 0!==t?t:0,p=Kw.isActionBarChatButton(n)&&r,h=["xapp-action-bar__button",p?"xapp-action-bar__button--active":""].filter(Boolean).join(" ");return f.jsxs("button",{className:h,onClick:l,"aria-label":u,"aria-pressed":p,tabIndex:d,children:[f.jsx(yx,{type:n.type,icon:n.icon,iconUrl:n.iconUrl,className:"xapp-action-bar__icon"}),n.label&&f.jsx("span",{className:"xapp-action-bar__label",children:n.label})]})},Sx=function(e){var t,n,r,i,o,a,s,l,c,u,d=e.config,p=e.isMobile,h=e.onClick,m=e.onDismiss,v=e.hasUserInteracted,g=Z.useState(!1),y=g[0],b=g[1],w=Z.useState(!1),x=w[0],k=w[1],S=Z.useState(!1),C=S[0],_=S[1],E=p?null===(t=d.mobile)||void 0===t?void 0:t.message:void 0,N=void 0!==E?E:d.message,I=p&&void 0!==(null===(n=d.mobile)||void 0===n?void 0:n.delay)?d.mobile.delay:null!==(r=d.delay)&&void 0!==r?r:0,T=p?null===(i=d.mobile)||void 0===i?void 0:i.timeout:void 0,j=void 0!==T?T:d.timeout,O=p?null===(o=d.mobile)||void 0===o?void 0:o.animation:void 0,P=void 0!==O?O:d.animation,A=p&&void 0!==(null===(a=d.mobile)||void 0===a?void 0:a.animationDelay)?d.mobile.animationDelay:null!==(s=d.animationDelay)&&void 0!==s?s:I,R=p&&void 0!==(null===(l=d.mobile)||void 0===l?void 0:l.animationTimeout)?d.mobile.animationTimeout:d.animationTimeout,M=p&&void 0!==(null===(c=d.mobile)||void 0===c?void 0:c.dismissible)?d.mobile.dismissible:null===(u=d.dismissible)||void 0===u||u;Z.useEffect(function(){if(N&&!v&&!C){var e=setTimeout(function(){b(!0)},I);return function(){return clearTimeout(e)}}b(!1)},[N,I,v,C]),Z.useEffect(function(){if(y&&j){var e=setTimeout(function(){b(!1)},j);return function(){return clearTimeout(e)}}},[y,j]),Z.useEffect(function(){if(P&&!v&&!C){var e=setTimeout(function(){k(!0)},A);return function(){return clearTimeout(e)}}k(!1)},[P,A,v,C]),Z.useEffect(function(){if(x&&R){var e=setTimeout(function(){k(!1)},R);return function(){return clearTimeout(e)}}},[x,R]);var L=function(){h(),b(!1)};if(!y||!N)return null;var D=x&&P?"xapp-action-bar-cta--".concat(P):"";return f.jsxs("div",{className:"xapp-action-bar-cta ".concat(D),onClick:L,role:"button",tabIndex:0,"aria-label":N,onKeyDown:function(e){"Enter"!==e.key&&" "!==e.key||(e.preventDefault(),L())},children:[f.jsx("span",{className:"xapp-action-bar-cta__message",children:N}),M&&f.jsx("button",{className:"xapp-action-bar-cta__dismiss",onClick:function(e){e.stopPropagation(),_(!0),b(!1),m()},"aria-label":"Dismiss",type:"button",children:f.jsx("svg",{width:"14",height:"14",viewBox:"0 0 14 14",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:f.jsx("path",{d:"M13 1L1 13M1 1L13 13",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"})})})]})},Cx="--xapp-action-bar-height";function _x(e){return Kw.isActionBarFormButton(e)||Kw.isActionBarScheduleButton(e)}function Ex(e,t){void 0===e&&(e=[]),void 0===t&&(t={});var n=t.chatDisabled,r=t.formDisabled;return e.filter(function(e){return(!n||!Kw.isActionBarChatButton(e))&&(!r||!_x(e))})}var Nx=function(e){var t,n,r=e.config,i=e.visible,o=e.chatDisabled,a=e.formDisabled,s=e.hasUserInteracted,l=void 0!==s&&s,c=e.onChatClick,u=e.onChatMinimize,d=e.onFormClick,p=e.onCtaDismiss,h=Z.useState(!1),m=h[0],v=h[1],g=null!=r.mobileBreakpoint?"(max-width: ".concat(r.mobileBreakpoint,"px)"):yb,y=null!==(t=r.position)&&void 0!==t?t:"right",b=Z.useRef(null);Z.useEffect(function(){if("function"==typeof window.matchMedia){var e=window.matchMedia(g);v(e.matches);var t=function(e){v(e.matches)};return"function"==typeof e.addEventListener?(e.addEventListener("change",t),function(){return e.removeEventListener("change",t)}):(e.addListener(t),function(){return e.removeListener(t)})}},[g]),Z.useLayoutEffect(function(){var e=b.current;if(e){var t=function(){var t=e.getBoundingClientRect().height;t<=0||document.documentElement.style.setProperty(Cx,"".concat(t,"px"))};if(t(),"undefined"==typeof ResizeObserver)return function(){document.documentElement.style.removeProperty(Cx)};var n=new ResizeObserver(t);return n.observe(e),function(){n.disconnect(),document.documentElement.style.removeProperty(Cx)}}},[m]);var w=Ex(r.buttons,{chatDisabled:o,formDisabled:a}),x=["xapp-action-bar","xapp-action-bar--".concat(y),m?"xapp-action-bar--mobile":"xapp-action-bar--desktop"].filter(Boolean).join(" "),k=w.some(Kw.isActionBarChatButton),S=(null===(n=r.cta)||void 0===n?void 0:n.message)&&!i&&!o&&k;return 0===w.length?null:f.jsxs("div",{ref:b,className:x,role:"toolbar","aria-label":"Chat actions",children:[S&&f.jsx("div",{className:"xapp-action-bar-cta-wrapper",children:f.jsx(Sx,{config:r.cta,isMobile:m,onClick:function(){c()},onDismiss:function(){null==p||p()},hasUserInteracted:l})}),f.jsx("div",{className:"xapp-action-bar__buttons",children:w.map(function(e){return f.jsx(kx,{button:e,chatActive:i,onChatClick:c,onChatMinimize:u,onFormClick:d,isMobile:m},e.id)})})]})};function Ix(){var e=Z.useRef(null),t=Z.useState(),n=t[0],r=t[1];return Z.useLayoutEffect(function(){var t,n;r(null===(n=null===(t=e.current)||void 0===t?void 0:t.getBoundingClientRect())||void 0===n?void 0:n.toJSON())},[]),[e,n]}function Tx(e,t){return{x:e.x+t.x,y:e.y+t.y}}function jx(e,t){return{x:e.x-t.x,y:e.y-t.y}}function Ox(e,t){return{x:e.x*t,y:e.y*t}}function Px(e){return Math.sqrt(e.x*e.x+e.y*e.y)}function Ax(e,t){var n=t*Math.PI/180,r=Math.cos(n),i=Math.sin(n);return{x:e.x*r+e.y*i,y:e.y*r-e.x*i}}function Rx(e,t){var n=jx(t.start,e.center),r=n.x,i=n.y,o=t.direction.x,a=t.direction.y,s=e.radius.x,l=e.radius.y,c=s*s,u=l*l,d=o*o/c+a*a/u,f=2*o*r/c+2*a*i/u,p=f*f-4*d*(r*r/c+i*i/u-1);if(p>=0){var h=Math.sqrt(p),m=(-f-h)/(2*d),v=(-f+h)/(2*d);if(m>0&&v>0)return Tx(t.start,Ox(t.direction,Math.min(m,v)));if(m>0)return Tx(t.start,Ox(t.direction,m));if(v>0)return Tx(t.start,Ox(t.direction,v))}return t.start}function Mx(e,t){var n,r,i,o=e.direction*Math.PI/180,a={x:e.width/2,y:e.height/2},s={x:t.x/2,y:t.y/2},l={x:a.x*Math.cos(o),y:a.y*Math.sin(o)},c=(n=l,r=Px(l)+e.length,(i=Px(n))?Ox(n,r/i):n),u=Tx(c,s),d=jx(l,c),f=e.angle,p=Ax(d,f/2),h=Ax(d,-f/2),m={center:s,radius:a},v=Rx(m,{start:u,direction:p}),g=Rx(m,{start:u,direction:h});return"m ".concat(u.x," ").concat(u.y," L ").concat(v.x," ").concat(v.y," L ").concat(g.x," ").concat(g.y," z")}var Lx=function(e){var t,n,r=Ix(),i=r[0],o=r[1],a={x:null!==(t=null==o?void 0:o.width)&&void 0!==t?t:0,y:null!==(n=null==o?void 0:o.height)&&void 0!==n?n:0};return f.jsx("div",{ref:i,className:"cta-bubble__tail",children:f.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 ".concat(a.x," ").concat(a.y),children:f.jsx("path",{d:Mx(e,a),fill:"currentColor"})})})},Dx=function(e){var t,n,r,i,o=Ix(),a=o[0],s=o[1],l=(e.animate||!1)&&"bounce"===e.buttonAnimation?"bounce":"none";return console.log("Returning CTABubble with message: ",e.children),f.jsxs("div",{ref:a,style:{border:e.borderStyle?"solid":"none",borderWidth:(null===(t=e.borderStyle)||void 0===t?void 0:t.width)||"0px",borderColor:(null===(n=e.borderStyle)||void 0===n?void 0:n.color)||"transparent",animation:"".concat(l," 1s infinite")},className:"cta-bubble",onClick:e.onClick,children:[f.jsx(Lx,{width:null!==(r=null==s?void 0:s.width)&&void 0!==r?r:0,height:null!==(i=null==s?void 0:s.height)&&void 0!==i?i:0,direction:60,angle:45,length:16}),f.jsx("div",{className:"cta-bubble__content",children:e.children}),e.dismissible&&f.jsx("button",{className:"cta-bubble__dismiss",onClick:function(t){t.stopPropagation(),e.onDismiss&&e.onDismiss()},"aria-label":"Dismiss",children:f.jsx("svg",{width:"12",height:"12",viewBox:"0 0 12 12",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:f.jsx("path",{d:"M11 1L1 11M1 1L11 11",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"})})})]})},Bx=function(e){var t=e.visible,n=e.timeout,r=e.delay,i=e.animate,o=e.buttonAnimation,a=e.dismissible,s=e.onClick,l=e.onDismiss,c=e.children;Yh("[CtaBubbleContainer] Props received:",{visible:t,timeout:n,delay:r,animate:i,buttonAnimation:o,dismissible:a,hasOnClick:!!s,hasOnDismiss:!!l,hasChildren:!!c,childrenContent:c});var u=Z.useMemo(function(){var e=t?(new Date).valueOf():void 0;return Yh("[CtaBubbleContainer] StartTime calculated: visible=".concat(t,", startTime=").concat(e)),e},[t]),d=Z.useState(!1),p=d[0],h=d[1];Yh("[CtaBubbleContainer] Current state: showBubble=".concat(p)),Z.useEffect(function(){Yh("[CtaBubbleContainer] useEffect triggered with:",{startTime:u,startTimeExists:!!u,timeout:n,timeoutType:typeof n,delay:r,delayType:typeof r,visible:t});var e=null,i=null,o=!0;if(u){var a=r||0;Yh("[CtaBubbleContainer] Timer setup: actualDelay=".concat(a,"ms (from delay=").concat(r,")")),i=setTimeout(function(){Yh("[CtaBubbleContainer] Delay timer fired after ".concat(a,"ms, isMounted=").concat(o)),o?(Yh("[CtaBubbleContainer] Component still mounted, setting showBubble=true"),h(!0),"number"==typeof n?(Yh("[CtaBubbleContainer] Hide timer setup: will hide after ".concat(n,"ms")),e=setTimeout(function(){Yh("[CtaBubbleContainer] Hide timer fired after ".concat(n,"ms, isMounted=").concat(o)),o?(Yh("[CtaBubbleContainer] Component still mounted, setting showBubble=false"),h(!1)):Yh("[CtaBubbleContainer] Component unmounted, skipping hide")},n)):Yh("[CtaBubbleContainer] No hide timer set (timeout=".concat(n,", type=").concat(typeof n,")"))):Yh("[CtaBubbleContainer] Component unmounted before delay timer, not showing bubble")},a)}else Yh("[CtaBubbleContainer] No startTime, skipping timer setup");return function(){Yh("[CtaBubbleContainer] Cleanup triggered, unmounting component"),o=!1,e&&(Yh("[CtaBubbleContainer] Clearing hide timer"),clearTimeout(e)),i&&(Yh("[CtaBubbleContainer] Clearing delay timer"),clearTimeout(i))}},[u,n,r,t]);var m=t&&p;return Yh("[CtaBubbleContainer] Render decision: visible=".concat(t,", showBubble=").concat(p,", shouldRender=").concat(m)),f.jsx(f.Fragment,{children:t&&p&&f.jsx(Dx,{onClick:s,animate:i,buttonAnimation:o,dismissible:a,onDismiss:function(){Yh("[CtaBubbleContainer] handleDismiss called, setting showBubble=false"),h(!1),l&&(Yh("[CtaBubbleContainer] Calling onDismiss callback"),l())},children:c})})},zx=function(e){var t,n=e.onClick,r=e.addClass,i=e.config,o=e.visible,a=e.borderStyle,s=e.imageUrl,l=e.hasInteracted,c=e.onCtaDismiss,u=Z.useState(em),d=u[0],p=u[1],h=Z.useState(!1),m=h[0],v=h[1],g=(null===(t=null==i?void 0:i.mobile)||void 0===t?void 0:t.applyAtLessThanWidth)||"400",y=window.innerWidth<=parseInt(g,10)&&(null==i?void 0:i.mobile)?i.mobile:i;Z.useEffect(function(){var e,t,n;if(l)return v(!1),function(){};var r=null!==(e=null==y?void 0:y.animationDelay)&&void 0!==e?e:null==y?void 0:y.delay;return r?t=setTimeout(function(){v(!0),y.animationTimeout&&(n=setTimeout(function(){v(!1)},y.animationTimeout))},r):(null==y?void 0:y.animationTimeout)?(v(!0),n=setTimeout(function(){v(!1)},y.animationTimeout)):(null==y?void 0:y.animation)&&v(!0),function(){t&&clearTimeout(t),n&&clearTimeout(n)}},[y,v,l]);var b=m&&!l?(null==y?void 0:y.animation)||"wiggle":"none";Z.useEffect(function(){var e=function(){var e=window.innerWidth<parseInt(g,10)?"30":em;p(e)};return e(),window.addEventListener("resize",e),function(){window.removeEventListener("resize",e)}},[g]);var w=Math.min(22,+d/48*22);return f.jsxs("button",{"aria-label":"open chat",className:"xapp-chat-button ".concat(r||"").trim(),onClick:n,children:[f.jsx("div",{id:"xapp-widget-button",className:"xapp-chat-button__btn",style:{width:"".concat(d,"px"),height:"".concat(d,"px"),borderRadius:"".concat(+d/2,"px"),border:a&&a.width?"solid":"none",borderWidth:(null==a?void 0:a.width)||"0px",borderColor:(null==a?void 0:a.color)||"transparent",animation:"".concat(b," 1s infinite")},children:s?f.jsx("img",{src:s,alt:"Chat Icon"}):f.jsx("svg",{width:w,height:w,viewBox:"0 0 22 22",children:f.jsx("path",{d:"M13 22l-4-6H2c-1.11-.043-2-.935-2-2V2C0 .89.89 0 2 0h18c1.11 0 2 .892 2 2v12c0 1.067-.89 1.957-2 2h-3l-4 6zm3-8h4c-.005.3-.01-12 0-12-.01.004-18 .006-18 0 .005.006 0 12 0 12h8l3 5 3-5z",fill:"#FFF",fillRule:"evenodd"})})}),y&&y.message&&!l&&f.jsx("div",{className:"xapp-chat-button__cta",children:f.jsx(Bx,{timeout:null==y?void 0:y.timeout,delay:null==y?void 0:y.delay,animate:m,buttonAnimation:b,dismissible:null==y?void 0:y.dismissible,visible:!o,onDismiss:c,children:null==y?void 0:y.message})})]})};function Ux(e,t){var n=Z.useState(),r=n[0],i=n[1],o=Z.useState(-1),a=o[0],s=o[1],l=Z.useState(e),c=l[0],u=l[1],d=Z.useState(t),f=d[0],p=d[1];Z.useEffect(function(){u(e)},[e]),Z.useEffect(function(){p(t)},[t]);var h=Z.useMemo(function(){return r?$v(r,a):void 0},[r,a]),m=Z.useCallback(function(e){if(r){var t=Qv(r);s(function(n){return function(e,t){return(e+t)%t}(n+e+(n<0&&e<=0?1:0),t)})}else s(-1)},[r]),v=Z.useCallback(function(e){switch(e){case"prev":m(-1);break;case"next":m(1);break;case"cancel":s(-1),u(void 0),p(void 0)}},[m]),g=function(e,t){var n=rm(),r=null==n?void 0:n.autocompleteSuggestionsUrl;return ng({url:r,query:e,context:t})}(c||"",f),y="success"===g.state?g.data:void 0,b=Z.useMemo(function(){return y?Yv(y,-1).map(function(e){return{heading:e.heading,items:e.items.slice().reverse()}}):void 0},[y]);return Z.useEffect(function(){var e=h;i(b),e&&b||s(-1)},[b,h]),Z.useMemo(function(){return{suggestions:r,index:a,execute:v,item:h}},[r,a,v,h])}var Fx=function(e){var t=e.onAdminJoin,n=Z.useRef(null),r=Z.useState(!1),i=r[0],o=r[1],a=Z.useState(""),s=a[0],l=a[1];function c(e){l(e.target.value)}var u=""===s||void 0===s,d=cb();function p(e){var r,a;e.preventDefault(),i?(d(function(e){return function(){e.bargeOut(function(e){e&&Yh(e)})}}),o(!1),t(!1),l("")):(d((a=null===(r=n.current)||void 0===r?void 0:r.value,function(e){return function(){e.bargeIn(a,function(e){e&&Yh(e)})}})),o(!0),t(!0))}return f.jsx("div",{className:"xappw-admin-input-container visible",children:i?f.jsx("form",{className:"xappw-admin-input-form",onSubmit:p,children:f.jsx("div",{className:"xappw-admin-input-form__buttons",children:f.jsx(lm,{addClass:"xappw-admin-input-form__btn",type:"submit",label:"Leave"})})}):f.jsxs("form",{className:"xappw-admin-input-form",onSubmit:p,children:[f.jsx("div",{className:"xappw-admin-input-form__buttons",children:f.jsx(lm,{addClass:"xappw-admin-input-form__btn",type:"submit",label:"Join",disable:u})}),f.jsx("div",{className:"xappw-admin-input",children:f.jsx("input",{ref:n,id:"adminBarInput",placeholder:"Type your name here...",className:"xappw-admin-input__input",onChange:c})})]})})};var qx=function(e){var t,n=e.text,r=e.applyBrandingClass,i=e.linkColor,o=(t={"chat-footer__branding":r},Object.keys(t).filter(function(e){return t[e]}).join(" ")),a=n.replace(/\[(.*?)\]\((.*?)\)/g,function(e,t,n){return'<a style="color: '.concat(i||"",'; text-decoration: underline;" href="').concat(n,'" target="_blank" rel="noopener noreferrer">').concat(t,"</a>")}).replace(/\*\*(.*?)\*\*/g,function(e,t){return"<b>".concat(t,"</b>")}).replace(/^(#{1,6}) (.*?)(?=\n|$)/gm,function(e,t,n){var r=t.length;return"<h".concat(r,">").concat(n,"</h").concat(r,">")});return f.jsx("div",{className:o,dangerouslySetInnerHTML:{__html:a}})},Hx=function(e){var t=e.text;return(null==t?void 0:t.match(/\[([^\]]+)\]\((https?:\/\/[^\)]+)\)/))?f.jsx(qx,{text:t,applyBrandingClass:!0,linkColor:"white"}):f.jsx("div",{className:"chat-footer__branding",style:{color:"white"},children:t})},Wx=function(e){var t=e.subtitle?f.jsxs("span",{children:[f.jsx("div",{children:e.label}),f.jsx("div",{className:"chat-menu-item--subtitle",children:e.subtitle})]}):f.jsx("span",{children:e.label});return f.jsx("button",{type:"button",className:"chat-menu-item",tabIndex:e.tabIndex?Number(e.tabIndex):0,onClick:function(){e.onClick&&e.onClick(e.label)},children:t})},Vx=function(e){var t=e.items,n=e.opened,r=e.openFrom||"bottom",i=wb(),o=Cm(),a=Rh(function(e){return e.visuals});return f.jsx("div",{className:"chat-menu-".concat(r," ").concat("chat-menu-".concat(r,n?"--opened":"--closed")),children:t.map(function(t,n){return Kw.isStandardMenuItem(t)?f.jsx(Wx,{onClick:e.onItemClick,label:t.label,subtitle:t.subtitle},n):Kw.isStaticImageMenuItem(t)?f.jsx("div",{className:"chat-menu-item-static",children:f.jsx("img",{style:{maxHeight:"100%",maxWidth:"auto"},src:t.imageUrl,alt:"Menu Item"})},n):Kw.isStaticTextMenuItem(t)?f.jsx("div",{className:"chat-menu-item-static-text",children:f.jsxs("div",{children:[f.jsx("div",{children:t.title}),f.jsx("div",{className:"chat-menu-item-static-text--body",children:t.body})]})},n):Kw.isOpenURLMenuItem(t)?f.jsx("button",{className:"chat-menu-item",onClick:i.bind(undefined,t.url,o,a,t.behavior),children:t.text},n):f.jsx("p",{children:"Unknown"})})})},$x=function(e){var t=e.bars;return t||(t=2),f.jsx("button",{className:"drawer-bars",tabIndex:e.tabIndex?Number(e.tabIndex):0,"aria-label":"open menu","aria-hidden":!1,onClick:e.onToggle,children:function(){for(var e=[],n=0;n<t;n++)e.push(f.jsx("div",{className:"drawer-bar bar".concat(n)},"drawer-bar-".concat(n)));return e}()})},Kx=function(){return f.jsx("svg",{style:{color:"grey",paddingRight:"5px"},xmlns:"http://www.w3.org/2000/svg",fill:"currentColor",viewBox:"0 0 16 16",children:f.jsx("path",{d:"M1.293 1.293a1 1 0 0 1 1.414 0L8 6.586l5.293-5.293a1 1 0 1 1 1.414 1.414L9.414 8l5.293 5.293a1 1 0 0 1-1.414 1.414L8 9.414l-5.293 5.293a1 1 0 0 1-1.414-1.414L6.586 8 1.293 2.707a1 1 0 0 1 0-1.414z"})})},Qx=function(){return f.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",fill:"currentColor",viewBox:"0 0 16 16",children:f.jsx("path",{fillRule:"evenodd",d:"M2 13.5a.5.5 0 0 0 .5.5h6a.5.5 0 0 0 0-1H3.707L13.854 2.854a.5.5 0 0 0-.708-.708L3 12.293V7.5a.5.5 0 0 0-1 0v6z"})})},Jx=function(){return f.jsx("svg",{viewBox:"80.208 98.129 313.069 282.823",xmlns:"http://www.w3.org/2000/svg",children:f.jsxs("g",{transform:"matrix(0.024498, 0, 0, -0.038359, 79.83091, 381.182404)",fill:"currentColor",stroke:"none",children:[f.jsx("path",{d:"M12670 7345 c-63 -18 -272 -77 -465 -130 -192 -53 -478 -132 -635 -175 -508 -141 -1091 -302 -2345 -649 -676 -187 -2038 -563 -3025 -836 -987 -273 -2072 -573 -2410 -666 -338 -94 -802 -222 -1030 -285 -1857 -514 -2579 -714 -2684 -742 -38 -10 -65 -21 -60 -24 5 -3 67 -22 139 -41 72 -20 326 -90 565 -157 239 -67 611 -170 825 -230 215 -60 586 -163 825 -230 239 -67 491 -137 560 -156 l126 -34 974 439 c1397 629 4128 1858 6050 2724 910 410 1826 822 2035 917 209 94 387 173 395 176 35 10 -66 -39 -8200 -3928 -586 -280 -1068 -512 -1071 -516 -3 -4 33 -117 82 -252 76 -213 355 -996 765 -2147 65 -183 120 -330 122 -329 1 2 114 558 250 1236 l248 1233 3455 2064 c1900 1135 3670 2193 3933 2351 264 158 491 293 505 301 62 33 -5 -12 -271 -182 -1671 -1070 -7188 -4613 -7188 -4617 0 -7 3661 -2455 3669 -2454 4 1 3713 6853 3977 7347 8 15 11 27 7 26 -5 0 -60 -15 -123 -34z"}),f.jsx("path",{d:"M5030 2232 c-15 -61 -479 -1861 -531 -2058 -21 -83 -39 -154 -39 -158 0 -3 369 330 820 740 452 411 817 750 813 754 -11 10 -1025 754 -1039 763 -8 4 -16 -10 -24 -41z"})]})})},Yx=function(e){var t=e.disabled,n=void 0!==t&&t,r=ee.useState(!1),i=r[0],o=r[1];return f.jsx(f.Fragment,{children:e.sendButtonIcon?f.jsx("button",{className:"xappw-custom-send-button ".concat(n?"disabled":""),tabIndex:e.tabIndex?Number(e.tabIndex):0,onClick:e.onClick,disabled:n,onMouseEnter:function(){return o(!0)},onMouseLeave:function(){return o(!1)},children:f.jsx("img",{src:n&&e.sendButtonIconDisabled?e.sendButtonIconDisabled:i&&!n&&e.sendButtonIconHover?e.sendButtonIconHover:e.sendButtonIcon,alt:"Send button",draggable:!1,className:"send-button-icon"})}):f.jsx(Uv,{className:"xappw-send-button ".concat(e.className||""," ").concat(n?"disabled":""),tabIndex:e.tabIndex,onClick:n?void 0:e.onClick,icon:Jx})})},Gx=function(e){var t,n,r=e.value,i=e.placeholder,o=e.sendButtonIcon,a=e.sendButtonIconHover,s=e.sendButtonIconDisabled,l=e.suggestion,c=e.footerConfig,u=e.inputConfig,d=e.onChange,p=e.onSubmit,h=e.onSuggestionCommand,m=Z.useState(!1),v=m[0],g=m[1],y=null==u?void 0:u.maxLength,b=r.text.length,w=void 0!==y&&b>=y,x=void 0!==y&&b>=.8*y;var k=Z.useCallback(function(e){e&&e.preventDefault(),p(r)},[r,p]),S=Z.useCallback(function(){d({text:"",formats:[]})},[d]),C=Z.useCallback(function(e){!l||"End"!==e.key&&"ArrowRight"!==e.key&&"Enter"!==e.key?h&&("ArrowUp"===e.key?(h("prev"),e.preventDefault()):"ArrowDown"===e.key?(h("next"),e.preventDefault()):"Escape"===e.key&&(h("cancel"),e.preventDefault())):d(l)},[l,d,h]);return f.jsx("div",{className:"xappw-input-container ".concat(e.addClass," ").concat(v?"drag-drop-zone":""),"aria-label":(r.text,"To clear input field click on clear icon on the left of send button"),"aria-hidden":!1,onDrop:function(t){g(!1),e.onFileUpload(t)},onDragOver:function(e){g(!0),e.preventDefault(),e.dataTransfer.dropEffect="copy"},onDragLeave:function(){g(!1)},children:f.jsxs("form",{className:"xappw-input-form",onSubmit:k,children:[f.jsx(Fv,{id:"chatWidgetInput",className:"xappw-input",placeholder:null!=i?i:"type your question here",tabIndex:null==u?void 0:u.tabIndex,maxLength:y,onInput:d,onChange:d,onKeyDown:C,value:r,spellCheck:!0},"input"),f.jsxs("div",{className:"xappw-input-form__buttons",children:[x&&f.jsxs("span",{className:"xappw-input-form__counter".concat(w?" xappw-input-form__counter--limit":""),children:[b,"/",y]}),r.text&&f.jsx(Uv,{icon:Kx,tabIndex:null===(t=null==c?void 0:c.clearButton)||void 0===t?void 0:t.tabIndex,className:"xappw-input-form__btn",onClick:S}),f.jsx(Yx,{className:"xappw-input-form__btn",sendButtonIcon:o,sendButtonIconHover:a,sendButtonIconDisabled:s,tabIndex:null===(n=null==c?void 0:c.sendButton)||void 0===n?void 0:n.tabIndex,disabled:!r.text,onClick:k})]})]})})};var Xx=function(e){var t=e.data,n=e.onItemUse,r=e.searchTerms,i=Z.useState(),o=i[0],a=i[1],s=Z.useState(),l=s[0],c=s[1];Z.useEffect(function(){t&&a(t),r||(a(void 0),c(void 0))},[t,r]);var u=(null==t?void 0:t.length)>0?e.index:NaN,d=Z.useMemo(function(){return $v(t,u)},[t,u]),p=Z.useCallback(function(e,t){if("inputText"===t.type)return n(e),c(void 0),!1},[n]);Z.useEffect(function(){c(d)},[d]);var h,m=Z.useMemo(function(){return function(e){return function(t){var n=t.data,r="FAQ"!==n.type,i=Z.useCallback(function(t){e(n),t.stopPropagation()},[n]);return r?f.jsx(Uv,{className:"xappw-suggestions__use",onClick:i,icon:Qx}):f.jsx(f.Fragment,{})}}(n)},[n]),v="xappw-suggestions ".concat(e.className||""," ").concat(e.hasWsButton?"xappw-suggestions--with-ws-button":"").trim();return f.jsxs("div",{className:v,children:[(null==l?void 0:l.content)&&f.jsx("div",{className:"xappw-suggestions__answer",children:(h=l.content,h.split("\n").map(function(e,t){return e?f.jsx(qx,{text:e},"line-".concat(t)):f.jsx(ee.Fragment,{},"line-".concat(t))}))}),o&&o.length>0&&f.jsx(qv,{suggestions:o,index:u,className:"xappw-suggestions__groups",itemActions:m,onItemClick:e.onItemClick,onItemHover:c,onSpanClick:p})]})},Zx=function(e){var t,n,r,i=e.isAdmin,o=e.isChatting,a=e.visible,s=e.placeholder,l=e.sendButtonIcon,c=e.sendButtonIconHover,u=e.sendButtonIconDisabled,d=e.footerConfig,p=e.menuConfig,h=e.inputConfig,m=e.hasWsButton,v=e.disabled,g=e.onSubmit,y=Cm(),b=Z.useState(!1),w=b[0],x=b[1],k=Z.useState(),S=k[0],C=k[1],_=Ux(S,Rh(function(e){return e.activeContexts})),E="FOOTER"===((null==p?void 0:p.menuButtonLocation)||"FOOTER"),N=null==p?void 0:p.items,I=null==p?void 0:p.itemsTabIndex,T=null===(t=null==p?void 0:p.button)||void 0===t?void 0:t.tabIndex,j=Z.useMemo(function(){return N||[]},[N]),O=null===(n=null==d?void 0:d.branding)||void 0===n?void 0:n.enabled,P=null===(r=null==d?void 0:d.branding)||void 0===r?void 0:r.text,A=Z.useState(!i),R=A[0],M=A[1],L=Z.useState({text:"",formats:[]}),D=L[0],B=L[1];var z=Z.useCallback(function(e){C(""),B({text:"",formats:[]}),g(e.text)},[g]),U=Z.useCallback(function(e){z(e)},[z]),F=Z.useCallback(function(e){B(e),C(e.text)},[]);return f.jsxs("div",{className:"chat-footer background-footer","aria-label":j.length?"to open menu click a button above the rounded rectangle at the bottom of widget":"","aria-hidden":!1,children:[E&&j.length?f.jsxs(f.Fragment,{children:[w?f.jsx(Vx,{opened:w,tabIndex:I,onItemClick:function(t){x(!1),e.onSubmit(t)},items:j}):f.jsx(f.Fragment,{}),f.jsx("div",{className:"chat-footer__menu-icon",children:f.jsx($x,{tabIndex:T,onToggle:function(){var e=!w;x(e),y(fb({drawer:e}))}})})]}):f.jsx(f.Fragment,{}),f.jsx(Xx,{className:"xappw-chat-footer__suggestions",data:_.suggestions,index:_.index,searchTerms:S,hasWsButton:m,onItemClick:U,onItemUse:F}),i&&o&&a&&f.jsx(Fx,{onAdminJoin:function(e){M(e)}}),f.jsx("div",{style:{pointerEvents:R&&!v?"auto":"none",opacity:R?1:.5},children:f.jsx(Gx,{addClass:"chat-footer__input "+(o&&a?"visible":""),suggestion:_.item,value:D,placeholder:s,sendButtonIcon:l,sendButtonIconHover:c,sendButtonIconDisabled:u,footerConfig:d,inputConfig:h,onSubmit:z,onChange:function(t){B(t),e.onChange(t.text),C(t.text)},onSuggestionCommand:_.execute,onFileUpload:e.onFileUpload})}),O&&P&&f.jsx(Hx,{text:P})]})};var ek=function(e){var t,i,o=e.config,a=e.widgetEnv,s=e.onClose,l=Z.useRef(null),c=Z.useRef(null),u=function(e,t){var n;return e.formConfig?{api:e.formConfig.api,intentId:e.formConfig.intentId,autoGreeting:e.formConfig.autoGreeting}:(null===(n=null==t?void 0:t.connection)||void 0===n?void 0:n.serverUrl)?{api:{url:t.connection.serverUrl,key:t.connection.accountKey},intentId:e.intentId,autoGreeting:e.autoGreeting}:null}(o,a),d=Z.useState("idle"),p=d[0],h=d[1],m=Z.useState(""),v=m[0],g=m[1],y=(null===(i=null===(t=o.formConfig)||void 0===t?void 0:t.api)||void 0===i?void 0:i.key)||(null==a?void 0:a.formWidgetKey),b=Z.useCallback(function(){return n(void 0,void 0,void 0,function(){return r(this,function(e){switch(e.label){case 0:return Wh()?[4,$h(o.preselectChipLabel?{preselectChipLabel:o.preselectChipLabel}:void 0,5,100)]:[3,2];case 1:if(e.sent())return h("success"),s(),[2];e.label=2;case 2:if(!y)return[3,8];h("loading"),e.label=3;case 3:return e.trys.push([3,6,,7]),[4,Hh(y)];case 4:return e.sent(),[4,$h(o.preselectChipLabel?{preselectChipLabel:o.preselectChipLabel}:void 0,30,100)];case 5:return e.sent()?(h("success"),s()):(h("error"),g("Form widget loaded but failed to open. Please try again.")),[3,7];case 6:return e.sent(),h("error"),g("Failed to load form. Please check your connection and try again."),[3,7];case 7:return[3,9];case 8:h("error"),g("Form widget key not configured. Please contact support."),e.label=9;case 9:return[2]}})})},[o.preselectChipLabel,y,s]);Z.useEffect(function(){b()},[b]),Z.useEffect(function(){var e=function(e){"Escape"===e.key&&s()};return document.addEventListener("keydown",e),function(){document.removeEventListener("keydown",e)}},[s]),tg(),Z.useEffect(function(){c.current&&c.current.focus()},[]);var w=Z.useCallback(function(e){e.target===l.current&&s()},[s]),x=Z.useCallback(function(){h("idle"),g(""),b()},[b]);return u||y?f.jsx("div",{className:"xapp-form-modal",ref:l,onClick:w,role:"dialog","aria-modal":"true","aria-label":"Form",children:f.jsxs("div",{className:"xapp-form-modal__content",ref:c,tabIndex:-1,children:[f.jsx("button",{className:"xapp-form-modal__close",onClick:s,"aria-label":"Close form",children:"×"}),f.jsxs("div",{className:"xapp-form-modal__form-container",children:["loading"===p&&f.jsxs("div",{className:"xapp-form-modal__loading",children:[f.jsx("div",{className:"xapp-form-modal__spinner","aria-hidden":"true"}),f.jsx("p",{children:"Loading form..."})]}),"error"===p&&f.jsxs("div",{className:"xapp-form-modal__error",children:[f.jsx("p",{children:v}),f.jsx("button",{className:"xapp-form-modal__retry",onClick:x,children:"Try Again"})]}),"idle"===p&&f.jsxs("div",{className:"xapp-form-modal__loading",children:[f.jsx("div",{className:"xapp-form-modal__spinner","aria-hidden":"true"}),f.jsx("p",{children:"Initializing..."})]})]})]})}):f.jsx("div",{className:"xapp-form-modal",ref:l,onClick:w,role:"dialog","aria-modal":"true","aria-label":"Form",children:f.jsxs("div",{className:"xapp-form-modal__content",ref:c,tabIndex:-1,children:[f.jsx("button",{className:"xapp-form-modal__close",onClick:s,"aria-label":"Close form",children:"×"}),f.jsxs("div",{className:"xapp-form-modal__error",children:[f.jsx("p",{children:"Form configuration not available."}),f.jsx("p",{children:"Please configure the form button with valid settings."})]})]})})},tk=function(e){var t=e.option,n=t.actionUrl?"chat-chip chat-chip-link":"chat-chip";return f.jsx("div",{onClick:function(){return null==e?void 0:e.onClick(t)},className:n,children:f.jsx("span",{children:"object"==typeof t?t.label:t})})},nk=function(e){return f.jsx("div",{className:"chat-chips",children:e.options.map(function(t,n){return f.jsx(tk,{onClick:e.onOptionClick,option:t},n)})})},rk=function(e){var t=cb(),n=Rh(function(e){return e.chips}),r=Cm(),i=Rh(function(e){return e.visuals}),o=wb();return f.jsx("div",{className:"message-list-container__chips ".concat((null==n?void 0:n.length)?"":"message-list-container__chips--empty"),children:f.jsx(nk,{options:n,onOptionClick:function(e){var n,a=Tb(e)&&e.actionUrl;a?o(a,r,i):t(gm(Tb(n=e)?n.label:n,{action:"click",ui:"chip"}))}})})};function ik(e){return"others"===e?"m 80 0 v 240 h -60 c 40 -40 60 -160 60 -240":"m 0 0 v 240 h 60 c -40 -40 -60 -160 -60 -240"}function ok(e){return f.jsx("svg",{className:"chat-text-bubble__tail",xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 80 240",children:f.jsx("path",{d:ik(e),fill:"currentColor"})})}var ak=function(e){var t=e.owner,n=e.onClick,r=Z.useCallback(function(){n&&n()},[n]);return f.jsxs("div",{onClick:r,className:"chat-text-bubble ".concat("mine"===t?"chat-text-bubble--mine":"chat-text-bubble--others"),children:[e.hasTail&&ok(t),e.children]})},sk=function(e){var t=e.onOpenUrl,n=Mh(e.message.user.nick),r=Z.useRef(null),i=Cm(),o=Rh(function(e){return e.visuals}),a=e.message.msg.html,s=Z.useCallback(function(e){if(t){var n=e.target;e.preventDefault(),t(n.href,i,o)}},[t]);return Z.useEffect(function(){if(r.current&&(r.current.innerHTML=a,t)){var e=r.current.querySelectorAll("a");return e.forEach(function(e){e.addEventListener("click",s)}),function(){e.forEach(function(e){e.removeEventListener("click",s)})}}},[r,a,t,s,e.message.timestamp]),f.jsx("div",{className:"chat-msg",children:f.jsx("div",{className:"chat-text-container",children:f.jsxs(ak,{owner:n?"others":"mine",hasTail:n&&!e.sibling,children:[f.jsx("span",{className:"message-sr-only",children:"at "+e.time+(n?" the bot said":" the user said")}),f.jsx("div",{ref:r})]})})})},lk=function(e){var t=e.message,n=e.ctx;if(!n)throw new TypeError("ctx not provided to ".concat(lk.name));var r=n.user,i=t.msg.permissionRequest,o=Mh(e.message.user.nick),a=t.user,s="Deny",l=Z.useCallback(function(e){n.write({type:"msg",user:a,msg:e})},[n,a]),c=Z.useCallback(function(e){n.write({type:"msg",user:r,msg:e})},[n,r]),u=Z.useCallback(function(){n.send({type:"msg",user:void 0,msg:{text:s}})},[n]),d=Z.useCallback(function(e){n.send({type:"permissionGrant",user:a,msg:e})},[a,n]),p=Z.useCallback(function(e,t){d({text:t,location:e?{latitude:e.coords.latitude,longitude:e.coords.longitude}:void 0,permissionRequest:i}),c({text:t});var n=e?null==i?void 0:i.approve:null==i?void 0:i.deny;n&&l(n)},[i,c,l,d]),h=Z.useCallback(function(e){p(void 0,e)},[p]),m=Z.useCallback(function(e){navigator.geolocation&&navigator.geolocation.getCurrentPosition(function(t){p(t,e)},function(){u()})},[u,p]);return i?f.jsxs("div",{className:"chat-msg",children:[f.jsx("span",{className:"message-sr-only",children:"at "+e.time+(o?" the bot said":" the user said")}),f.jsxs("div",{className:"buttons-container",children:[f.jsx(lm,{label:"Allow",addClass:"button",onClick:m}),f.jsx(lm,{label:s,addClass:"button",onClick:h})]})]}):f.jsx(f.Fragment,{})},ck=function(e){var t=e.text,i=Z.useState(!1),o=i[0],a=i[1];return f.jsx("button",{className:"tool-call-item__copy-btn",onClick:function(e){return n(void 0,void 0,void 0,function(){var n;return r(this,function(r){switch(r.label){case 0:e.stopPropagation(),r.label=1;case 1:return r.trys.push([1,3,,4]),[4,navigator.clipboard.writeText(t)];case 2:return r.sent(),a(!0),setTimeout(function(){return a(!1)},1500),[3,4];case 3:return r.sent(),(n=document.createElement("textarea")).value=t,document.body.appendChild(n),n.select(),document.execCommand("copy"),document.body.removeChild(n),a(!0),setTimeout(function(){return a(!1)},1500),[3,4];case 4:return[2]}})})},title:"Copy to clipboard",children:o?"✓":"⧉"})},uk=function(e){var t,n,r;return null!==(r=null!==(n=null!==(t=e.label)&&void 0!==t?t:e.displayName)&&void 0!==n?n:e.name)&&void 0!==r?r:"Working..."},dk=function(e){var t=e.toolCall,n=uk(t);return f.jsxs("div",{className:"tool-progress-item ".concat(t.isExecuting?"tool-progress-item--executing":""," ").concat(t.error?"tool-progress-item--error":""),children:[f.jsx("span",{className:"tool-progress-item__icon",children:t.isExecuting?f.jsx("span",{className:"tool-progress-item__spinner","aria-label":"executing"}):t.error?f.jsx("span",{className:"tool-progress-item__status tool-progress-item__status--error",children:"!"}):f.jsx("span",{className:"tool-progress-item__status tool-progress-item__status--success",children:"✓"})}),f.jsx("span",{className:"tool-progress-item__label",children:n})]})},fk=function(e){var t=e.toolCall,n=Z.useState(!1),r=n[0],i=n[1],o=function(e){if(null==e)return"";try{if("string"==typeof e)try{var t=JSON.parse(e);return JSON.stringify(t,null,2)}catch(t){return e}return JSON.stringify(e,null,2)}catch(t){return String(e)}},a=uk(t),s=t.endTime?"".concat(((t.endTime-t.startTime)/1e3).toFixed(2),"s"):null,l=void 0!==t.input&&null!==t.input,c=void 0!==t.result&&null!==t.result,u=!!t.error;return f.jsxs("div",{className:"tool-call-item ".concat(t.isExecuting?"tool-call-item--executing":""),children:[f.jsxs("button",{className:"tool-call-item__header",onClick:function(){return i(!r)},"aria-expanded":r,children:[f.jsx("span",{className:"tool-call-item__icon",children:t.isExecuting?f.jsx("span",{className:"tool-call-item__spinner","aria-label":"executing"}):t.error?f.jsx("span",{className:"tool-call-item__status tool-call-item__status--error",children:"!"}):f.jsx("span",{className:"tool-call-item__status tool-call-item__status--success",children:"✓"})}),f.jsxs("span",{className:"tool-call-item__info",children:[f.jsx("span",{className:"tool-call-item__label",children:a}),f.jsx("span",{className:"tool-call-item__name",children:t.name})]}),s&&f.jsx("span",{className:"tool-call-item__duration",children:s}),f.jsx("span",{className:"tool-call-item__chevron ".concat(r?"tool-call-item__chevron--expanded":""),children:"▾"})]}),r&&f.jsxs("div",{className:"tool-call-item__content",children:[l&&f.jsxs("div",{className:"tool-call-item__section",children:[f.jsxs("div",{className:"tool-call-item__section-header",children:[f.jsx("span",{className:"tool-call-item__section-label",children:"Input"}),f.jsx(ck,{text:o(t.input)})]}),f.jsx("pre",{className:"tool-call-item__code",children:o(t.input)})]}),c&&f.jsxs("div",{className:"tool-call-item__section",children:[f.jsxs("div",{className:"tool-call-item__section-header",children:[f.jsx("span",{className:"tool-call-item__section-label",children:"Output"}),f.jsx(ck,{text:o(t.result)})]}),f.jsx("pre",{className:"tool-call-item__code",children:o(t.result)})]}),u&&f.jsxs("div",{className:"tool-call-item__section",children:[f.jsxs("div",{className:"tool-call-item__section-header",children:[f.jsx("span",{className:"tool-call-item__section-label tool-call-item__section-label--error",children:"Error"}),f.jsx(ck,{text:t.error||""})]}),f.jsx("pre",{className:"tool-call-item__code tool-call-item__code--error",children:t.error})]}),!l&&!c&&!u&&f.jsx("div",{className:"tool-call-item__empty",children:"No data available"})]})]})},pk=function(e){var t=e.toolCalls,n=e.debugMode,r=void 0!==n&&n;if(!t||0===t.length)return null;if(r)return f.jsxs("div",{className:"tool-call-display",children:[f.jsxs("div",{className:"tool-call-display__header",children:[f.jsx("span",{className:"tool-call-display__icon",children:"⚙"}),f.jsxs("span",{className:"tool-call-display__title",children:["Tool Calls (",t.length,")"]})]}),f.jsx("div",{className:"tool-call-display__list",children:t.map(function(e,t){return f.jsx(fk,{toolCall:e},"".concat(e.name,"-").concat(e.startTime,"-").concat(t))})})]});var i=t.filter(function(e){return!e.hidden});return 0===i.length?null:f.jsx("div",{className:"tool-progress-display",children:i.map(function(e,t){return f.jsx(dk,{toolCall:e},"".concat(e.name,"-").concat(e.startTime,"-").concat(t))})})};function hk(e){return e.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;")}function mk(e){return hk(e).replace(/\*\*(.+?)\*\*/g,"<strong>$1</strong>").replace(/__(.+?)__/g,"<strong>$1</strong>").replace(/\*([^*]+?)\*/g,"<em>$1</em>").replace(/_([^_]+?)_/g,"<em>$1</em>")}function vk(e){if(!e)return"";var t=[],n=e.replace(/```([^\s`]*)\r?\n([\s\S]*?)```/g,function(e,n,r){var i=hk(r.replace(/\n$/,"")),o=n?' data-language="'.concat(hk(n),'"'):"";return t.push("<pre><code".concat(o,">").concat(i,"</code></pre>")),"%%CODEBLOCK".concat(t.length-1,"%%")}),r=[];n=n.replace(/(?:^|\n)(\|.+\|)\n(\|[\s:|-]+\|)\n((?:\|.+\|\n?)+)/g,function(e,t,n,i){return r.push(function(e,t,n){var r=function(e){return e.split("|").slice(1,-1).map(function(e){return mk(e.trim())})},i=t.split("|").slice(1,-1).map(function(e){return e.trim()}).map(function(e){return e.startsWith(":")&&e.endsWith(":")?"center":e.endsWith(":")?"right":"left"}),o=r(e).map(function(e,t){return'<th scope="col" style="text-align:'.concat(i[t]||"left",'">').concat(e,"</th>")}).join(""),a=n.trim().split("\n").filter(function(e){return""!==e.trim()}).map(function(e){return"<tr>"+r(e).map(function(e,t){return'<td style="text-align:'.concat(i[t]||"left",'">').concat(e,"</td>")}).join("")+"</tr>"}).join("");return'<div style="overflow-x:auto"><table><thead><tr>'.concat(o,"</tr></thead><tbody>").concat(a,"</tbody></table></div>")}(t,n,i)),"\n%%TABLE".concat(r.length-1,"%%\n")});var i=[];n=n.replace(/`([^`\n]+)`/g,function(e,t){return i.push("<code>".concat(hk(t),"</code>")),"%%INLINECODE".concat(i.length-1,"%%")});var o=[];return n=n.replace(/\[([^\]]+)\]\(([^)]+)\)/g,function(e,t,n){return o.push('<a href="'.concat(hk(n),'" target="_blank" rel="noopener noreferrer">').concat(mk(t),"</a>")),"%%LINK".concat(o.length-1,"%%")}),n=(n=(n=(n=n.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/^### (.+)$/gm,"<h4>$1</h4>").replace(/^## (.+)$/gm,"<h3>$1</h3>").replace(/^# (.+)$/gm,"<h2>$1</h2>").replace(/\*\*(.+?)\*\*/g,"<strong>$1</strong>").replace(/__(.+?)__/g,"<strong>$1</strong>").replace(/\*([^*]+?)\*/g,"<em>$1</em>").replace(/_([^_]+?)_/g,"<em>$1</em>").replace(/^[-*] (.+)$/gm,"<li>$1</li>").replace(/\n/g,"<br>")).replace(/(<li>.*?<\/li>)(<br>)?/g,"$1")).replace(/(<li>.*?<\/li>)+/g,"<ul>$&</ul>")).replace(/<ul>(.*?)<\/ul>/g,function(e){return e.replace(/<br>/g,"")}),r.forEach(function(e,t){n=n.replace(new RegExp("(?:<br>)?%%TABLE".concat(t,"%%(?:<br>)?")),function(){return e})}),t.forEach(function(e,t){n=n.replace(new RegExp("(?:<br>)?%%CODEBLOCK".concat(t,"%%(?:<br>)?")),function(){return e})}),i.forEach(function(e,t){n=n.replace("%%INLINECODE".concat(t,"%%"),function(){return e})}),o.forEach(function(e,t){n=n.replace("%%LINK".concat(t,"%%"),function(){return e})}),n}var gk=function(e){var t,n=e.message,r=new Date(n.timestamp),i=r.getHours()+":"+r.getMinutes(),o=Mh(null===(t=e.message.user)||void 0===t?void 0:t.nick),a=n.isStreaming,s=Z.useMemo(function(){return o&&n.msg.text?vk(n.msg.text):null},[o,n.msg.text]),l=n.wasStreamed,c=o&&!e.sibling&&!a&&!l,u=e.toolCalls&&e.toolCalls.length>0,d=e.onLinkClick;return f.jsxs("div",{className:"chat-msg".concat(a?" chat-msg--streaming":""),children:[u&&f.jsx(pk,{toolCalls:e.toolCalls,debugMode:e.debugMode}),f.jsx("div",{className:"chat-text-container",children:f.jsxs(ak,{owner:o?"others":"mine",hasTail:c,children:[f.jsx("span",{className:"message-sr-only",children:"at "+i+(o?a?" the bot is typing":" the bot said":" the user said")}),s?f.jsx("span",{className:"chat-msg__content",onClick:function(e){var t,n;if(!(!d||e.metaKey||e.ctrlKey||e.shiftKey||e.altKey)){var r=null===(n=(t=e.target).closest)||void 0===n?void 0:n.call(t,"a");r&&e.currentTarget.contains(r)&&(e.preventDefault(),d(r.href))}},dangerouslySetInnerHTML:{__html:s}}):f.jsx("span",{className:"chat-msg__content",children:n.msg.text}),a&&f.jsx("span",{className:"streaming-cursor","aria-hidden":"true"})]})})]})},yk=function(e){var t=e.display,n=Cm(),r=Rh(function(e){return e.visuals}),i=wb();return f.jsx("div",{className:"chat-schedule-button-container",children:f.jsxs("button",{className:"chat-schedule-button",onClick:function(){i(tm,n,r)},children:[f.jsx("i",{className:"fa fa-lg fa-calendar"}),f.jsx("span",{children:t.label||"Schedule Now!"})]})})},bk=function(e){var t=e.sources,n=e.prefix,r=void 0===n?"Sources:":n,i=e.onSourceClick;if(!t||0===t.length)return null;return f.jsxs("div",{className:"source-links",children:[r&&f.jsx("span",{className:"source-links__prefix",children:r}),f.jsx("span",{className:"source-links__list",children:t.map(function(e,n){return f.jsxs("span",{className:"source-links__item",children:[f.jsx("a",{href:e.url,target:!1!==e.newTab?"_blank":"_self",rel:!1!==e.newTab?"noopener noreferrer":void 0,className:"source-links__link",onClick:function(t){return function(e,t){i&&(t.preventDefault(),i(e))}(e,t)},title:e.url,children:e.title}),n<t.length-1&&f.jsx("span",{className:"source-links__separator",children:"·"})]},n)})})]})};var wk,xk=["text","html","card","list"],kk=function(e){var t,n,r,i,o=e.messageMiddleware||aw,a=Z.useContext(nm),s=e.middlewareContext,l=e.agent,c=Cm(),u=Rh(function(e){return e.visuals}),d=(null===(t=null==a?void 0:a.env)||void 0===t?void 0:t.urls)&&(null==s?void 0:s.openUrl)?function(e){return s.openUrl(e,c,u)}:void 0,p=null===(n=e.agents)||void 0===n?void 0:n[e.message.user.nick],h=(null==p?void 0:p.hideUserInfo)||!1;var m,v=e.message.isStreaming,g=!(!(null===(r=e.message.msg)||void 0===r?void 0:r.text)&&!(null===(i=e.message.msg)||void 0===i?void 0:i.html)),y=!v&&g;return f.jsx("div",{className:"chat-msg-container-wrapper ".concat(Mh(e.message.user.nick)?"agent":"visitor"," ").concat(e.sibling?"sibling":""),children:f.jsxs("div",{className:"chat-msg-container ".concat((m=e.message,Mh(m.user.nick)?"agent":"visitor")),children:[function(){var t,n,r,i,c,u,p,m,v,g,y,b,w,x,k,S,C,_=e.message.msg;if("chat.msg"===e.message.type){var E=xk.find(function(e){return!!_[e]}),N=e.message.isStreaming,I=e.message.wasStreamed,T=e.message.toolCalls,j=T&&T.length>0,O=null!==(i=null===(r=null===(n=null===(t=null==a?void 0:a.env)||void 0===t?void 0:t.connection)||void 0===n?void 0:n.mcp)||void 0===r?void 0:r.debugMode)&&void 0!==i&&i,P=j&&!_.text;return f.jsxs(f.Fragment,{children:[P&&f.jsx(mm,{showAvatar:!0,user:l,avatarPosition:null===(p=null===(u=null===(c=null==a?void 0:a.env)||void 0===c?void 0:c.theme)||void 0===u?void 0:u.messages)||void 0===p?void 0:p.avatarPosition,hideUserInfo:h,isStreaming:!0,children:f.jsx("div",{className:"chat-msg",children:f.jsx(pk,{toolCalls:T,debugMode:O})})}),_.text&&f.jsx(mm,{showAvatar:"text"===E,user:l,avatarPosition:null===(g=null===(v=null===(m=null==a?void 0:a.env)||void 0===m?void 0:m.theme)||void 0===v?void 0:v.messages)||void 0===g?void 0:g.avatarPosition,hideUserInfo:h,isStreaming:N||I,children:f.jsx(gk,{message:e.message,sibling:e.sibling,user:l,toolCalls:j?T:void 0,debugMode:O,onLinkClick:d})}),_.html&&f.jsx(mm,{showAvatar:"html"===E,user:l,avatarPosition:null===(w=null===(b=null===(y=null==a?void 0:a.env)||void 0===y?void 0:y.theme)||void 0===b?void 0:b.messages)||void 0===w?void 0:w.avatarPosition,hideUserInfo:h,children:f.jsx(sk,{message:e.message,sibling:e.sibling,onOpenUrl:null===(x=e.middlewareContext)||void 0===x?void 0:x.openUrl})}),_.displays&&o&&_.displays.map(function(t,n){if("ScheduleButton"===t.type)return f.jsx(yk,{minimizeOnClick:e.minimizeOnClick,display:t},n);var r=o;return f.jsx(r,{msg:t,ctx:e.middlewareContext},n)}),_.permissionRequest&&s&&f.jsx(mm,{showAvatar:"permissionRequest"===E,user:l,avatarPosition:null===(C=null===(S=null===(k=null==a?void 0:a.env)||void 0===k?void 0:k.theme)||void 0===S?void 0:S.messages)||void 0===C?void 0:C.avatarPosition,hideUserInfo:h,children:f.jsx(lk,{message:e.message,sibling:e.sibling,ctx:s})})]})}return f.jsx(f.Fragment,{})}(),y&&function(){var t,n=e.message.timestamp,r=function(e){var t=new Date,n=Math.floor((t.valueOf()-e.valueOf())/1e3);if(n<1)return"now";if(n<60)return"".concat(n," seconds ago");var r=Math.floor(n/60);if(r<60)return"".concat(r," minutes ago");var i=Math.floor(r/60);return i<24?"".concat(i," hours ago"):e.toLocaleString()}(new Date(n)),i=null===(t=e.message.msg)||void 0===t?void 0:t.sources,o=i&&i.length>0,a=Mh(e.message.user.nick);return f.jsxs("div",{className:"chat-msg-footer ".concat(a?"agent":"visitor"),children:[f.jsx("span",{className:"chat-msg-timestamp",children:r}),o&&f.jsx(bk,{sources:i.map(function(e){return{title:e.title,url:e.url,newTab:e.newTab}})})]})}()]})})},Sk=function(e){return f.jsxs("div",{className:"card-container ".concat(e.addClass),children:[(t="string"==typeof e.icon,f.jsx("div",{className:"card-container__icon",children:!t&&e.icon})),f.jsxs("div",{className:"card-container__content ".concat(e.contentAddClass),children:[f.jsx("div",{className:"card-container__title",children:e.title}),e.children]})]});var t},Ck=function(e){var t=e.agent,n=void 0===t?{}:t,r=e.hasRating,i=void 0!==r&&r,o=e.shouldDisplay,a=void 0===o||o,s=e.onRate,l=void 0===s?function(){}:s,c=Z.useCallback(function(){l("bad")},[l]),u=Z.useCallback(function(){l("good")},[l]),d=Z.useCallback(function(){l(void 0)},[l]);return a?i?f.jsxs(Sk,{title:"Chat Rating",addClass:"chat-rating-card",children:["You have rated the chat service.",f.jsx("div",{className:"buttons-container",children:f.jsx(lm,{addClass:"button button-rate-again",label:"Rate again",onClick:d})})]}):f.jsxs(Sk,{title:"Chat Rating",addClass:"chat-rating-card",children:[n.displayName," has requested you to rate the chat service.",f.jsxs("div",{className:"buttons-container",children:[f.jsx(lm,{addClass:"button button-rate-bad",label:"Rate Bad",onClick:c}),f.jsx(lm,{addClass:"button button-rate-good",label:"Rate Good",onClick:u})]})]}):null},_k=function(e){var t=cb(),n=Z.useCallback(function(e){t(function(e){return function(t){return function(){t.sendChatRating(e)}}}(e))},[t]);return f.jsxs(f.Fragment,{children:[f.jsx("span",{className:"message-sr-only",children:"at "+e.time+" system message"}),f.jsx(Ck,{agent:e.agent,hasRating:e.hasRating,shouldDisplay:e.shouldDisplay,onRate:n})]})};function Ek(e,t){var n,r;switch(void 0===t&&(t="ssml"),typeof e){case"string":n=e;break;case"number":n="".concat(e)}return Nk(e)&&(n=Ak(e,t)),(r=e)&&(r.start||r.end)&&(n=function(e,t){void 0===t&&(t="ssml");if(!e)return"";var n=e.start,r=e.end,i="".concat(Ak(n,t)," to ").concat(Ak(r,t));o=Ik(n.date),a=Ik(r.date),o.getFullYear()===a.getFullYear()&&o.getMonth()===a.getMonth()&&o.getDate()===a.getDate()&&(i="on ".concat(Ak({date:n.date},t)," from ").concat(Ak({time:n.time},t)," to ").concat(Ak({time:r.time},t)));var o,a;return i}(e,t)),function(e){return!!e&&"object"==typeof e&&"number"==typeof e.amount&&"string"==typeof e.format}(e)&&(n=function(e,t){void 0===t&&(t="ssml");if(!e)return"";var n=e.amount>1,r="ssml"===t?'<say-as interpret-as="cardinal">'.concat(e.amount,"</say-as>"):e.amount,i=Rk[e.format],o=e.format;Object.keys(Rk).forEach(function(e){Rk[e]===i&&e.length>o.length&&!e.endsWith("s")&&(o=e)});var a=n?"".concat(o,"s"):o;return"".concat(r," ").concat(a)}(e,t)),Array.isArray(e)&&(n=function(e,t){void 0===t&&(t=wk.or);var n=wk[t];if(!e||0===e.length)return"";if(1===e.length)return e[0];if(e.length>=2){var r=e.length-2;return e.reduce(function(e,t,i){return e+=t,i<r?e+=", ":i===r&&(e+=" ".concat(n," ")),e},"")}}(e,wk.and)),n}function Nk(e){return!(!e||!e.date&&!e.time)}function Ik(e){var t=String(e).split("-").map(Number),n=t[0],r=t[1],i=t[2];return new Date(n,r-1,i)}function Tk(e){return e<10?"0".concat(e):String(e)}function jk(e){if(isNaN(e.getTime()))throw new RangeError("Invalid time value")}function Ok(e){return jk(e),"".concat(e.getFullYear(),"-").concat(Tk(e.getMonth()+1),"-").concat(Tk(e.getDate()))}function Pk(e){jk(e);var t=e.getHours();return"".concat(t%12==0?12:t%12,":").concat(Tk(e.getMinutes())," ").concat(t<12?"AM":"PM")}function Ak(e,n){if(void 0===n&&(n="ssml"),!e)return"";var r=t({},e);r.date||(r.date=Ok(new Date));var i=new Date(Date.parse(function(e){if("object"!=typeof e)return"";var t="";try{if(Nk(e)){var n=e.date?Ok(Ik(e.date)):void 0,r=e.time;t="".concat(n||"").concat(n&&r?"T":"").concat(r||"")}else{var i=e.start,o=e.end;if(i){n=i.date?Ok(Ik(i.date)):void 0,r=i.time;t="".concat(n||"").concat(n&&r?"T":"").concat(r||"")}if(i&&o&&(t+=" --\x3e "),o){n=o.date?Ok(Ik(o.date)):void 0,r=o.time;t+="".concat(n||"").concat(n&&r?"T":"").concat(r||"")}}}catch(e){console.error(e)}return t}(r))),o="";return e.date&&(o+="ssml"===n?'<say-as interpret-as="date" format="ymd">'.concat(Ok(i),"</say-as>"):"".concat(function(e){return jk(e),"".concat(e.getMonth()+1,"-").concat(e.getDate(),"-").concat(e.getFullYear())}(i))),e.time&&("ssml"===n?o+='<say-as interpret-as="time">'.concat(Pk(i),"</say-as>"):(o.length>0&&(o+=" "),o+="".concat(Pk(i)))),o}!function(e){e[e.or=0]="or",e[e.and=1]="and"}(wk||(wk={}));var Rk={ms:1,millisecond:1,milliseconds:1,s:1e3,second:1e3,seconds:1e3,m:6e4,minute:6e4,minutes:6e4,h:36e5,hour:36e5,hours:36e5,d:864e5,day:864e5,days:864e5,w:6048e5,week:6048e5,weeks:6048e5,M:2628e6,month:2628e6,months:2628e6,Q:7776e6,quarter:7776e6,quarters:7776e6,y:3154e7,years:3154e7,year:3154e7};var Mk=/\$\{([^\\}]*(?:\\.[^\\}]*)*)\}/g;function Lk(e,t,n,r){for(var i,o=e,a=new RegExp(Mk);null!==(i=a.exec(e));){var s=void 0,l=t[i[1].trim()];l&&(s=Ek(l.value,n)),(s||r)&&(o=o.replace(i[0],s))}return o}var Dk=function(e){var t=e.agents,n=e.text,r=e.delay,i=e.time,o=Z.useState(r),a=o[0],s=o[1],l=Object.values(t).filter(function(e){return e.requestFailed});Z.useEffect(function(){if(0!==r)var e=r,t=setInterval(function(){e--,s(e),0===e&&clearInterval(t)},1e3);else s(5)},[r]);var c=Z.useMemo(function(){return{sec:{name:"sec",value:a}}},[a]),u=Z.useMemo(function(){return function(e,t,n){if(!e||!t)return e;var r=e;if("string"==typeof r)r=Lk(r,t,"displayText",n);else{var i=r;["ssml","displayText"].forEach(function(e){i[e]&&(i[e]=Lk(i[e],t,e,n))})}return r}(n,c)},[n,c]);return 0===a?f.jsx(f.Fragment,{}):f.jsx(f.Fragment,{children:l.map(function(e){var t,n;return f.jsx("div",{className:"chat-msg-container-wrapper",children:f.jsx("div",{className:"chat-msg-container agent",children:f.jsx(mm,{user:null==e?void 0:e.user,showAvatar:!0,children:f.jsx("div",{className:"chat-msg",children:f.jsxs(ak,{owner:"others",hasTail:!0,children:[f.jsx("span",{className:"message-sr-only",children:"at "+i+" the bot said"}),f.jsx("span",{children:"object"==typeof u?u.displayText:u})]})})})},null===(t=null==e?void 0:e.user)||void 0===t?void 0:t.nick)},"failure-msg-".concat(null===(n=null==e?void 0:e.user)||void 0===n?void 0:n.nick))})})},Bk=function(e){return f.jsx("svg",{className:"message-svg",width:"16",height:"12",viewBox:"0 0 16 12",children:f.jsx("path",{d:"M14.4 0H1.6C.72 0 .008.675.008 1.5L0 10.5c0 .825.72 1.5 1.6 1.5h12.8c.88 0 1.6-.675 1.6-1.5v-9c0-.825-.72-1.5-1.6-1.5zm0 3L8 6.75 1.6 3V1.5L8 5.25l6.4-3.75V3z",fill:"#424242",fillRule:"evenodd"})})},zk=function(e){var t=Z.useRef(null),n=Z.useRef(null),r=Z.useRef(null),i=Z.useRef(null),o=Z.useState(!1),a=o[0],s=o[1];function l(){var e,t,r;(null===(e=n.current)||void 0===e?void 0:e.validity.patternMismatch)?null===(t=n.current)||void 0===t||t.setCustomValidity("This doesn't look like an email!"):null===(r=n.current)||void 0===r||r.setCustomValidity("")}function c(o){var a,l,c,u,d;o.preventDefault(),(null===(a=i.current)||void 0===a?void 0:a.checkValidity())?(e.onSubmit({name:null===(c=t.current)||void 0===c?void 0:c.value,email:null===(u=n.current)||void 0===u?void 0:u.value,message:null===(d=r.current)||void 0===d?void 0:d.value}),s(!0)):null===(l=i.current)||void 0===l||l.reportValidity()}function u(){s(!1)}return f.jsx(Sk,{title:e.title,addClass:"offline-card",contentAddClass:a?"sent":"",icon:f.jsx(Bk,{}),children:a?f.jsxs("div",{className:"message-form--sent",children:["Your message has been sent. We will get back to you as soon as possible.",f.jsx(lm,{addClass:"button-resend",label:"Send another",onClick:u})]},"sent"):f.jsxs("form",{ref:i,className:"message-form",onSubmit:c,children:[f.jsxs("div",{className:"content",children:[f.jsxs("div",{className:"section",children:[f.jsx("label",{className:"label",children:"Name"}),f.jsx("input",{ref:t,maxLength:255})]}),f.jsxs("div",{className:"section",children:[f.jsx("label",{className:"label",children:"Email"}),f.jsx("input",{ref:n,onChange:l,type:"email",required:!0,pattern:"^\\w+([\\.-]?\\w+)*@\\w+([\\.-]?\\w+)*(\\.\\w{2,3})+$"})]}),f.jsxs("div",{className:"section",children:[f.jsx("label",{className:"label",children:"Message"}),f.jsx("textarea",{required:!0,ref:r})]})]}),f.jsx("div",{className:"button-container",children:f.jsx(lm,{type:"submit",addClass:"message-form__submit",label:"Send"})})]},"not-sent")})},Uk=function(e){return f.jsx(zk,{title:"Offline message card title",onSubmit:e.onSubmit})},Fk=function(e){var t=cb(),n=Z.useCallback(function(e){t(function(e){return function(t){return function(){t.sendOfflineMsg(e,function(e){e&&Yh(e)})}}}(e))},[t]);return f.jsxs(f.Fragment,{children:[f.jsx("span",{className:"message-sr-only",children:"at "+e.time+" system message"}),f.jsx(Uk,{onSubmit:n})]})},qk=function(e){var t=Z.useState(!1),n=t[0],r=t[1],i=e.onSubmit,o=Z.useCallback(function(e){i(e),r(!0)},[i]);return f.jsx(f.Fragment,{children:!n&&f.jsx(zk,{title:"Introduce yourself!",onSubmit:o})})},Hk=function(e){var t=cb(),n=Rh(function(e){return e.sessionId}),r=Z.useCallback(function(e){e.message&&(t(bm({displayName:e.name,email:e.email},n)),t(gm(e.message)))},[t,n]);return f.jsxs(f.Fragment,{children:[f.jsx("span",{className:"message-sr-only",children:"at "+e.time+" system message"}),f.jsx(qk,{onSubmit:r})]})},Wk=function(e){var t=e.position,n=void 0===t?0:t;return n<=0?null:f.jsx("div",{className:"system-msg-container",children:f.jsxs("span",{className:"system-msg",children:["Queue position: ",n]})})};function Vk(e){switch(e.type){case"chat.memberjoin":return e.message||"".concat(e.user.displayName||"Bot"," has joined the chat");case"chat.memberleave":return e.message||"".concat(e.user.displayName||"Bot"," has left the chat");case"chat.systemmessage":return e.message;case"chat.rating":if(e.newRating){var t=(n=e.newRating)[0].toUpperCase()+n.slice(1);return"You have rated the chat service ".concat(t)}return"You have removed the chat rating";default:return JSON.stringify(e)}var n}var $k=function(e){var t;if(function(e){var t;return null===(t=e.nick)||void 0===t?void 0:t.endsWith(Pg)}(e.message.user))return null;var n=e.message,r=function(e){return"chat.memberjoin"===e.type&&e.showDivider||"chat.memberleave"===e.type&&e.showDivider}(n),i=null===(t=n.user)||void 0===t?void 0:t.avatarPath;return f.jsxs("div",{className:"system-msg-container",children:[r&&i&&f.jsxs("div",{className:"system-msg-divider",children:[f.jsx("div",{className:"divider-line"}),f.jsx("div",{className:"divider-avatar",children:f.jsx("img",{src:i,alt:"".concat(n.user.displayName||"User","'s avatar")})}),f.jsx("div",{className:"divider-line"})]}),f.jsx("span",{className:"message-sr-only",children:"at "+e.time+" system message"}),f.jsx("span",{className:"system-msg",children:Vk(e.message)})]})};var Kk=function(e){return f.jsxs("div",{className:"typing-indicator",children:[f.jsx("div",{className:"typing-indicator-part"}),f.jsx("div",{className:"typing-indicator-part"}),f.jsx("div",{className:"typing-indicator-part"})]})},Qk=function(e){var t=Object.values(e.agents).filter(function(e){return e.typing});return f.jsx(f.Fragment,{children:t.map(function(t,n){var r,i,o=(null===(r=t.user)||void 0===r?void 0:r.nick)||"".concat(n),a=(null===(i=t.user)||void 0===i?void 0:i.displayName)||"Somebody";return f.jsx("span",{children:e.textTypingStatusEnabled?f.jsxs("div",{className:"chat-msg-agent-typing",children:[a," is typing"]},"typing-status-".concat(o)):f.jsx("div",{className:"chat-msg-container-wrapper",children:f.jsx("div",{className:"chat-msg-container agent chat-typing-progress",children:f.jsx(mm,{user:t.user,showAvatar:!0,children:f.jsx("div",{className:"chat-msg",children:f.jsx(ak,{owner:"others",hasTail:!0,children:f.jsx(Kk,{})})})})},o)},"typing-status-".concat(o))},"typing-status-".concat(n))})})},Jk=function(e){e.visible;var n=e.messages,r=void 0===n?[]:n,i=e.agents,o=void 0===i?{}:i;e.isOffline,e.isChatting;var a=e.queuePosition,s=void 0===a?0:a,l=e.lastRatingRequestTimestamp,c=void 0===l?0:l,u=e.hasRating,d=void 0!==u&&u;e.visitorId;var p=e.messageMiddleware,h=e.textTypingStatusEnabled,m=e.agent,v=e.hasWsButton,g=e.disableAutoScroll,y=void 0!==g&&g,b=e.onSend,w=void 0===b?function(){return Promise.resolve()}:b,x=e.onWrite,k=void 0===x?function(){return Promise.resolve()}:x,S=e.onOpenUrl,C=void 0===S?function(){}:S,_=e.minimizeOnClick,E=void 0===_?function(){}:_;e.children;var N=Z.useRef(null),I=Z.useRef(null),T=Z.useRef(v),j=Z.useCallback(function(){if(!I.current)return!0;var e=I.current,t=e.scrollTop,n=e.scrollHeight,r=e.clientHeight;return Math.abs(n-r-t)<10},[]),O=Z.useCallback(function(e){void 0===e&&(e="smooth");var t=I.current;t&&("function"!=typeof t.scrollTo?t.scrollTop=t.scrollHeight:t.scrollTo({top:t.scrollHeight,behavior:e}))},[]);Z.useEffect(function(){y||O("smooth")},[r,o,O,y]),Z.useEffect(function(){if(!y){var e=T.current,t=v;if(T.current=t,e&&!t)if(j()){var n=setTimeout(function(){O("smooth")},350);return function(){return clearTimeout(n)}}}},[v,j,O,y]);var P=Z.useCallback(function(e){w(e),y||O("smooth")},[w,y,O]),A=Z.useCallback(function(e){k(e),y||O("smooth")},[k,y,O]),R=Z.useMemo(function(){return new Xb({send:P,write:A,openUrl:C})},[P,A,C]),M=new Date,L=M.getHours()+":"+M.getMinutes();function D(e,n){var r,i,a,s;switch((null===(i=null===(r=e.user)||void 0===r?void 0:r.nick)||void 0===i?void 0:i.startsWith("visitor:"))?s=e.user:(s=(null===(a=o[e.user.nick])||void 0===a?void 0:a.user)||m)||(Yh('Could not get a user from agents list with nick: "'.concat(e.user.nick,'"')),s=e.user),e.type){case"chat.file":case"chat.msg":return f.jsx(kk,{message:e,sibling:n,agent:s,messageMiddleware:p,middlewareContext:R.resolve(s),minimizeOnClick:E},"cm-".concat(e.type,"-").concat(e.timestamp));case"chat.failureMsg":return f.jsx(Dk,t({agents:o,time:L},e.failureMsg),"fm-".concat(e.type,"-").concat(e.timestamp));case"chat.memberjoin":case"chat.memberleave":case"chat.systemmessage":case"chat.rating":case"chat.typing":return f.jsx($k,{time:L,message:e},"sm-".concat(e.type,"-").concat(e.timestamp));case"chat.request.rating":return f.jsx(_k,{agent:s,hasRating:d,time:L,shouldDisplay:e.timestamp===c},"cr-".concat(e.type,"-").concat(e.timestamp));case"chat.offline":return f.jsx(Fk,{time:L},"offline-".concat(e.timestamp));case"chat.prechat":return f.jsx(Hk,{time:L},"prechat");default:return f.jsxs("span",{children:[f.jsx("span",{className:"message-sr-only",children:"at "+L+" system message"}),f.jsxs("div",{"data-testid":"unhandled-message",children:["Unhandled message: ",JSON.stringify(e)]},"uhm-".concat(e.timestamp))]},"default-".concat(e.timestamp))}}return f.jsxs("div",{className:"message-list-container",ref:I,children:[f.jsxs("div",{className:"message-list-container__msgs",children:[function(){for(var e=-1,t=r.length-1;t>0;t--)if("chat.msg"===r[t].type){e=t;break}return r.map(function(t,n){var i,o,a=!1;if(["chat.file","chat.msg","chat.memberjoin","chat.memberleave","chat.rating","chat.request.rating","chat.offline","chat.prechat"].includes(t.type)&&!(null===(o=null===(i=t.user)||void 0===i?void 0:i.nick)||void 0===o?void 0:o.endsWith(Pg)))if(0===n||n===r.length-1||n===e)a=!0;else{var s=r[n-1];t.timestamp&&s.timestamp&&(a=t.timestamp-s.timestamp>3e5)}0===n&&"chat.memberjoin"===t.type&&(a=!1);var l=a?new Date(t.timestamp).toLocaleString():void 0;return f.jsxs("span",{children:[a&&f.jsx("div",{className:"ts-msg-container",children:f.jsx("span",{className:"ts-msg",children:l})}),D(t,!1)]},"message-list-render-all-".concat(n))})}(),f.jsx("div",{ref:N,style:{float:"left",clear:"both"}}),f.jsx(Wk,{position:s}),f.jsx(Qk,{agents:o,textTypingStatusEnabled:h})]}),f.jsx(rk,{})]})},Yk=function(){return f.jsxs("div",{className:"server-offline",children:[f.jsx("h2",{children:"We can't reach the chat right now"}),f.jsx("h3",{children:"Check your connection and try again in a moment."})]})},Gk=function(e){var t=e.children,n=e.className,r=void 0===n?"":n;return f.jsx("div",{className:"button-group ".concat(r),children:t})},Xk=function(e){return f.jsx("div",{id:"xapp-widget-close","aria-label":"close widget","aria-hidden":!1,tabIndex:e.tabIndex?Number(e.tabIndex):0,className:"cancel-button",onClick:e.onClick})};function Zk(e){return Tb(e)?e.actionUrl?"[".concat(e.label,"](").concat(e.actionUrl,")"):e.label:e}var eS=function(e){var t=Rh(function(e){return e.chats});return f.jsx("div",{id:"xapp-widget-export","aria-label":"export conversation","aria-hidden":!1,tabIndex:e.tabIndex?Number(e.tabIndex):0,className:"export-button",onClick:function(){return n(void 0,void 0,void 0,function(){var e,n;return r(this,function(r){switch(r.label){case 0:e=function(e){return e.filter(jw).map(function(e){var t,n,r,i=(null===(t=e.user.nick)||void 0===t?void 0:t.startsWith("visitor:"))?"User":"Assistant",o=(null===(n=e.msg)||void 0===n?void 0:n.text)||"",a="".concat(i,": ").concat(o),s=null===(r=e.msg)||void 0===r?void 0:r.options;if(s&&s.length>0){var l=s.map(Zk).join(", ");a+="\nSuggestions: ".concat(l)}return a}).join("\n")}(t),r.label=1;case 1:return r.trys.push([1,3,,4]),[4,navigator.clipboard.writeText(e)];case 2:return r.sent(),[3,4];case 3:return r.sent(),console.warn("[ExportButton] Using deprecated execCommand fallback for clipboard copy"),(n=document.createElement("textarea")).value=e,document.body.appendChild(n),n.select(),document.execCommand("copy"),document.body.removeChild(n),[3,4];case 4:return[2]}})})}})},tS=function(e){return f.jsx("div",{id:"xapp-widget-menu","aria-label":"open menu","aria-hidden":!1,tabIndex:e.tabIndex?Number(e.tabIndex):0,className:"menu-button",onClick:e.onClick})},nS=function(e){return f.jsx("div",{id:"xapp-widget-minimize","aria-label":"minimize widget","aria-hidden":!1,tabIndex:e.tabIndex?Number(e.tabIndex):0,className:"minimize-button ".concat(e.showInRight?"positionRight":""),onClick:e.onClick})},rS=function(e){return f.jsx("div",{id:"xapp-widget-refresh","aria-label":"refresh chat","aria-hidden":!1,tabIndex:e.tabIndex?Number(e.tabIndex):0,className:"refresh-button ".concat(e.showInRight?"positionRight":e.showInLeft?"positionLeft":""),onClick:e.onClick})},iS="Virtual Assistant",oS="Leave us a message",aS="We're away!",sS="Connecting...";function lS(e,t){var n,r,i,o;switch(Yh('getStatusText called with status: "'.concat(e,'"')),e){case"online":return null!==(n=null==t?void 0:t.online)&&void 0!==n?n:iS;case"offline":return null!==(r=null==t?void 0:t.offline)&&void 0!==r?r:oS;case"away":return null!==(i=null==t?void 0:t.away)&&void 0!==i?i:aS;default:return null!==(o=null==t?void 0:t.connecting)&&void 0!==o?o:sS}}function cS(e){if(function(e){return"string"==typeof e&&/<\/?[a-z][\s\S]*>/i.test(e)}(e)){var t=function(e){try{if("undefined"==typeof DOMParser)return Yh("DOMParser not available, returning text content only"),e.replace(/<[^>]*>/g,"");var t=(new DOMParser).parseFromString(e,"text/html");if(!t||!t.body)return Yh("DOMParser failed to parse HTML, returning text content only"),e.replace(/<[^>]*>/g,"");var n=["span","div","p","strong","em","b","i","u","br"],r=["color","background-color","font-size","font-weight","font-style","text-align","display","flex","align-items","justify-content","gap","margin","padding","width","height","border-radius"],i=function(e){if(e.nodeType===Node.ELEMENT_NODE){var o=e,a=o.tagName.toLowerCase();if(!n.includes(a)){var s=t.createTextNode(o.textContent||"");return void o.replaceWith(s)}if(Array.from(o.attributes).forEach(function(e){"style"!==e.name&&o.removeAttribute(e.name)}),o.hasAttribute("style")){var l=o.getAttribute("style")||"",c=[];l.split(";").forEach(function(e){var t=e.split(":"),n=t[0],i=t.slice(1).join(":").trim(),o=n.trim();o&&i&&r.includes(o.toLowerCase())&&(/javascript:|expression\(|@import|behavior:/i.test(i)||c.push("".concat(o,": ").concat(i)))}),c.length>0?o.setAttribute("style",c.join("; ")):o.removeAttribute("style")}Array.from(o.childNodes).forEach(function(e){return i(e)})}};return Array.from(t.body.childNodes).forEach(function(e){return i(e)}),t.body.innerHTML}catch(t){return Yh("Error sanitizing HTML: ".concat(t)),e.replace(/<[^>]*>/g,"")}}(e);return f.jsx("span",{dangerouslySetInnerHTML:{__html:t}})}return e}var uS=function(e){var t,n,r,i,o,a,s,l,c,u,d,p,h,m,v,g=Cm(),y=e.menuConfig,b=e.onSubmit,w=e.debugMode,x=Z.useState(!1),k=x[0],S=x[1],C=(null==y?void 0:y.menuButtonLocation)||"FOOTER",_="HEADER_LEFT"===C,E="HEADER_RIGHT"===C,N=null==y?void 0:y.items,I=null==y?void 0:y.itemsTabIndex,T=null===(t=null==y?void 0:y.button)||void 0===t?void 0:t.tabIndex,j=Z.useMemo(function(){return N||[]},[N]),O=E&&j.length>0;function P(){var e=!k;S(e),g(fb({drawer:e}))}var A="",R=e.canRefresh,M=e.canMinimize,L=e.canCancel;return R&&(A="To refresh chat click on clockwise gapped circle arrow icon in top right side of widget. "),M&&(A="".concat(A).concat("To minimize widget click on minus icon in top right side of widget. ")),L&&(A="".concat(A).concat("To close widget click on close icon in top right side of widget.")),f.jsxs(f.Fragment,{children:[f.jsxs("div",{className:"status-container background-header","aria-label":A,"aria-hidden":!1,children:[_&&j.length?f.jsx(f.Fragment,{children:f.jsx("div",{className:"chat-footer__menu-icon",children:f.jsx($x,{bars:3,tabIndex:T,onToggle:P})})}):f.jsx(f.Fragment,{}),void 0===(null===(n=null==e?void 0:e.agent)||void 0===n?void 0:n.avatarPath)?f.jsx("div",{}):f.jsx("div",{className:"status-container__avatar",children:f.jsx(pm,{entity:e.agent})}),f.jsxs("div",{className:"\n ".concat("status-text","\n ").concat(_&&j.length?"status-text-positionWithMenu":void 0===(null===(r=null==e?void 0:e.agent)||void 0===r?void 0:r.avatarPath)?"status-text-positionLeftNoAvatar":"status-text-positionLeft","\n ").concat((null===(i=e.config)||void 0===i?void 0:i.alignTextCenter)?"status-text-positionCenter":""," \n "),children:[f.jsx("span",{className:"status-text-title",children:lS(e.accountStatus,null===(o=e.config)||void 0===o?void 0:o.status)}),(null===(s=null===(a=e.config)||void 0===a?void 0:a.subtitle)||void 0===s?void 0:s.enabled)&&f.jsx("span",{className:"status-text-subtitle",children:cS(null===(c=null===(l=e.config)||void 0===l?void 0:l.subtitle)||void 0===c?void 0:c.text)})]}),f.jsxs(Gk,{children:[O&&f.jsx(tS,{onClick:P,tabIndex:T}),w&&f.jsx(eS,{}),e.canRefresh&&f.jsx(rS,{onClick:e.refreshOnClick,tabIndex:null===(d=null===(u=e.config)||void 0===u?void 0:u.actions)||void 0===d?void 0:d.refreshTabIndex,showInLeft:!1,showInRight:!1}),e.canMinimize&&f.jsx(nS,{onClick:e.minimizeOnClick,tabIndex:null===(h=null===(p=e.config)||void 0===p?void 0:p.actions)||void 0===h?void 0:h.minimizeTabIndex,showInRight:!1}),e.canCancel&&f.jsx(Xk,{onClick:e.cancelOnClick,tabIndex:null===(v=null===(m=e.config)||void 0===m?void 0:m.actions)||void 0===v?void 0:v.cancelTabIndex})]})]}),k?f.jsx("div",{className:"xa-chat-menu-container",children:f.jsx(Vx,{openFrom:E?"right":"left",opened:k,tabIndex:I,onItemClick:function(e){S(!1),b(e)},items:j})}):f.jsx(f.Fragment,{})]})};function dS(e){var t,n,i,o,a;return hS("--xapp-",mS(vS("primary-color",null==e?void 0:e.primaryColor),hS("widget-",mS(bS(null==e?void 0:e.size),wS(null==e?void 0:e.margin),_S(null==e?void 0:e.border),function(e){return r(this,function(t){switch(t.label){case 0:return e?[4,["z-index",e]]:[3,2];case 1:t.sent(),t.label=2;case 2:return[2]}})}(null==e?void 0:e.zIndex))),function(e){if(!e)return gS();return hS("chat-button-",mS(wS(e.margin),SS(e.background),hS("image-",bS(e.imageSize)),function(e){var t,n,i,o,a;return r(this,function(r){switch(r.label){case 0:return e?(t=e.primaryColor||"0, 117, 170",n=e.secondaryColor||"110, 178, 209",i=e.opacity||.75,[4,["animation-primary-color","".concat(t)]]):[2];case 1:return r.sent(),[4,["animation-secondary-color","".concat(n)]];case 2:return r.sent(),[4,["animation-opacity","".concat(i)]];case 3:return r.sent(),[4,["animation-primary-rgba","rgba(".concat(t,", ").concat(i,")")]];case 4:return r.sent(),[4,["animation-secondary-rgba","rgba(".concat(n,", ").concat(i,")")]];case 5:return r.sent(),o="radial-gradient(40.83% 40.83% at 47.92% 52.5%, rgba(".concat(t,", ").concat(i,") 78.85%, rgba(").concat(n,", ").concat(i,") 92.07%)"),a="radial-gradient(40.83% 40.83% at 47.92% 52.5%, rgba(".concat(t,", ").concat(i,") 20.46%, rgba(").concat(n,", ").concat(i,") 92.07%)"),[4,["animation-pulse-intense",o]];case 6:return r.sent(),[4,["animation-pulse-less-intense",a]];case 7:return r.sent(),[2]}})}(e.animation)))}(null==e?void 0:e.chatButton),hS("header-",function(e){if(!e)return gS();return mS(SS(e.background),kS(e.text),hS("subtitle-",kS(e.subtitle)),_S(e.border),xS(e.padding),vS("avatar-background",e.avatarBackground))}(null==e?void 0:e.header)),hS("footer-",function(e){var t;if(!e)return gS();return mS(SS(e.background),_S(e.border),hS("branding-",kS(null===(t=e.branding)||void 0===t?void 0:t.text)))}(null==e?void 0:e.footer)),hS("content-",mS(SS(null===(t=null==e?void 0:e.content)||void 0===t?void 0:t.background))),hS("messages-",function(e){if(!e)return gS();return mS(hS("mine-",yS(e.mine)),hS("others-",yS(e.others)),xS(null==e?void 0:e.padding),vS("max-width",null==e?void 0:e.maxWidth))}(null==e?void 0:e.messages)),hS("text-typing-status-",kS(null===(n=null==e?void 0:e.textTypingStatus)||void 0===n?void 0:n.text)),hS("send-",CS(null==e?void 0:e.sendButton)),hS("menu-",CS(null==e?void 0:e.menuButton)),hS("menu-",function(e){return mS(hS("item-",function(e){return mS(kS(null==e?void 0:e.text),hS("subtitle-",kS(null==e?void 0:e.subtitle)),_S(null==e?void 0:e.border),SS(null==e?void 0:e.background),vS("height",null==e?void 0:e.height))}(null==e?void 0:e.item)))}(null==e?void 0:e.menu)),hS("refresh-",CS(null==e?void 0:e.refreshButton)),hS("minimize-",CS(null==e?void 0:e.minimizeButton)),hS("cancel-",CS(null==e?void 0:e.cancelButton)),hS("carousel-",mS(hS("title-",kS(null===(i=null==e?void 0:e.carousel)||void 0===i?void 0:i.title)),hS("subtitle-",kS(null===(o=null==e?void 0:e.carousel)||void 0===o?void 0:o.subtitle)),hS("action-",CS(null===(a=null==e?void 0:e.carousel)||void 0===a?void 0:a.button)))),hS("input-",function(e){if(!e)return gS();return mS(SS(e.background),_S(e.border),kS(e.text),hS("placeholder-",kS(e.placeholder)))}(null==e?void 0:e.input)),hS("cta-",function(e){if(!e)return gS();return mS(SS(e.background),kS(e.text))}(null==e?void 0:e.cta)),hS("action-bar-",function(e){if(!e)return gS();return mS(SS(e.background),_S(e.border),xS(e.padding),wS(e.margin),vS("box-shadow",e.boxShadow),vS("border-radius",e.borderRadius),hS("button-",function(e){if(!e)return gS();return mS(SS(e.background),vS("hover-background",e.hoverBackground),hS("icon-",bS(e.iconSize)),vS("icon-color",e.iconColor),hS("label-",kS(e.label)),vS("gap",e.gap),vS("border-radius",e.borderRadius),xS(e.padding))}(e.button)))}(null==e?void 0:e.actionBar))))}var fS=new Map;function pS(e){var t=e.theme,n=JSON.stringify(function(e){for(var t=[],n=dS(e),r=n.next();!1===r.done;){var i=r.value,o=i[0],a=i[1];null!=a&&""!==a&&t.push([o,a]),r=n.next()}return t}(t));return ee.useLayoutEffect(function(){var e=JSON.parse(n);return function(e){for(var t,n=document.documentElement,r=0,i=e;r<i.length;r++){var o=i[r],a=o[0],s=o[1];n.style.setProperty(a,s),fS.set(a,(null!==(t=fS.get(a))&&void 0!==t?t:0)+1)}}(e),function(){return function(e){for(var t,n=document.documentElement,r=0,i=e;r<i.length;r++){var o=i[r][0],a=(null!==(t=fS.get(o))&&void 0!==t?t:1)-1;a<=0?(fS.delete(o),n.style.removeProperty(o)):fS.set(o,a)}}(e)}},[n]),null}function hS(e,t){var n;return r(this,function(r){switch(r.label){case 0:n=t.next(),r.label=1;case 1:return n.done?[3,3]:[4,["".concat(e).concat(n.value[0]),n.value[1]]];case 2:return r.sent(),n=t.next(),[3,1];case 3:return[2]}})}function mS(){var e,t,n,i,o,a=[];for(e=0;e<arguments.length;e++)a[e]=arguments[e];return r(this,function(e){switch(e.label){case 0:t=0,n=a,e.label=1;case 1:if(!(t<n.length))return[3,5];i=n[t],o=i.next(),e.label=2;case 2:return!1!==o.done?[3,4]:[4,o.value];case 3:return e.sent(),o=i.next(),[3,2];case 4:return t++,[3,1];case 5:return[2]}})}function vS(e,t){return r(this,function(n){switch(n.label){case 0:return[4,[e,t]];case 1:return n.sent(),[2]}})}function gS(){return r(this,function(e){return[2]})}function yS(e){return mS(vS("bubble-color",null==e?void 0:e.bubbleColor),kS(null==e?void 0:e.text))}function bS(e){return r(this,function(t){switch(t.label){case 0:return[4,["width",null==e?void 0:e.width]];case 1:return t.sent(),[4,["height",null==e?void 0:e.height]];case 2:return t.sent(),[2]}})}function wS(e){return r(this,function(t){switch(t.label){case 0:return e?[4,["margin-top",e.top]]:[3,5];case 1:return t.sent(),[4,["margin-right",e.right]];case 2:return t.sent(),[4,["margin-bottom",e.bottom]];case 3:return t.sent(),[4,["margin-left",e.left]];case 4:t.sent(),t.label=5;case 5:return[2]}})}function xS(e){return r(this,function(t){switch(t.label){case 0:return e?[4,["padding-top",e.top]]:[3,5];case 1:return t.sent(),[4,["padding-right",e.right]];case 2:return t.sent(),[4,["padding-bottom",e.bottom]];case 3:return t.sent(),[4,["padding-left",e.left]];case 4:t.sent(),t.label=5;case 5:return[2]}})}function kS(e){return r(this,function(t){switch(t.label){case 0:return e?[4,["text-color",e.color]]:[3,6];case 1:return t.sent(),[4,["font-size",e.fontSize]];case 2:return t.sent(),[4,["font-family",e.fontFamily]];case 3:return t.sent(),[4,["font-weight",e.fontWeight]];case 4:return t.sent(),[4,["font-style",e.fontStyle]];case 5:t.sent(),t.label=6;case 6:return[2]}})}function SS(e){return r(this,function(t){switch(t.label){case 0:return[4,["background",e]];case 1:return t.sent(),[2]}})}function CS(e){return r(this,function(t){switch(t.label){case 0:return[4,["button-color",null==e?void 0:e.color]];case 1:return t.sent(),[4,["button-width",null==e?void 0:e.width]];case 2:return t.sent(),[4,["button-bg",null==e?void 0:e.background]];case 3:return t.sent(),[4,["button-hover-bg",null==e?void 0:e.hoverBackground]];case 4:return t.sent(),[4,["button-disabled-bg",null==e?void 0:e.disabledBackground]];case 5:return t.sent(),[2]}})}function _S(e){return r(this,function(t){switch(t.label){case 0:return e?[4,["border-color",e.color]]:[3,4];case 1:return t.sent(),[4,["border-width",e.width]];case 2:return t.sent(),[4,["border-radius",e.radius]];case 3:t.sent(),t.label=4;case 4:return[2]}})}var ES=function(e){if(null===e)return"null";if(void 0===e)return"undefined";if("object"!=typeof e)return String(e);try{var t=new WeakSet;return JSON.stringify(e,function(e,n){if("object"==typeof n&&null!==n){if(t.has(n))return"[Circular]";t.add(n)}return n},2)}catch(t){return"[Object: ".concat(Object.prototype.toString.call(e),"]")}},NS=function(e){var o=e.enableErrorOverlay,a=Z.useState([]),s=a[0],l=a[1],c=Z.useState(!1),u=c[0],d=c[1],p=Z.useState(!0),h=p[0],m=p[1],v=Z.useState(!1),g=v[0],y=v[1],b=Z.useState("bottom"),w=b[0],x=b[1];Z.useEffect(function(){var e,t=function(){var e;if("undefined"==typeof window)return!1;var t=null===(e=window.localStorage)||void 0===e?void 0:e.getItem("xaErrorOverlay");return"enabled"===t?(console.log("[ErrorOverlay] Enabled via localStorage"),!0):"disabled"===t?(console.log("[ErrorOverlay] Disabled via localStorage"),!1):void 0!==o?(console.log("[ErrorOverlay] Using config setting:",o),o):!(void 0===globalThis.__DEV__||!globalThis.__DEV__)&&(console.log("[ErrorOverlay] Enabled via __DEV__"),!0)}();y(t);var n=null===(e=window.localStorage)||void 0===e?void 0:e.getItem("xaErrorOverlayPosition");"top"!==n&&"bottom"!==n||x(n),console.log("[ErrorOverlay] Component mounted, enabled:",t,"position:",n||"bottom")},[o]);var k=Z.useCallback(function(e){console.log("[ErrorOverlay] Adding error:",e),l(function(n){var r=(new Date).toISOString(),o=n[n.length-1];if(o&&o.message===e.message)return i(i([],n.slice(0,-1),!0),[t(t({},o),{count:o.count+1,timestamp:r})],!1);var a=t({id:"".concat(r,"-").concat(Math.random()),timestamp:r,count:1},e);return i(i([],n,!0),[a],!1).slice(-50)})},[]);Z.useEffect(function(){if(g){console.log("[ErrorOverlay] Setting up error interception");var e=console.error,t=console.warn;console.error=function(){for(var t=[],n=0;n<arguments.length;n++)t[n]=arguments[n];var r=t.map(function(e){return ES(e)}).join(" "),i=new Error;k({message:r,type:"error",stack:i.stack}),e.apply(console,t)},console.warn=function(){for(var e=[],n=0;n<arguments.length;n++)e[n]=arguments[n];var r=e.map(function(e){return ES(e)}).join(" ");k({message:r,type:"warning"}),t.apply(console,e)};var n=function(e){var t;k({message:e.message,type:"error",stack:null===(t=e.error)||void 0===t?void 0:t.stack})},r=function(e){var t;k({message:"Unhandled Promise Rejection: ".concat(e.reason),type:"error",stack:null===(t=e.reason)||void 0===t?void 0:t.stack})};return window.addEventListener("error",n),window.addEventListener("unhandledrejection",r),function(){console.log("[ErrorOverlay] Cleaning up error interception"),console.error=e,console.warn=t,window.removeEventListener("error",n),window.removeEventListener("unhandledrejection",r)}}console.log("[ErrorOverlay] Not enabled, skipping error interception")},[g,k]);return g&&h?0===s.length?null:f.jsxs("div",{className:"error-overlay error-overlay--".concat(w," ").concat(u?"minimized":""),children:[f.jsxs("div",{className:"error-overlay-header",children:[f.jsxs("span",{className:"error-overlay-title",children:["Debug Console (",s.length,")"]}),f.jsxs("div",{className:"error-overlay-actions",children:[f.jsx("button",{onClick:function(){return n(void 0,void 0,void 0,function(){var e,t,n;return r(this,function(r){switch(r.label){case 0:e=s.map(function(e){return"[".concat(e.timestamp,"] ").concat(e.type.toUpperCase(),": ").concat(e.message).concat(e.stack?"\n"+e.stack:"")}).join("\n\n"),r.label=1;case 1:return r.trys.push([1,3,,4]),[4,navigator.clipboard.writeText(e)];case 2:return r.sent(),console.log("[ErrorOverlay] Errors copied to clipboard"),[3,4];case 3:t=r.sent(),console.error("[ErrorOverlay] Failed to copy to clipboard:",t),(n=document.createElement("textarea")).value=e,n.style.position="fixed",n.style.opacity="0",document.body.appendChild(n),n.select();try{document.execCommand("copy"),console.log("[ErrorOverlay] Errors copied to clipboard using fallback method")}catch(e){console.error("[ErrorOverlay] Fallback copy method also failed:",e)}return document.body.removeChild(n),[3,4];case 4:return[2]}})})},title:"Copy all to clipboard",children:"📋"}),f.jsx("button",{onClick:function(){l([])},title:"Clear all",children:"🗑️"}),f.jsx("button",{onClick:function(){var e="bottom"===w?"top":"bottom";x(e),"undefined"!=typeof window&&window.localStorage&&window.localStorage.setItem("xaErrorOverlayPosition",e)},title:"Move to ".concat("bottom"===w?"top":"bottom"),children:"bottom"===w?"⬆️":"⬇️"}),f.jsx("button",{onClick:function(){var e=!g;y(e),"undefined"!=typeof window&&window.localStorage&&window.localStorage.setItem("xaErrorOverlay",e?"enabled":"disabled"),console.log("[ErrorOverlay] Toggled enabled state to:",e),e||l([])},title:"Disable Error Overlay",children:"🔧"}),f.jsx("button",{onClick:function(){return d(!u)},title:"Minimize/Maximize",children:u?"▲":"▼"}),f.jsx("button",{onClick:function(){return m(!1)},title:"Close",children:"✕"})]})]}),!u&&f.jsx("div",{className:"error-overlay-content",children:s.map(function(e){return f.jsxs("div",{className:"error-entry error-".concat(e.type),children:[f.jsxs("div",{className:"error-header",children:[f.jsx("span",{className:"error-time",children:new Date(e.timestamp).toLocaleTimeString()}),e.count>1&&f.jsxs("span",{className:"error-count",children:["(",e.count,"x)"]}),f.jsx("span",{className:"error-badge error-badge-".concat(e.type),children:e.type})]}),f.jsx("div",{className:"error-message",children:e.message}),e.stack&&f.jsxs("details",{className:"error-stack",children:[f.jsx("summary",{children:"Stack trace"}),f.jsx("pre",{children:e.stack})]})]},e.id)})})]}):null},IS=function(e){var t=e.button,n=e.onPress,r=Z.useCallback(function(){"disabled"===t.pressBehavior||t.isPressed||n(t.id)},[t.pressBehavior,t.isPressed,t.id,n]),i=Z.useMemo(function(){var e=["ws-button"];return("disabled"===t.pressBehavior||t.isPressed)&&e.push("ws-button--disabled"),t.isPressed&&"spinning"===t.pressBehavior&&e.push("ws-button--spinning"),e.join(" ")},[t.pressBehavior,t.isPressed]),o=Z.useMemo(function(){var e=["ws-button-container"];return t.isDismissing&&e.push("ws-button-container--dismissing"),e.join(" ")},[t.isDismissing]);return f.jsx("div",{className:o,children:f.jsxs("button",{className:i,onClick:r,disabled:"disabled"===t.pressBehavior||t.isPressed,"aria-label":t.text,"aria-busy":t.isPressed&&"spinning"===t.pressBehavior,children:[t.isPressed&&"spinning"===t.pressBehavior&&f.jsx("span",{className:"ws-button__spinner"}),f.jsx("span",{className:"ws-button__text",children:t.text})]})})},TS=function(e){var t=e.onClose,n=e.onReset;return f.jsxs("div",{className:"modalContent",children:[f.jsxs("div",{className:"modalBody",children:[f.jsx("h2",{children:"Restart Conversation"}),f.jsx("p",{children:"Would you like to refresh and return to the starting point of the conversation?"})]}),f.jsxs("div",{className:"modalActions",children:[f.jsx("button",{onClick:t,className:"cancelBtn",children:"Cancel"}),f.jsx("button",{onClick:n,className:"restartBtn",children:"Restart"})]})]})};function jS(e){var t=function(e){return function(t,n){return void 0===t&&(t=e),Yh("static reducer",t,n),t}}(e);return kw({reducer:t,middleware:function(e){return e({thunk:!0})},devTools:!1})}var OS=function(e){var n=e.state,r=Z.useMemo(function(){return jS(n)},[n]),i=Z.useMemo(function(){return t(t({},e.config),{connection:{serverUrl:"",type:"local"}})},[e.config]);return f.jsx(_h,{store:r,children:f.jsx(BS,t({},e,{config:i,disableAutoScroll:e.disableAutoScroll,preview:e.preview}))})},PS=function(e){var n=e.messages,r=Z.useMemo(function(){return function(e){var n,r=Nw(),o=e.length>0?e[e.length-1]:void 0,a="chat.msg"===(null==o?void 0:o.type)?o.msg:null,s=(null===(n=null==a?void 0:a.options)||void 0===n?void 0:n.length)?a.options:[];return t(t({},r),{connection:t(t({},r.connection),{connectionStatus:"online"}),accountStatus:"online",chats:i([],e,!0),chips:s,isChatting:!0,visuals:{visible:!0,opened:!0}})}(n)},[n]);return f.jsx(OS,{state:r,mode:e.mode,config:e.config,disableAutoScroll:e.disableAutoScroll,preview:e.preview})},AS="undefined"==typeof window?Z.useEffect:Z.useLayoutEffect;"undefined"!=typeof process&&process.env;var RS=function(e){var t,n=null!==(t=e.mode)&&void 0!==t?t:"preview",r=Z.useMemo(function(){return t=e.previewMessages||[],n=e.config,r=Date.now(),t.map(function(e,t){var i,o;return{type:"chat.msg",user:{nick:"agent:robot",display_name:(null==n?void 0:n.botName)||"Assistant",avatarPath:null==n?void 0:n.avatarUrl},timestamp:r+t,msg:{text:e.displayText,html:e.html,options:null===(i=e.suggestions)||void 0===i?void 0:i.map(function(e){return{label:e.title,actionUrl:e.url||"#"}}),list:e.list?{type:e.list.type,title:e.list.title,items:e.list.items.map(function(e){return{title:e.title,subTitle:e.description,url:e.url,imageUrl:e.imageUrl,hideUrl:e.hideUrl}})}:void 0,displays:e.list?[(o={type:e.list.type,title:e.list.title,items:e.list.items.map(function(e){return{title:e.title,subTitle:e.description,url:e.url,imageUrl:e.imageUrl,hideUrl:e.hideUrl}})},{type:o.type,title:o.title,items:(o.items||[]).map(function(e){var t={title:e.title,description:e.subTitle,token:e.token,url:e.url,hideUrl:e.hideUrl,image:{url:e.imageUrl,imageActionUrl:e.imageActionUrl,accessibilityText:""}},n=e.buttons;return n&&n.length>0&&(t.buttons=n.map(function(e){return{openUrlAction:e.actionUrl,title:e.label}})),t})})]:void 0}}});var t,n,r},[e.previewMessages,e.config]);return f.jsx(PS,{messages:r,mode:n,config:e.config,disableAutoScroll:e.disableAutoScroll,preview:!0})},MS=function(e){var n,r=null!==(n=e.mode)&&void 0!==n?n:"normal",i=Z.useState(e.config),o=i[0],a=i[1],s=Z.useState(!!e.getConfig),l=s[0],c=s[1],u=Z.useState(),d=u[0],p=u[1];Z.useEffect(function(){var t=!1;return e.getConfig?(c(!0),p(void 0),e.getConfig().then(function(e){t||(a(e),c(!1),Yh("[ChatWidget] Config loaded from getConfig callback"))}).catch(function(e){t||(p(e),c(!1),Gh("[ChatWidget] Failed to load config: ".concat(e.message)))})):e.config&&(a(e.config),c(!1)),function(){t=!0}},[e.getConfig,e.config]);var h,m,v=(h=o,m=Rh(function(e){return e.connection.nonce}),Yh("nonce from Redux: ".concat(m)),om(h,m)),g=Z.useMemo(function(){var e;return t(t({},o),{connection:v,assetUrl:null!==(e=null==v?void 0:v.serverUrl)&&void 0!==e?e:Zh,env:o})},[v,o]),y=Rh(function(e){return e.connection.token}),b=Z.useMemo(function(){var e={items:[{delay:5,text:"We are having trouble communicating with the assistant right now. Re-trying in ${sec} seconds..."},{delay:5,text:"We are still having trouble communicating with the assistant right now. Re-trying in ${sec} seconds..."},{delay:0,text:"Sorry, we cannot communicate with the assistant right now. Please check your connection or try again later."}]};return(null==o?void 0:o.configurableMessages)&&Array.isArray(o.configurableMessages.items)&&o.configurableMessages.items.length>0&&(e=o.configurableMessages),{token:y,bot:{nick:"Bot",displayName:null==o?void 0:o.botName,avatarPath:null==o?void 0:o.avatarUrl},configurableMessages:e,hooks:null==o?void 0:o.hooks,env:o}},[y,null==o?void 0:o.botName,null==o?void 0:o.avatarUrl,null==o?void 0:o.configurableMessages,null==o?void 0:o.hooks]),w=function(e,t){var n=Z.useState(),r=n[0],i=n[1],o=Cm(),a=[t,e,o],s=Z.useRef(void 0);return Z.useEffect(function(){if(s.current){var n=s.current,r=n[0],a=n[1],l=n[2],c=[];r!==t&&c.push("options"),a!==e&&c.push("config"),l!==o&&c.push("dispatch"),c.length>0&&Yh("[useChatServer] Effect re-running due to: ".concat(c.join(", ")))}else Yh("[useChatServer] Effect running for first time");if(s.current=[t,e,o],!e||!t)return Yh("[useChatServer] Config or options null, not creating server"),void i(void 0);Yh("Creating new chat server - type: ".concat(e.type));var u=sb(e,t);return u.init(o),i(u),function(){Yh("Cleanup - disposing old server"),u.dispose()}},a),r}(l||d?null:v,l||d?null:b),x="widget-container--".concat(r);return l?f.jsx("div",{className:"widget-container widget-container--loading ".concat(x),children:f.jsx("div",{className:"xa-spinner-container visible",children:f.jsx("div",{className:"xa-spinner"})})}):d?f.jsx("div",{className:"widget-container widget-container--error ".concat(x),children:f.jsxs("div",{className:"widget-error-message",children:["Failed to load chat configuration: ",d.message]})}):f.jsx(nm.Provider,{value:g,children:f.jsx(lb.Provider,{value:w,children:f.jsx(BS,t({},e,{config:o}))})})};function LS(e){var t,n;return _x(e)&&(null===(n=null===(t=e.formConfig)||void 0===t?void 0:t.api)||void 0===n?void 0:n.key)||void 0}function DS(){return Fh()||Wh()}var BS=function(e){var n,r,i,o,a,s,l,c,u,d,p,h,m,v,g,y,b,w,x,k,S,C,_,E,N,I,T,j,O,P,A,R,M,L,D,B,z,U,F,q,H,W,V,$,K,Q,J,Y,G=Cm(),X=cb();rg();var ee=Rh(function(e){return e}),te=Z.useRef({}),ne=null!==(n=e.mode)&&void 0!==n?n:"normal",re="docked"===ne,ie="static"===ne,oe=!0===e.preview||"preview"===ne,ae="widget-container--".concat(ne),se=Uw(oe),le=vb(ee.chats),ce=Z.useMemo(function(){var t;return gb(null===(t=e.config)||void 0===t?void 0:t.cta,{hasConversation:le,arrivedViaChatLink:se})},[null===(r=e.config)||void 0===r?void 0:r.cta,le,se]),de=re&&!0===(null===(i=e.config.popOut)||void 0===i?void 0:i.enabled),fe=null!==(a=null===(o=e.config.popOut)||void 0===o?void 0:o.minWidth)&&void 0!==a?a:640,pe=Z.useRef(null),he=Z.useState(!1),me=he[0],ve=he[1],ge=Z.useState(!1),ye=ge[0],be=ge[1],we=Z.useState(!1),xe=we[0],ke=we[1],Se=Z.useState(!1),Ce=Se[0],_e=Se[1],Ee=Z.useState("undefined"==typeof window?0:window.innerWidth),Ne=Ee[0],Ie=Ee[1];Z.useEffect(function(){if(de&&"undefined"!=typeof window){var e=function(){return Ie(window.innerWidth)};return e(),window.addEventListener("resize",e),function(){return window.removeEventListener("resize",e)}}},[de]),Z.useEffect(function(){if(de&&"undefined"!=typeof IntersectionObserver&&pe.current){var e=new IntersectionObserver(function(e){var t=e[e.length-1];t&&(ve(!t.isIntersecting),t.isIntersecting&&(be(!0),ke(!1),_e(!1)))});return e.observe(pe.current),function(){return e.disconnect()}}},[de]);var Te,je="message"!==(null===(s=e.config.popOut)||void 0===s?void 0:s.after)||!!(null==(Te=ee.chats)?void 0:Te.some(function(e){var t,n;return"chat.msg"===e.type&&!!(null===(n=null===(t=e.user)||void 0===t?void 0:t.nick)||void 0===n?void 0:n.startsWith("visitor:"))})),Oe=de&&ye&&me&&!xe&&je,Pe=Ne>=fe,Ae=null!==(c=null===(l=e.config.popOut)||void 0===l?void 0:l.mobile)&&void 0!==c?c:"auto",Re=Oe&&!Pe&&"none"!==Ae&&!Ce,Me=Oe&&(Pe||Ce);function Le(){_e(!0)}var De=Z.useMemo(function(){return de&&"undefined"!=typeof document?document.createElement("div"):null},[de]),Be=Z.useRef({fromBottom:0,latest:!0});Z.useEffect(function(){if(De){var e=function(e){var t=e.target;if(t instanceof HTMLElement&&t.classList.contains("message-list-container")){var n=t.scrollHeight-t.clientHeight-t.scrollTop;Be.current={fromBottom:n,latest:n<=t.clientHeight}}};return De.addEventListener("scroll",e,!0),function(){return De.removeEventListener("scroll",e,!0)}}},[De]),AS(function(){if(De){De.className="widget-portal";var e=Me?document.body:pe.current;if(e&&De.parentElement!==e){var t=document.activeElement,n=t instanceof HTMLElement&&De.contains(t)?t:void 0,r=De.querySelector(".message-list-container");e.appendChild(De);var i=function(){if(r){var e=Be.current,t=e.fromBottom,n=e.latest,i=r.scrollHeight-r.clientHeight;r.scrollTop=n?i:Math.max(0,i-t)}};i(),null==n||n.focus({preventScroll:!0});var o=requestAnimationFrame(i),a=window.setTimeout(i,250);return function(){cancelAnimationFrame(o),window.clearTimeout(a)}}}},[De,Me]),Z.useEffect(function(){return function(){return null==De?void 0:De.remove()}},[De]);var ze,Ue=!0===(null===(u=e.config.header)||void 0===u?void 0:u.hidden)&&(re||ie)&&!Me,Fe=Z.useMemo(function(){return Ue&&e.config.menu&&"FOOTER"!==e.config.menu.menuButtonLocation?t(t({},e.config.menu),{menuButtonLocation:"FOOTER"}):e.config.menu},[Ue,e.config.menu]),qe=null===(p=null===(d=e.config.header)||void 0===d?void 0:d.actions)||void 0===p?void 0:p.refresh,He=!re&&!ie&&!oe&&(null===(m=null===(h=e.config.header)||void 0===h?void 0:h.actions)||void 0===m?void 0:m.minimize);Yh("docked: ".concat(re," static: ").concat(ie," preview: ").concat(oe," minimized: ").concat(null===(g=null===(v=e.config.header)||void 0===v?void 0:v.actions)||void 0===g?void 0:g.minimize)),ze="boolean"==typeof(null===(b=null===(y=e.config.header)||void 0===y?void 0:y.actions)||void 0===b?void 0:b.cancel)?!re&&!ie&&!oe&&(null===(x=null===(w=e.config.header)||void 0===w?void 0:w.actions)||void 0===x?void 0:x.cancel):!re&&!ie&&!oe,ee.visuals||(ee.visuals={});var We=(null===(k=e.config)||void 0===k?void 0:k.autoOpenOnWidth)?parseInt(e.config.autoOpenOnWidth,10):NaN,Ve=!isNaN(We)&&window.innerWidth>=We,$e=Z.useState(!He&&!ze||(isNaN(We)?ee.visuals.visible:Ve)),Ke=$e[0],Qe=$e[1],Je=Z.useState(!1);Je[0];var Ye=Je[1],Ge=Z.useRef(!1),Xe=Z.useRef(null),Ze=Z.useRef(Ve),et=Z.useContext(lb),tt=null===(C=null===(S=e.config)||void 0===S?void 0:S.autoOpenOnPattern)||void 0===C?void 0:C.patterns,nt=window.location.href,rt=tt&&tt.length>0,it=null==tt?void 0:tt.some(function(e){return nt.includes(e)}),ot=null===(E=null===(_=e.config)||void 0===_?void 0:_.autoOpenOnPattern)||void 0===E?void 0:E.minimumWidth,at=window.innerWidth,st=Z.useCallback(function(e){ie||oe||(Yh("setVisible: ".concat(e)),Qe(e),G(fb({visible:e})))},[G,ie,oe]);Z.useEffect(function(){var t,n,r=function(e){var t=document.getElementsByTagName("body")[0];t.tabIndex=-1,"Escape"===e.key&&t.focus()};return document.addEventListener("keydown",r),zw((null==ee?void 0:ee.sessionExpiration)||(null===(t=e.config)||void 0===t?void 0:t.sessionExpiration),null===(n=null==ee?void 0:ee.chats[ee.chats.length-1])||void 0===n?void 0:n.timestamp,null==ee||ee.lastTimestamp)&&(G(yg(void 0)),G({type:"reset"})),function(){document.removeEventListener("keydown",r),Xe.current&&clearTimeout(Xe.current)}},[]);var lt=Z.useState(!document.hidden),ct=lt[0],ut=lt[1];Z.useEffect(function(){var e=function(){ut(!document.hidden)};return document.addEventListener("visibilitychange",e),function(){document.removeEventListener("visibilitychange",e)}},[]),Z.useEffect(function(){et?ct?(Yh("Tab is VISIBLE - calling wakeup()"),et.wakeup()):(Yh("Tab is HIDDEN - calling sleep()"),et.sleep()):Yh("Tab visibility changed but no chatServer yet")},[et,G,ct]),Z.useEffect(function(){if(et){var e=function(){Yh("beforeunload - notifying router of user disconnecting"),et.notifyDisconnecting&&et.notifyDisconnecting("close_tab")};return window.addEventListener("beforeunload",e),function(){window.removeEventListener("beforeunload",e)}}},[et]),Z.useEffect(function(){ee.visuals.opened?st(!0):"normal"!==ne||Ve||st(!1),rt&&it&&st(!0),at<+ot&&st(!1),Ve&&!Ze.current&&(Ze.current=!0,st(!0))},[at,rt,it,ot,st,ee.visuals.opened,ne,Ve]);var dt=Z.useCallback(function(){Ge.current&&(Xe.current&&(clearTimeout(Xe.current),Xe.current=null),X(ym(!1)),Ye(!1),Ge.current=!1)},[X]),ft=Z.useCallback(function(){Ge.current||(X(ym(!0)),Ye(!0),Ge.current=!0),Xe.current&&clearTimeout(Xe.current),Xe.current=window.setTimeout(function(){dt()},2e3)},[X,dt]);var pt=wb();function ht(e){oe||("offline"!==ee.accountStatus||ee.isChatting)&&e&&(dt(),et.flush(),X(gm(e)))}function mt(){G({type:"reset"})}function vt(){te.current.style.display="none"}function gt(){G(fb({opened:!1,hasInteracted:!0})),st(!1)}function yt(){G(fb({opened:!0,hasInteracted:!0})),st(!0),setTimeout(function(){var e;null===(e=document.getElementById("chatWidgetInput"))||void 0===e||e.focus({preventScroll:!0})},100)}function bt(){G(fb({hasInteracted:!0}))}var wt=Z.useState(!1),xt=wt[0],kt=wt[1],St=Z.useState(null),Ct=St[0],_t=St[1],Et=Z.useCallback(function(e){$h(e.preselectChipLabel?{preselectChipLabel:e.preselectChipLabel}:void 0).then(function(t){t||(Yh("Form widget not available, showing modal fallback"),_t(e),kt(!0))})},[]),Nt=Z.useCallback(function(){kt(!1),_t(null)},[]);var It="offline"===ee.accountStatus&&!ee.isChatting,Tt=ee&&ee.chats;Yh('Rendering - accountStatus: "'.concat(ee.accountStatus,'", connectionStatus: "').concat(ee.connection.connectionStatus,'"'));var jt=e.config,Ot=e.onConnectionStatusChange,Pt=!0===(null===(N=null==jt?void 0:jt.actionBar)||void 0===N?void 0:N.enabled),At=Vw(),Rt=null!==(T=null===(I=null==jt?void 0:jt.actionBar)||void 0===I?void 0:I.buttons)&&void 0!==T?T:[],Mt=!(null==jt?void 0:jt.formWidgetKey)&&Rt.some(_x)&&!Rt.some(LS),Lt=Z.useState(function(){return Mt&&DS()}),Dt=Lt[0],Bt=Lt[1];Z.useEffect(function(){if(Mt&&!Dt){var e=0,t=setInterval(function(){e++,DS()?(Bt(!0),clearInterval(t)):e>=30&&clearInterval(t)},500);return function(){return clearInterval(t)}}},[Mt,Dt]);var zt=Z.useMemo(function(){var e=null==jt?void 0:jt.actionBar;return e&&Mt&&!Dt?t(t({},e),{buttons:e.buttons.filter(function(e){return!_x(e)})}):e},[null==jt?void 0:jt.actionBar,Mt,Dt]),Ut=Z.useMemo(function(){return Pt&&zt?Ex(zt.buttons,{chatDisabled:jt.disabled,formDisabled:At}):[]},[Pt,zt,null==jt?void 0:jt.disabled,At]),Ft=Pt&&Ut.length>0;$w(!It&&!e.preChatFormEnabled&&Ke&&!oe);var qt=ee.connection.connectionStatus;Z.useEffect(function(){Ot&&Ot(qt)},[qt,Ot]),Fw(null===(j=e.config)||void 0===j?void 0:j.middlewareUrl);var Ht=!At&&(!Pt||Ut.some(_x)),Wt=null!==(O=null==jt?void 0:jt.formWidgetKey)&&void 0!==O?O:Ut.map(LS).find(Boolean);Z.useEffect(function(){var e;Wt&&Ht&&(e=Wt)&&Hh(e).catch(function(e){console.warn("[chat-widget] Failed to preload form-widget script:",e)})},[Wt,Ht]),Z.useEffect(function(){if(Ft){var e=parseInt(document.body.getAttribute("data-xapp-action-bar-count")||"0",10);document.body.setAttribute("data-xapp-action-bar-count",String(e+1)),document.body.setAttribute("data-xapp-action-bar-enabled","true")}return function(){if(Ft){var e=parseInt(document.body.getAttribute("data-xapp-action-bar-count")||"0",10),t=Math.max(0,e-1);0===t?(document.body.removeAttribute("data-xapp-action-bar-enabled"),document.body.removeAttribute("data-xapp-action-bar-count")):document.body.setAttribute("data-xapp-action-bar-count",String(t))}}},[Ft]);var Vt=(null===(P=ee.agents["agent:robot"])||void 0===P?void 0:P.user)||(null==jt?void 0:jt.agent)||{nick:"agent:robot",avatarPath:jt.avatarUrl,display_name:"Agent"},$t=f.jsxs("div",{className:"widget-container ".concat(ae," ").concat(function(){var e;return Ke?"visible":(null===(e=ee.visuals)||void 0===e?void 0:e.hasInteracted)?"":"widget-container--initial-hidden"}()).concat(Ft?" widget-container--with-action-bar":"").concat(Me?" widget-container--popped":"").concat(Re?" widget-container--collapsed":""),children:[f.jsx(pS,{theme:null==jt?void 0:jt.theme}),!Ue&&f.jsx(uS,{accountStatus:ee.accountStatus,refreshOnClick:function(){jt.header.actions.refreshShowConfirmation?te.current.style.display="block":mt()},minimizeOnClick:Me?function(){Pe?ke(!0):_e(!1)}:gt,cancelOnClick:function(){(null==et?void 0:et.notifyDisconnecting)&&et.notifyDisconnecting("widget_close"),G({type:"reset"}),G(fb({opened:!1,hasInteracted:!0})),st(!1)},agent:Vt,canRefresh:qe,canMinimize:Me||He,canCancel:ze,config:null==jt?void 0:jt.header,menuConfig:jt.menu,debugMode:null===(M=null===(R=null===(A=e.config)||void 0===A?void 0:A.connection)||void 0===R?void 0:R.mcp)||void 0===M?void 0:M.debugMode,onSubmit:ht}),f.jsx(Jk,{visible:Ke,queuePosition:ee.queuePosition,isChatting:ee.isChatting,isOffline:It,messages:Tt,agents:ee.agents,agent:null==jt?void 0:jt.agent,lastRatingRequestTimestamp:ee.lastRatingRequestTimestamp,hasRating:ee.hasRating,visitorId:ee.visitorId,hasWsButton:!!ee.wsButton,messageMiddleware:e.messageMiddleware,textTypingStatusEnabled:null===(D=null===(L=e.config)||void 0===L?void 0:L.typingStatus)||void 0===D?void 0:D.textTypingStatusEnabled,disableAutoScroll:e.disableAutoScroll,onSend:function(e){oe||X(function(e){return function(t){return function(n,r){var i=r();("offline"!==i.accountStatus||i.isChatting)&&(e.msg&&n(vm(e.msg,i.visitor,+new Date)),t.sendChatMsgRequest(e,function(){}))}}}(e))},onWrite:function(e){oe||G(vm(e.msg,e.user))},onOpenUrl:pt,minimizeOnClick:gt}),f.jsx("div",{className:"xa-spinner-container ".concat(Ke&&"pending"===qt?"visible":""),children:f.jsx("div",{className:"xa-spinner"})}),"offline"===qt&&f.jsx(Yk,{}),ee.wsButton&&Ke&&f.jsx(IS,{button:ee.wsButton,onPress:function(e){var n,r;Yh("WS Button pressed: ".concat(e)),"spinning"===(null===(n=ee.wsButton)||void 0===n?void 0:n.pressBehavior)&&G({type:"ws_button_display",detail:t(t({},ee.wsButton),{isPressed:!0,timestamp:+new Date})}),et&&et.sendButtonPressed&&et.sendButtonPressed(e).catch(function(e){Gh("Failed to send button press: ".concat(e)),ee.wsButton&&G({type:"ws_button_display",detail:t(t({},ee.wsButton),{isPressed:!1,timestamp:+new Date})})}),"disabled"===(null===(r=ee.wsButton)||void 0===r?void 0:r.pressBehavior)&&(G({type:"ws_button_display",detail:t(t({},ee.wsButton),{isDismissing:!0,timestamp:+new Date})}),setTimeout(function(){G({type:"ws_button_dismiss",detail:{id:e,timestamp:+new Date}})},300))}}),f.jsx(Zx,{isAdmin:null==jt?void 0:jt.isAdmin,isChatting:ee.isChatting,placeholder:null===(B=null==jt?void 0:jt.input)||void 0===B?void 0:B.placeholder,sendButtonIcon:null===(U=null===(z=null==jt?void 0:jt.footer)||void 0===z?void 0:z.sendButton)||void 0===U?void 0:U.icon,sendButtonIconHover:null===(q=null===(F=null==jt?void 0:jt.footer)||void 0===F?void 0:F.sendButton)||void 0===q?void 0:q.iconHover,sendButtonIconDisabled:null===(W=null===(H=null==jt?void 0:jt.footer)||void 0===H?void 0:H.sendButton)||void 0===W?void 0:W.iconDisabled,visible:Ke,hasWsButton:!!ee.wsButton,menuConfig:Fe,footerConfig:null===(V=e.config)||void 0===V?void 0:V.footer,inputConfig:null===($=e.config)||void 0===$?void 0:$.input,disabled:oe,onChange:ft,onSubmit:ht,onFileUpload:function(e){var t;if(e.preventDefault(),!oe){var n=null===(t=null==e?void 0:e.dataTransfer)||void 0===t?void 0:t.files[0];n&&X(function(e){return function(t){return function(n,r){var i=r();if("offline"!==i.accountStatus||i.isChatting){var o={mimeType:e.type,name:e.name,size:e.size,url:window.URL.createObjectURL(e)};t.sendFile(e,function(e){e&&Yh("Error sending file",e)}),n({type:"synthetic",detail:{type:"visitor.send.file",attachment:o,user:{nick:""},attributes:{currentUrl:window.location.href},timestamp:+new Date}})}}}}(n))}}}),f.jsx("div",{className:"restartModal",ref:te,onClick:vt,children:f.jsx(TS,{onClose:vt,onReset:mt})})]});return f.jsxs(f.Fragment,{children:[de?f.jsx("div",{className:"widget-anchor",ref:pe,children:De&&ue.createPortal($t,De)}):$t,!Ft||!zt||Re&&"button"===Ae?f.jsx(zx,{addClass:Ke&&!Re?"visible":"",onClick:Re?Le:yt,config:ce,imageUrl:null===(J=null==jt?void 0:jt.chatButton)||void 0===J?void 0:J.imageUrl,visible:!Re&&Ke,hasInteracted:null===(Y=ee.visuals)||void 0===Y?void 0:Y.hasInteracted,onCtaDismiss:bt}):f.jsxs(f.Fragment,{children:[f.jsx(Nx,{config:t(t({},zt),{cta:gb(null!==(K=zt.cta)&&void 0!==K?K:jt.cta,{hasConversation:le,arrivedViaChatLink:se})}),visible:!Re&&Ke,chatDisabled:jt.disabled,formDisabled:At,hasUserInteracted:null===(Q=ee.visuals)||void 0===Q?void 0:Q.hasInteracted,onChatClick:Re?Le:yt,onChatMinimize:gt,onFormClick:Et,onCtaDismiss:bt}),xt&&Ct&&f.jsx(ek,{config:Ct,widgetEnv:jt,onClose:Nt})]}),f.jsx(NS,{enableErrorOverlay:null==jt?void 0:jt.enableErrorOverlay})]})},zS=function(e){var n,r=null!==(n=e.mode)&&void 0!==n?n:"normal",i="preview"===r?"static":r;return!0===e.preview||"preview"===r?f.jsx(RS,t({},e,{mode:i})):f.jsx(MS,t({},e))},US=function(e){var n=ow(),r=t(t({},e),{messageMiddleware:n});return f.jsx(zS,t({},r))},FS=function(e){var n,r,i,o,a,s,l=ow(),c=om(e.config),u=Z.useMemo(function(){var t,n,r,i,o;return Dw({connection:c,userId:null===(t=e.config)||void 0===t?void 0:t.userId,accessToken:null===(n=e.config)||void 0===n?void 0:n.accessToken,attributes:null===(r=e.config)||void 0===r?void 0:r.attributes,sessionExpiration:null===(i=e.config)||void 0===i?void 0:i.sessionExpiration,enableErrorOverlay:null===(o=e.config)||void 0===o?void 0:o.enableErrorOverlay})},[c,null===(n=e.config)||void 0===n?void 0:n.userId,null===(r=e.config)||void 0===r?void 0:r.accessToken,null===(i=e.config)||void 0===i?void 0:i.attributes,null===(o=e.config)||void 0===o?void 0:o.sessionExpiration,null===(a=e.config)||void 0===a?void 0:a.enableErrorOverlay]);if(null===(s=e.config)||void 0===s?void 0:s.disabled)return f.jsx(f.Fragment,{});var d=t(t({},e),{messageMiddleware:l,getConfig:e.getConfig});return f.jsx(_h,{store:u,children:f.jsx(zS,t({},d))})},qS=function(e){var n,r=null!==(n=e.mode)&&void 0!==n?n:"normal";return!0===e.preview||"preview"===r?f.jsx(US,t({},e)):f.jsx(FS,t({},e))};function HS(e){return e.split("-").map(function(e,t){return e.length?t?e[0].toUpperCase()+e.substring(1).toLowerCase():e.toLowerCase():""}).join("")}function WS(e){return Object.keys(e).reduce(function(t,n){var r=n,i="string";n.endsWith("-FLAG")?(r=n.substring(0,n.length-5),i="boolean"):n.endsWith("-MSEC")&&(r=n.substring(0,n.length-5),i="number");for(var o=r.split("_").map(HS),a=t;o.length>1;){var s=o.shift();"object"==typeof a&&(a[s]||(a[s]={}),a=a[s])}return"object"==typeof a&&(a[o.shift()]=function(e,t){return"string"===t?e:"boolean"===t?"TRUE"===e:"number"===t?parseFloat(e):e}(e[n],i)),t},{})}function VS(e,n){if(!n)return e;var r=t({},e);for(var o in n)if(n.hasOwnProperty(o)){var a=n[o],s=r[o];if(void 0===a)continue;null===a?r[o]=a:Array.isArray(a)?r[o]=i([],a,!0):"object"!=typeof a||Array.isArray(a)?r[o]=a:s&&"object"==typeof s&&!Array.isArray(s)?r[o]=VS(s,a):r[o]=t({},a)}return r}function $S(e){try{return localStorage.getItem(e)||void 0}catch(e){return}}function KS(){var e=$S(xg),t=$S(wg);if(!t){t=function(){var e=new Uint8Array(8);try{crypto.getRandomValues(e)}catch(t){e.forEach(function(t,n){return e[n]=Math.floor(256*Math.random())})}var t=Array.from(e,function(e){return e.toString(16).padStart(2,"0")}).join("");return"usr_".concat(Date.now().toString(36)).concat(t)}();try{localStorage.setItem(wg,t)}catch(e){}}return{sessionId:e,userId:t}}function QS(e){return"mcp"===im(e).type?KS():function(e){var t;try{var n=im(e),r="xappchat.".concat(n.serverUrl),i=$S(n.accountKey?"".concat(r,".").concat(n.accountKey):r);t=i?JSON.parse(i):void 0}catch(e){t=void 0}return{sessionId:"string"==typeof(null==t?void 0:t.sessionId)?t.sessionId:void 0,userId:"string"==typeof(null==t?void 0:t.userId)?t.userId:_w()}}(e)}function JS(){try{var e="1.108.0";return e||void 0}catch(e){return}}function YS(e){var t=function(){try{var e=document.getElementById("xapp-js");return(null==e?void 0:e.src)||void 0}catch(e){return}}();return Jv({eventsUrl:Gv(im(e).serverUrl),key:Xh().key||void 0,widgetType:"chat",source:"chat-widget",version:JS(),bundles:t?[t]:[],metadata:function(){var t=QS(e);return{sessionId:t.sessionId||"unknown",userId:t.userId}}})}var GS="{{INJECT}}";function XS(e){var t=e||GS;try{var n=JSON.parse(t),r=window.xaConfig||{};window.xaConfig=VS(n,r)}catch(e){t!==GS&&Gh("Chat Widget: injected config could not be parsed",{injected:t,error:e})}}function ZS(){return n(this,arguments,void 0,function(e){var t;return void 0===e&&(e=1e4),r(this,function(n){switch(n.label){case 0:t=Date.now(),n.label=1;case 1:return tC(window)?[3,3]:Date.now()-t>e?(console.warn("[xapp-chat-widget] Timeout waiting for window.xaConfig"),[2,{}]):[4,new Promise(function(e){return setTimeout(e,50)})];case 2:return n.sent(),[3,1];case 3:return[2,window.xaConfig]}})})}function eC(){var e=WS(process.env),n="true"===new URL(window.location.href).searchParams.get("isAdmin"),r=tC(window)?window.xaConfig:{};return t(t(t(t({},e),{isAdmin:n}),r),{attributes:t(t({},null==e?void 0:e.attributes),null==r?void 0:r.attributes)})}function tC(e){return!!e&&null!=e.xaConfig&&"object"==typeof e.xaConfig}var nC="chat-config-error";var rC=function(e){var t,n=e.env,r=function(){var e=Z.useState(!1),t=e[0],n=e[1];return Z.useEffect(function(){if(!document.getElementById("xapp-style")){var e=Xh(),t=document.createElement("link");t.id="xapp-style",t.href="".concat(e.path,"/xapp-chat-widget.css"),t.rel="stylesheet",document.head.appendChild(t),t.addEventListener("load",function(){n(!0)})}},[]),[t]}()[0];if(n.disabled)return f.jsx(f.Fragment,{});var i=n.mode,o=null===(t=window.xaConfig)||void 0===t?void 0:t.getConfig;return r?f.jsx(qS,{config:n,mode:i,getConfig:o}):f.jsx(f.Fragment,{})},iC=!1,oC=null;function aC(){return n(this,void 0,void 0,function(){var e,n,i;return r(this,function(r){switch(r.label){case 0:if(iC)return[2];iC=!0,r.label=1;case 1:return r.trys.push([1,,4,5]),XS(),tC(window)||window.xaSkipConfigWait?[3,3]:[4,ZS()];case 2:r.sent(),r.label=3;case 3:if(!function(e,t){return void 0===t&&(t={}),!!(null==e?void 0:e.disabled)||!!t.hasAsyncConfigLoader||!!sm(e).serverUrl}(e=eC(),{hasAsyncConfigLoader:!!(null===(i=window.xaConfig)||void 0===i?void 0:i.getConfig)}))return Gh("Chat Widget: not rendering, the configuration has no server URL",function(e){var t=sm(e);return{serverUrl:t.serverUrl,accountKey:t.accountKey,connectionType:t.type}}(e)),function(){if("debug"===window.xaLogLevel&&!document.getElementById(nC)){var e=document.createElement("div");e.id=nC,e.textContent="Chat Load Error",e.style.cssText="\n position: fixed;\n bottom: 20px;\n right: 20px;\n background-color: #f44336;\n color: white;\n padding: 12px 16px;\n border-radius: 4px;\n font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;\n font-size: 14px;\n font-weight: 500;\n z-index: 10000;\n box-shadow: 0 2px 8px rgba(0,0,0,0.2);\n transition: opacity ".concat(300,"ms ease-in-out;\n "),document.body.appendChild(e),setTimeout(function(){e.style.opacity="0",setTimeout(function(){return e.remove()},300)},2e3)}}(),[2];(n=document.getElementById("xapp-widget"))||((n=document.createElement("div")).id="xapp-widget",document.body.appendChild(n));try{YS(e)}catch(e){}return oC||(oC=ah.createRoot(n)),oC.render(f.jsx(rC,{env:e})),function(e){try{var n=Zv({mcp:e.disabled?void 0:e,notice:!0===e.agentNotice,siteTools:!0===e.webmcp,channelId:e.channelId}).verdict;if(!Vv("chat"))return;var r=QS(e),i=r.sessionId,o=r.userId,a=Wv({pageUrl:window.location.href,referrer:document.referrer,nav:navigator,verdict:n,screen:window.screen,viewport:{width:window.innerWidth,height:window.innerHeight}});Xv({eventsUrl:Gv(im(e).serverUrl),key:Xh().key||void 0,widgetType:"chat",metadata:t({sessionId:i||"unknown",userId:o},a)})}catch(e){}}(e),[3,5];case 4:return iC=!1,[7];case 5:return[2]}})})}return window.addEventListener("load",function(){aC()}),"complete"===document.readyState&&aC(),e.ChatMessagePart=mm,e.INJECT_PLACEHOLDER=GS,e.React=ee,e.injectConfig=XS,e.renderWidget=aC,e}({});
7
+ n(Qw,e),n(Jw,e),n(sx,e),n(Yw,e),n(lx,e),n(cx,e),n(ux,e),n(dx,e),n(fx,e),n(px,e)}(Kw);var hx=function(){return f.jsx("svg",{width:"24",height:"24",viewBox:"0 0 24 24",fill:"currentColor",children:f.jsx("path",{d:"M19 4h-1V2h-2v2H8V2H6v2H5c-1.11 0-1.99.9-1.99 2L3 20c0 1.1.89 2 2 2h14c1.1 0 2-.9 2-2V6c0-1.1-.9-2-2-2zm0 16H5V10h14v10zm0-12H5V6h14v2zM9 14H7v-2h2v2zm4 0h-2v-2h2v2zm4 0h-2v-2h2v2zm-8 4H7v-2h2v2zm4 0h-2v-2h2v2zm4 0h-2v-2h2v2z"})})},mx=function(){return f.jsx("svg",{width:"24",height:"24",viewBox:"0 0 24 24",fill:"currentColor",children:f.jsx("path",{d:"M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76 0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71 0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71 0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76 0 5-2.24 5-5s-2.24-5-5-5z"})})},vx=function(){return f.jsx("svg",{width:"24",height:"24",viewBox:"0 0 24 24",fill:"currentColor",children:f.jsx("path",{d:"M12 2C6.48 2 2 6.48 2 12s4.48 10 10 10 10-4.48 10-10S17.52 2 12 2zm1 15h-2v-2h2v2zm0-4h-2V7h2v6z"})})},gx={chat:function(){return f.jsx("svg",{width:"24",height:"24",viewBox:"0 0 24 24",fill:"currentColor",children:f.jsx("path",{d:"M20 2H4c-1.1 0-2 .9-2 2v18l4-4h14c1.1 0 2-.9 2-2V4c0-1.1-.9-2-2-2zm0 14H6l-2 2V4h16v12z"})})},form:function(){return f.jsx("svg",{width:"24",height:"24",viewBox:"0 0 24 24",fill:"currentColor",children:f.jsx("path",{d:"M14 2H6c-1.1 0-2 .9-2 2v16c0 1.1.9 2 2 2h12c1.1 0 2-.9 2-2V8l-6-6zM6 20V4h7v5h5v11H6zm2-6h8v2H8v-2zm0-3h8v2H8v-2zm0 6h5v2H8v-2z"})})},calendar:hx,schedule:hx,phone:function(){return f.jsx("svg",{width:"24",height:"24",viewBox:"0 0 24 24",fill:"currentColor",children:f.jsx("path",{d:"M6.62 10.79c1.44 2.83 3.76 5.14 6.59 6.59l2.2-2.2c.27-.27.67-.36 1.02-.24 1.12.37 2.33.57 3.57.57.55 0 1 .45 1 1V20c0 .55-.45 1-1 1-9.39 0-17-7.61-17-17 0-.55.45-1 1-1h3.5c.55 0 1 .45 1 1 0 1.25.2 2.45.57 3.57.11.35.03.74-.25 1.02l-2.2 2.2z"})})},link:mx,url:mx,email:function(){return f.jsx("svg",{width:"24",height:"24",viewBox:"0 0 24 24",fill:"currentColor",children:f.jsx("path",{d:"M20 4H4c-1.1 0-1.99.9-1.99 2L2 18c0 1.1.9 2 2 2h16c1.1 0 2-.9 2-2V6c0-1.1-.9-2-2-2zm0 4l-8 5-8-5V6l8 5 8-5v2z"})})},help:function(){return f.jsx("svg",{width:"24",height:"24",viewBox:"0 0 24 24",fill:"currentColor",children:f.jsx("path",{d:"M12 2C6.48 2 2 6.48 2 12s4.48 10 10 10 10-4.48 10-10S17.52 2 12 2zm1 17h-2v-2h2v2zm2.07-7.75l-.9.92C13.45 12.9 13 13.5 13 15h-2v-.5c0-1.1.45-2.1 1.17-2.83l1.24-1.26c.37-.36.59-.86.59-1.41 0-1.1-.9-2-2-2s-2 .9-2 2H8c0-2.21 1.79-4 4-4s4 1.79 4 4c0 .88-.36 1.68-.93 2.25z"})})},payment:function(){return f.jsx("svg",{width:"24",height:"24",viewBox:"0 0 24 24",fill:"currentColor",children:f.jsx("path",{d:"M20 4H4c-1.11 0-1.99.89-1.99 2L2 18c0 1.11.89 2 2 2h16c1.11 0 2-.89 2-2V6c0-1.11-.89-2-2-2zm0 14H4v-6h16v6zm0-10H4V6h16v2z"})})}},yx=function(e){var t=e.type,n=e.icon,r=e.iconUrl,i=e.className;if(r)return f.jsx("div",{className:i,children:f.jsx("img",{src:r,alt:"".concat(n||t," icon")})});var o=gx[n||t]||vx;return f.jsx("div",{className:i,children:f.jsx(o,{})})},bx=["http:","https:","tel:","mailto:"];function wx(e,t,n){if(!function(e){try{var t=new URL(e,window.location.href);return bx.includes(t.protocol)}catch(e){return!1}}(e))return console.warn("[ActionBar] Blocked navigation to unsafe URL:",e),!1;if("sameWindow"===t)window.location.href=e;else if("newWindow"===t&&n){var r="width=".concat(n.width||600,",height=").concat(n.height||400);window.open(e,"_blank",r)}else window.open(e,"_blank","noopener,noreferrer");return!0}var xx={chat:"Chat",form:"Contact",schedule:"Book",phone:"Call",url:"Link",email:"Email",help:"Help",payment:"Pay"},kx=function(e){var t,n=e.button,r=e.chatActive,i=e.onChatClick,o=e.onChatMinimize,a=e.onFormClick,s=e.isMobile,l=Z.useCallback(function(){if(Kw.isActionBarChatButton(n))r?o():i();else if(Kw.isActionBarFormButton(n)||Kw.isActionBarScheduleButton(n))a(n);else if(Kw.isActionBarPhoneButton(n)){var e=n.phoneNumber.replace(/\s/g,"");window.location.href="tel:".concat(e)}else if(Kw.isActionBarUrlButton(n)){var t=n.url,s=n.target;wx(t,void 0===s?"newTab":s,n.windowOptions)}else if(Kw.isActionBarEmailButton(n)){var l=n.emailAddress,c=n.subject,u=n.body,d="mailto:".concat(l),f=[];c&&f.push("subject=".concat(encodeURIComponent(c))),u&&f.push("body=".concat(encodeURIComponent(u))),f.length>0&&(d+="?".concat(f.join("&"))),window.location.href=d}else if(Kw.isActionBarHelpButton(n)){t=n.url;var p=n.target;wx(t,void 0===p?"newTab":p)}else if(Kw.isActionBarPaymentButton(n)){t=n.url;var h=n.target;wx(t,void 0===h?"newTab":h)}},[n,r,i,o,a]),c=n.visibility||"all";if("mobile-only"===c&&!s)return null;if("desktop-only"===c&&s)return null;var u=n.label||xx[n.type]||n.type,d=null!==(t=n.tabIndex)&&void 0!==t?t:0,p=Kw.isActionBarChatButton(n)&&r,h=["xapp-action-bar__button",p?"xapp-action-bar__button--active":""].filter(Boolean).join(" ");return f.jsxs("button",{className:h,onClick:l,"aria-label":u,"aria-pressed":p,tabIndex:d,children:[f.jsx(yx,{type:n.type,icon:n.icon,iconUrl:n.iconUrl,className:"xapp-action-bar__icon"}),n.label&&f.jsx("span",{className:"xapp-action-bar__label",children:n.label})]})},Sx=function(e){var t,n,r,i,o,a,s,l,c,u,d=e.config,p=e.isMobile,h=e.onClick,m=e.onDismiss,v=e.hasUserInteracted,g=Z.useState(!1),y=g[0],b=g[1],w=Z.useState(!1),x=w[0],k=w[1],S=Z.useState(!1),C=S[0],_=S[1],E=p?null===(t=d.mobile)||void 0===t?void 0:t.message:void 0,N=void 0!==E?E:d.message,I=p&&void 0!==(null===(n=d.mobile)||void 0===n?void 0:n.delay)?d.mobile.delay:null!==(r=d.delay)&&void 0!==r?r:0,T=p?null===(i=d.mobile)||void 0===i?void 0:i.timeout:void 0,j=void 0!==T?T:d.timeout,O=p?null===(o=d.mobile)||void 0===o?void 0:o.animation:void 0,P=void 0!==O?O:d.animation,A=p&&void 0!==(null===(a=d.mobile)||void 0===a?void 0:a.animationDelay)?d.mobile.animationDelay:null!==(s=d.animationDelay)&&void 0!==s?s:I,R=p&&void 0!==(null===(l=d.mobile)||void 0===l?void 0:l.animationTimeout)?d.mobile.animationTimeout:d.animationTimeout,M=p&&void 0!==(null===(c=d.mobile)||void 0===c?void 0:c.dismissible)?d.mobile.dismissible:null===(u=d.dismissible)||void 0===u||u;Z.useEffect(function(){if(N&&!v&&!C){var e=setTimeout(function(){b(!0)},I);return function(){return clearTimeout(e)}}b(!1)},[N,I,v,C]),Z.useEffect(function(){if(y&&j){var e=setTimeout(function(){b(!1)},j);return function(){return clearTimeout(e)}}},[y,j]),Z.useEffect(function(){if(P&&!v&&!C){var e=setTimeout(function(){k(!0)},A);return function(){return clearTimeout(e)}}k(!1)},[P,A,v,C]),Z.useEffect(function(){if(x&&R){var e=setTimeout(function(){k(!1)},R);return function(){return clearTimeout(e)}}},[x,R]);var L=function(){h(),b(!1)};if(!y||!N)return null;var D=x&&P?"xapp-action-bar-cta--".concat(P):"";return f.jsxs("div",{className:"xapp-action-bar-cta ".concat(D),onClick:L,role:"button",tabIndex:0,"aria-label":N,onKeyDown:function(e){"Enter"!==e.key&&" "!==e.key||(e.preventDefault(),L())},children:[f.jsx("span",{className:"xapp-action-bar-cta__message",children:N}),M&&f.jsx("button",{className:"xapp-action-bar-cta__dismiss",onClick:function(e){e.stopPropagation(),_(!0),b(!1),m()},"aria-label":"Dismiss",type:"button",children:f.jsx("svg",{width:"14",height:"14",viewBox:"0 0 14 14",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:f.jsx("path",{d:"M13 1L1 13M1 1L13 13",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"})})})]})},Cx="--xapp-action-bar-height";function _x(e){return Kw.isActionBarFormButton(e)||Kw.isActionBarScheduleButton(e)}function Ex(e,t){void 0===e&&(e=[]),void 0===t&&(t={});var n=t.chatDisabled,r=t.formDisabled;return e.filter(function(e){return(!n||!Kw.isActionBarChatButton(e))&&(!r||!_x(e))})}var Nx=function(e){var t,n,r=e.config,i=e.visible,o=e.chatDisabled,a=e.formDisabled,s=e.hasUserInteracted,l=void 0!==s&&s,c=e.onChatClick,u=e.onChatMinimize,d=e.onFormClick,p=e.onCtaDismiss,h=Z.useState(!1),m=h[0],v=h[1],g=null!=r.mobileBreakpoint?"(max-width: ".concat(r.mobileBreakpoint,"px)"):yb,y=null!==(t=r.position)&&void 0!==t?t:"right",b=Z.useRef(null);Z.useEffect(function(){if("function"==typeof window.matchMedia){var e=window.matchMedia(g);v(e.matches);var t=function(e){v(e.matches)};return"function"==typeof e.addEventListener?(e.addEventListener("change",t),function(){return e.removeEventListener("change",t)}):(e.addListener(t),function(){return e.removeListener(t)})}},[g]),Z.useLayoutEffect(function(){var e=b.current;if(e){var t=function(){var t=e.getBoundingClientRect().height;t<=0||document.documentElement.style.setProperty(Cx,"".concat(t,"px"))};if(t(),"undefined"==typeof ResizeObserver)return function(){document.documentElement.style.removeProperty(Cx)};var n=new ResizeObserver(t);return n.observe(e),function(){n.disconnect(),document.documentElement.style.removeProperty(Cx)}}},[m]);var w=Ex(r.buttons,{chatDisabled:o,formDisabled:a}),x=["xapp-action-bar","xapp-action-bar--".concat(y),m?"xapp-action-bar--mobile":"xapp-action-bar--desktop"].filter(Boolean).join(" "),k=w.some(Kw.isActionBarChatButton),S=(null===(n=r.cta)||void 0===n?void 0:n.message)&&!i&&!o&&k;return 0===w.length?null:f.jsxs("div",{ref:b,className:x,role:"toolbar","aria-label":"Chat actions",children:[S&&f.jsx("div",{className:"xapp-action-bar-cta-wrapper",children:f.jsx(Sx,{config:r.cta,isMobile:m,onClick:function(){c()},onDismiss:function(){null==p||p()},hasUserInteracted:l})}),f.jsx("div",{className:"xapp-action-bar__buttons",children:w.map(function(e){return f.jsx(kx,{button:e,chatActive:i,onChatClick:c,onChatMinimize:u,onFormClick:d,isMobile:m},e.id)})})]})};function Ix(){var e=Z.useRef(null),t=Z.useState(),n=t[0],r=t[1];return Z.useLayoutEffect(function(){var t,n;r(null===(n=null===(t=e.current)||void 0===t?void 0:t.getBoundingClientRect())||void 0===n?void 0:n.toJSON())},[]),[e,n]}function Tx(e,t){return{x:e.x+t.x,y:e.y+t.y}}function jx(e,t){return{x:e.x-t.x,y:e.y-t.y}}function Ox(e,t){return{x:e.x*t,y:e.y*t}}function Px(e){return Math.sqrt(e.x*e.x+e.y*e.y)}function Ax(e,t){var n=t*Math.PI/180,r=Math.cos(n),i=Math.sin(n);return{x:e.x*r+e.y*i,y:e.y*r-e.x*i}}function Rx(e,t){var n=jx(t.start,e.center),r=n.x,i=n.y,o=t.direction.x,a=t.direction.y,s=e.radius.x,l=e.radius.y,c=s*s,u=l*l,d=o*o/c+a*a/u,f=2*o*r/c+2*a*i/u,p=f*f-4*d*(r*r/c+i*i/u-1);if(p>=0){var h=Math.sqrt(p),m=(-f-h)/(2*d),v=(-f+h)/(2*d);if(m>0&&v>0)return Tx(t.start,Ox(t.direction,Math.min(m,v)));if(m>0)return Tx(t.start,Ox(t.direction,m));if(v>0)return Tx(t.start,Ox(t.direction,v))}return t.start}function Mx(e,t){var n,r,i,o=e.direction*Math.PI/180,a={x:e.width/2,y:e.height/2},s={x:t.x/2,y:t.y/2},l={x:a.x*Math.cos(o),y:a.y*Math.sin(o)},c=(n=l,r=Px(l)+e.length,(i=Px(n))?Ox(n,r/i):n),u=Tx(c,s),d=jx(l,c),f=e.angle,p=Ax(d,f/2),h=Ax(d,-f/2),m={center:s,radius:a},v=Rx(m,{start:u,direction:p}),g=Rx(m,{start:u,direction:h});return"m ".concat(u.x," ").concat(u.y," L ").concat(v.x," ").concat(v.y," L ").concat(g.x," ").concat(g.y," z")}var Lx=function(e){var t,n,r=Ix(),i=r[0],o=r[1],a={x:null!==(t=null==o?void 0:o.width)&&void 0!==t?t:0,y:null!==(n=null==o?void 0:o.height)&&void 0!==n?n:0};return f.jsx("div",{ref:i,className:"cta-bubble__tail",children:f.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 ".concat(a.x," ").concat(a.y),children:f.jsx("path",{d:Mx(e,a),fill:"currentColor"})})})},Dx=function(e){var t,n,r,i,o=Ix(),a=o[0],s=o[1],l=(e.animate||!1)&&"bounce"===e.buttonAnimation?"bounce":"none";return console.log("Returning CTABubble with message: ",e.children),f.jsxs("div",{ref:a,style:{border:e.borderStyle?"solid":"none",borderWidth:(null===(t=e.borderStyle)||void 0===t?void 0:t.width)||"0px",borderColor:(null===(n=e.borderStyle)||void 0===n?void 0:n.color)||"transparent",animation:"".concat(l," 1s infinite")},className:"cta-bubble",onClick:e.onClick,children:[f.jsx(Lx,{width:null!==(r=null==s?void 0:s.width)&&void 0!==r?r:0,height:null!==(i=null==s?void 0:s.height)&&void 0!==i?i:0,direction:60,angle:45,length:16}),f.jsx("div",{className:"cta-bubble__content",children:e.children}),e.dismissible&&f.jsx("button",{className:"cta-bubble__dismiss",onClick:function(t){t.stopPropagation(),e.onDismiss&&e.onDismiss()},"aria-label":"Dismiss",children:f.jsx("svg",{width:"12",height:"12",viewBox:"0 0 12 12",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:f.jsx("path",{d:"M11 1L1 11M1 1L11 11",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"})})})]})},Bx=function(e){var t=e.visible,n=e.timeout,r=e.delay,i=e.animate,o=e.buttonAnimation,a=e.dismissible,s=e.onClick,l=e.onDismiss,c=e.children;Yh("[CtaBubbleContainer] Props received:",{visible:t,timeout:n,delay:r,animate:i,buttonAnimation:o,dismissible:a,hasOnClick:!!s,hasOnDismiss:!!l,hasChildren:!!c,childrenContent:c});var u=Z.useMemo(function(){var e=t?(new Date).valueOf():void 0;return Yh("[CtaBubbleContainer] StartTime calculated: visible=".concat(t,", startTime=").concat(e)),e},[t]),d=Z.useState(!1),p=d[0],h=d[1];Yh("[CtaBubbleContainer] Current state: showBubble=".concat(p)),Z.useEffect(function(){Yh("[CtaBubbleContainer] useEffect triggered with:",{startTime:u,startTimeExists:!!u,timeout:n,timeoutType:typeof n,delay:r,delayType:typeof r,visible:t});var e=null,i=null,o=!0;if(u){var a=r||0;Yh("[CtaBubbleContainer] Timer setup: actualDelay=".concat(a,"ms (from delay=").concat(r,")")),i=setTimeout(function(){Yh("[CtaBubbleContainer] Delay timer fired after ".concat(a,"ms, isMounted=").concat(o)),o?(Yh("[CtaBubbleContainer] Component still mounted, setting showBubble=true"),h(!0),"number"==typeof n?(Yh("[CtaBubbleContainer] Hide timer setup: will hide after ".concat(n,"ms")),e=setTimeout(function(){Yh("[CtaBubbleContainer] Hide timer fired after ".concat(n,"ms, isMounted=").concat(o)),o?(Yh("[CtaBubbleContainer] Component still mounted, setting showBubble=false"),h(!1)):Yh("[CtaBubbleContainer] Component unmounted, skipping hide")},n)):Yh("[CtaBubbleContainer] No hide timer set (timeout=".concat(n,", type=").concat(typeof n,")"))):Yh("[CtaBubbleContainer] Component unmounted before delay timer, not showing bubble")},a)}else Yh("[CtaBubbleContainer] No startTime, skipping timer setup");return function(){Yh("[CtaBubbleContainer] Cleanup triggered, unmounting component"),o=!1,e&&(Yh("[CtaBubbleContainer] Clearing hide timer"),clearTimeout(e)),i&&(Yh("[CtaBubbleContainer] Clearing delay timer"),clearTimeout(i))}},[u,n,r,t]);var m=t&&p;return Yh("[CtaBubbleContainer] Render decision: visible=".concat(t,", showBubble=").concat(p,", shouldRender=").concat(m)),f.jsx(f.Fragment,{children:t&&p&&f.jsx(Dx,{onClick:s,animate:i,buttonAnimation:o,dismissible:a,onDismiss:function(){Yh("[CtaBubbleContainer] handleDismiss called, setting showBubble=false"),h(!1),l&&(Yh("[CtaBubbleContainer] Calling onDismiss callback"),l())},children:c})})},zx=function(e){var t,n=e.onClick,r=e.addClass,i=e.config,o=e.visible,a=e.borderStyle,s=e.imageUrl,l=e.hasInteracted,c=e.onCtaDismiss,u=Z.useState(em),d=u[0],p=u[1],h=Z.useState(!1),m=h[0],v=h[1],g=(null===(t=null==i?void 0:i.mobile)||void 0===t?void 0:t.applyAtLessThanWidth)||"400",y=window.innerWidth<=parseInt(g,10)&&(null==i?void 0:i.mobile)?i.mobile:i;Z.useEffect(function(){var e,t,n;if(l)return v(!1),function(){};var r=null!==(e=null==y?void 0:y.animationDelay)&&void 0!==e?e:null==y?void 0:y.delay;return r?t=setTimeout(function(){v(!0),y.animationTimeout&&(n=setTimeout(function(){v(!1)},y.animationTimeout))},r):(null==y?void 0:y.animationTimeout)?(v(!0),n=setTimeout(function(){v(!1)},y.animationTimeout)):(null==y?void 0:y.animation)&&v(!0),function(){t&&clearTimeout(t),n&&clearTimeout(n)}},[y,v,l]);var b=m&&!l?(null==y?void 0:y.animation)||"wiggle":"none";Z.useEffect(function(){var e=function(){var e=window.innerWidth<parseInt(g,10)?"30":em;p(e)};return e(),window.addEventListener("resize",e),function(){window.removeEventListener("resize",e)}},[g]);var w=Math.min(22,+d/48*22);return f.jsxs("button",{"aria-label":"open chat",className:"xapp-chat-button ".concat(r||"").trim(),onClick:n,children:[f.jsx("div",{id:"xapp-widget-button",className:"xapp-chat-button__btn",style:{width:"".concat(d,"px"),height:"".concat(d,"px"),borderRadius:"".concat(+d/2,"px"),border:a&&a.width?"solid":"none",borderWidth:(null==a?void 0:a.width)||"0px",borderColor:(null==a?void 0:a.color)||"transparent",animation:"".concat(b," 1s infinite")},children:s?f.jsx("img",{src:s,alt:"Chat Icon"}):f.jsx("svg",{width:w,height:w,viewBox:"0 0 22 22",children:f.jsx("path",{d:"M13 22l-4-6H2c-1.11-.043-2-.935-2-2V2C0 .89.89 0 2 0h18c1.11 0 2 .892 2 2v12c0 1.067-.89 1.957-2 2h-3l-4 6zm3-8h4c-.005.3-.01-12 0-12-.01.004-18 .006-18 0 .005.006 0 12 0 12h8l3 5 3-5z",fill:"#FFF",fillRule:"evenodd"})})}),y&&y.message&&!l&&f.jsx("div",{className:"xapp-chat-button__cta",children:f.jsx(Bx,{timeout:null==y?void 0:y.timeout,delay:null==y?void 0:y.delay,animate:m,buttonAnimation:b,dismissible:null==y?void 0:y.dismissible,visible:!o,onDismiss:c,children:null==y?void 0:y.message})})]})};function Ux(e,t){var n=Z.useState(),r=n[0],i=n[1],o=Z.useState(-1),a=o[0],s=o[1],l=Z.useState(e),c=l[0],u=l[1],d=Z.useState(t),f=d[0],p=d[1];Z.useEffect(function(){u(e)},[e]),Z.useEffect(function(){p(t)},[t]);var h=Z.useMemo(function(){return r?$v(r,a):void 0},[r,a]),m=Z.useCallback(function(e){if(r){var t=Qv(r);s(function(n){return function(e,t){return(e+t)%t}(n+e+(n<0&&e<=0?1:0),t)})}else s(-1)},[r]),v=Z.useCallback(function(e){switch(e){case"prev":m(-1);break;case"next":m(1);break;case"cancel":s(-1),u(void 0),p(void 0)}},[m]),g=function(e,t){var n=rm(),r=null==n?void 0:n.autocompleteSuggestionsUrl;return ng({url:r,query:e,context:t})}(c||"",f),y="success"===g.state?g.data:void 0,b=Z.useMemo(function(){return y?Yv(y,-1).map(function(e){return{heading:e.heading,items:e.items.slice().reverse()}}):void 0},[y]);return Z.useEffect(function(){var e=h;i(b),e&&b||s(-1)},[b,h]),Z.useMemo(function(){return{suggestions:r,index:a,execute:v,item:h}},[r,a,v,h])}var Fx=function(e){var t=e.onAdminJoin,n=Z.useRef(null),r=Z.useState(!1),i=r[0],o=r[1],a=Z.useState(""),s=a[0],l=a[1];function c(e){l(e.target.value)}var u=""===s||void 0===s,d=cb();function p(e){var r,a;e.preventDefault(),i?(d(function(e){return function(){e.bargeOut(function(e){e&&Yh(e)})}}),o(!1),t(!1),l("")):(d((a=null===(r=n.current)||void 0===r?void 0:r.value,function(e){return function(){e.bargeIn(a,function(e){e&&Yh(e)})}})),o(!0),t(!0))}return f.jsx("div",{className:"xappw-admin-input-container visible",children:i?f.jsx("form",{className:"xappw-admin-input-form",onSubmit:p,children:f.jsx("div",{className:"xappw-admin-input-form__buttons",children:f.jsx(lm,{addClass:"xappw-admin-input-form__btn",type:"submit",label:"Leave"})})}):f.jsxs("form",{className:"xappw-admin-input-form",onSubmit:p,children:[f.jsx("div",{className:"xappw-admin-input-form__buttons",children:f.jsx(lm,{addClass:"xappw-admin-input-form__btn",type:"submit",label:"Join",disable:u})}),f.jsx("div",{className:"xappw-admin-input",children:f.jsx("input",{ref:n,id:"adminBarInput",placeholder:"Type your name here...",className:"xappw-admin-input__input",onChange:c})})]})})};var qx=function(e){var t,n=e.text,r=e.applyBrandingClass,i=e.linkColor,o=(t={"chat-footer__branding":r},Object.keys(t).filter(function(e){return t[e]}).join(" ")),a=n.replace(/\[(.*?)\]\((.*?)\)/g,function(e,t,n){return'<a style="color: '.concat(i||"",'; text-decoration: underline;" href="').concat(n,'" target="_blank" rel="noopener noreferrer">').concat(t,"</a>")}).replace(/\*\*(.*?)\*\*/g,function(e,t){return"<b>".concat(t,"</b>")}).replace(/^(#{1,6}) (.*?)(?=\n|$)/gm,function(e,t,n){var r=t.length;return"<h".concat(r,">").concat(n,"</h").concat(r,">")});return f.jsx("div",{className:o,dangerouslySetInnerHTML:{__html:a}})},Hx=function(e){var t=e.text;return(null==t?void 0:t.match(/\[([^\]]+)\]\((https?:\/\/[^\)]+)\)/))?f.jsx(qx,{text:t,applyBrandingClass:!0,linkColor:"white"}):f.jsx("div",{className:"chat-footer__branding",style:{color:"white"},children:t})},Wx=function(e){var t=e.subtitle?f.jsxs("span",{children:[f.jsx("div",{children:e.label}),f.jsx("div",{className:"chat-menu-item--subtitle",children:e.subtitle})]}):f.jsx("span",{children:e.label});return f.jsx("button",{type:"button",className:"chat-menu-item",tabIndex:e.tabIndex?Number(e.tabIndex):0,onClick:function(){e.onClick&&e.onClick(e.label)},children:t})},Vx=function(e){var t=e.items,n=e.opened,r=e.openFrom||"bottom",i=wb(),o=Cm(),a=Rh(function(e){return e.visuals});return f.jsx("div",{className:"chat-menu-".concat(r," ").concat("chat-menu-".concat(r,n?"--opened":"--closed")),children:t.map(function(t,n){return Kw.isStandardMenuItem(t)?f.jsx(Wx,{onClick:e.onItemClick,label:t.label,subtitle:t.subtitle},n):Kw.isStaticImageMenuItem(t)?f.jsx("div",{className:"chat-menu-item-static",children:f.jsx("img",{style:{maxHeight:"100%",maxWidth:"auto"},src:t.imageUrl,alt:"Menu Item"})},n):Kw.isStaticTextMenuItem(t)?f.jsx("div",{className:"chat-menu-item-static-text",children:f.jsxs("div",{children:[f.jsx("div",{children:t.title}),f.jsx("div",{className:"chat-menu-item-static-text--body",children:t.body})]})},n):Kw.isOpenURLMenuItem(t)?f.jsx("button",{className:"chat-menu-item",onClick:i.bind(undefined,t.url,o,a,t.behavior),children:t.text},n):f.jsx("p",{children:"Unknown"})})})},$x=function(e){var t=e.bars;return t||(t=2),f.jsx("button",{className:"drawer-bars",tabIndex:e.tabIndex?Number(e.tabIndex):0,"aria-label":"open menu","aria-hidden":!1,onClick:e.onToggle,children:function(){for(var e=[],n=0;n<t;n++)e.push(f.jsx("div",{className:"drawer-bar bar".concat(n)},"drawer-bar-".concat(n)));return e}()})},Kx=function(){return f.jsx("svg",{style:{color:"grey",paddingRight:"5px"},xmlns:"http://www.w3.org/2000/svg",fill:"currentColor",viewBox:"0 0 16 16",children:f.jsx("path",{d:"M1.293 1.293a1 1 0 0 1 1.414 0L8 6.586l5.293-5.293a1 1 0 1 1 1.414 1.414L9.414 8l5.293 5.293a1 1 0 0 1-1.414 1.414L8 9.414l-5.293 5.293a1 1 0 0 1-1.414-1.414L6.586 8 1.293 2.707a1 1 0 0 1 0-1.414z"})})},Qx=function(){return f.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",fill:"currentColor",viewBox:"0 0 16 16",children:f.jsx("path",{fillRule:"evenodd",d:"M2 13.5a.5.5 0 0 0 .5.5h6a.5.5 0 0 0 0-1H3.707L13.854 2.854a.5.5 0 0 0-.708-.708L3 12.293V7.5a.5.5 0 0 0-1 0v6z"})})},Jx=function(){return f.jsx("svg",{viewBox:"80.208 98.129 313.069 282.823",xmlns:"http://www.w3.org/2000/svg",children:f.jsxs("g",{transform:"matrix(0.024498, 0, 0, -0.038359, 79.83091, 381.182404)",fill:"currentColor",stroke:"none",children:[f.jsx("path",{d:"M12670 7345 c-63 -18 -272 -77 -465 -130 -192 -53 -478 -132 -635 -175 -508 -141 -1091 -302 -2345 -649 -676 -187 -2038 -563 -3025 -836 -987 -273 -2072 -573 -2410 -666 -338 -94 -802 -222 -1030 -285 -1857 -514 -2579 -714 -2684 -742 -38 -10 -65 -21 -60 -24 5 -3 67 -22 139 -41 72 -20 326 -90 565 -157 239 -67 611 -170 825 -230 215 -60 586 -163 825 -230 239 -67 491 -137 560 -156 l126 -34 974 439 c1397 629 4128 1858 6050 2724 910 410 1826 822 2035 917 209 94 387 173 395 176 35 10 -66 -39 -8200 -3928 -586 -280 -1068 -512 -1071 -516 -3 -4 33 -117 82 -252 76 -213 355 -996 765 -2147 65 -183 120 -330 122 -329 1 2 114 558 250 1236 l248 1233 3455 2064 c1900 1135 3670 2193 3933 2351 264 158 491 293 505 301 62 33 -5 -12 -271 -182 -1671 -1070 -7188 -4613 -7188 -4617 0 -7 3661 -2455 3669 -2454 4 1 3713 6853 3977 7347 8 15 11 27 7 26 -5 0 -60 -15 -123 -34z"}),f.jsx("path",{d:"M5030 2232 c-15 -61 -479 -1861 -531 -2058 -21 -83 -39 -154 -39 -158 0 -3 369 330 820 740 452 411 817 750 813 754 -11 10 -1025 754 -1039 763 -8 4 -16 -10 -24 -41z"})]})})},Yx=function(e){var t=e.disabled,n=void 0!==t&&t,r=ee.useState(!1),i=r[0],o=r[1];return f.jsx(f.Fragment,{children:e.sendButtonIcon?f.jsx("button",{className:"xappw-custom-send-button ".concat(n?"disabled":""),tabIndex:e.tabIndex?Number(e.tabIndex):0,onClick:e.onClick,disabled:n,onMouseEnter:function(){return o(!0)},onMouseLeave:function(){return o(!1)},children:f.jsx("img",{src:n&&e.sendButtonIconDisabled?e.sendButtonIconDisabled:i&&!n&&e.sendButtonIconHover?e.sendButtonIconHover:e.sendButtonIcon,alt:"Send button",draggable:!1,className:"send-button-icon"})}):f.jsx(Uv,{className:"xappw-send-button ".concat(e.className||""," ").concat(n?"disabled":""),tabIndex:e.tabIndex,onClick:n?void 0:e.onClick,icon:Jx})})},Gx=function(e){var t,n,r=e.value,i=e.placeholder,o=e.sendButtonIcon,a=e.sendButtonIconHover,s=e.sendButtonIconDisabled,l=e.suggestion,c=e.footerConfig,u=e.inputConfig,d=e.onChange,p=e.onSubmit,h=e.onSuggestionCommand,m=Z.useState(!1),v=m[0],g=m[1],y=null==u?void 0:u.maxLength,b=r.text.length,w=void 0!==y&&b>=y,x=void 0!==y&&b>=.8*y;var k=Z.useCallback(function(e){e&&e.preventDefault(),p(r)},[r,p]),S=Z.useCallback(function(){d({text:"",formats:[]})},[d]),C=Z.useCallback(function(e){!l||"End"!==e.key&&"ArrowRight"!==e.key&&"Enter"!==e.key?h&&("ArrowUp"===e.key?(h("prev"),e.preventDefault()):"ArrowDown"===e.key?(h("next"),e.preventDefault()):"Escape"===e.key&&(h("cancel"),e.preventDefault())):d(l)},[l,d,h]);return f.jsx("div",{className:"xappw-input-container ".concat(e.addClass," ").concat(v?"drag-drop-zone":""),"aria-label":(r.text,"To clear input field click on clear icon on the left of send button"),"aria-hidden":!1,onDrop:function(t){g(!1),e.onFileUpload(t)},onDragOver:function(e){g(!0),e.preventDefault(),e.dataTransfer.dropEffect="copy"},onDragLeave:function(){g(!1)},children:f.jsxs("form",{className:"xappw-input-form",onSubmit:k,children:[f.jsx(Fv,{id:"chatWidgetInput",className:"xappw-input",placeholder:null!=i?i:"type your question here",tabIndex:null==u?void 0:u.tabIndex,maxLength:y,onInput:d,onChange:d,onKeyDown:C,value:r,spellCheck:!0},"input"),f.jsxs("div",{className:"xappw-input-form__buttons",children:[x&&f.jsxs("span",{className:"xappw-input-form__counter".concat(w?" xappw-input-form__counter--limit":""),children:[b,"/",y]}),r.text&&f.jsx(Uv,{icon:Kx,tabIndex:null===(t=null==c?void 0:c.clearButton)||void 0===t?void 0:t.tabIndex,className:"xappw-input-form__btn",onClick:S}),f.jsx(Yx,{className:"xappw-input-form__btn",sendButtonIcon:o,sendButtonIconHover:a,sendButtonIconDisabled:s,tabIndex:null===(n=null==c?void 0:c.sendButton)||void 0===n?void 0:n.tabIndex,disabled:!r.text,onClick:k})]})]})})};var Xx=function(e){var t=e.data,n=e.onItemUse,r=e.searchTerms,i=Z.useState(),o=i[0],a=i[1],s=Z.useState(),l=s[0],c=s[1];Z.useEffect(function(){t&&a(t),r||(a(void 0),c(void 0))},[t,r]);var u=(null==t?void 0:t.length)>0?e.index:NaN,d=Z.useMemo(function(){return $v(t,u)},[t,u]),p=Z.useCallback(function(e,t){if("inputText"===t.type)return n(e),c(void 0),!1},[n]);Z.useEffect(function(){c(d)},[d]);var h,m=Z.useMemo(function(){return function(e){return function(t){var n=t.data,r="FAQ"!==n.type,i=Z.useCallback(function(t){e(n),t.stopPropagation()},[n]);return r?f.jsx(Uv,{className:"xappw-suggestions__use",onClick:i,icon:Qx}):f.jsx(f.Fragment,{})}}(n)},[n]),v="xappw-suggestions ".concat(e.className||""," ").concat(e.hasWsButton?"xappw-suggestions--with-ws-button":"").trim();return f.jsxs("div",{className:v,children:[(null==l?void 0:l.content)&&f.jsx("div",{className:"xappw-suggestions__answer",children:(h=l.content,h.split("\n").map(function(e,t){return e?f.jsx(qx,{text:e},"line-".concat(t)):f.jsx(ee.Fragment,{},"line-".concat(t))}))}),o&&o.length>0&&f.jsx(qv,{suggestions:o,index:u,className:"xappw-suggestions__groups",itemActions:m,onItemClick:e.onItemClick,onItemHover:c,onSpanClick:p})]})},Zx=function(e){var t,n,r,i=e.isAdmin,o=e.isChatting,a=e.visible,s=e.placeholder,l=e.sendButtonIcon,c=e.sendButtonIconHover,u=e.sendButtonIconDisabled,d=e.footerConfig,p=e.menuConfig,h=e.inputConfig,m=e.hasWsButton,v=e.disabled,g=e.onSubmit,y=Cm(),b=Z.useState(!1),w=b[0],x=b[1],k=Z.useState(),S=k[0],C=k[1],_=Ux(S,Rh(function(e){return e.activeContexts})),E="FOOTER"===((null==p?void 0:p.menuButtonLocation)||"FOOTER"),N=null==p?void 0:p.items,I=null==p?void 0:p.itemsTabIndex,T=null===(t=null==p?void 0:p.button)||void 0===t?void 0:t.tabIndex,j=Z.useMemo(function(){return N||[]},[N]),O=null===(n=null==d?void 0:d.branding)||void 0===n?void 0:n.enabled,P=null===(r=null==d?void 0:d.branding)||void 0===r?void 0:r.text,A=Z.useState(!i),R=A[0],M=A[1],L=Z.useState({text:"",formats:[]}),D=L[0],B=L[1];var z=Z.useCallback(function(e){C(""),B({text:"",formats:[]}),g(e.text)},[g]),U=Z.useCallback(function(e){z(e)},[z]),F=Z.useCallback(function(e){B(e),C(e.text)},[]);return f.jsxs("div",{className:"chat-footer background-footer","aria-label":j.length?"to open menu click a button above the rounded rectangle at the bottom of widget":"","aria-hidden":!1,children:[E&&j.length?f.jsxs(f.Fragment,{children:[w?f.jsx(Vx,{opened:w,tabIndex:I,onItemClick:function(t){x(!1),e.onSubmit(t)},items:j}):f.jsx(f.Fragment,{}),f.jsx("div",{className:"chat-footer__menu-icon",children:f.jsx($x,{tabIndex:T,onToggle:function(){var e=!w;x(e),y(fb({drawer:e}))}})})]}):f.jsx(f.Fragment,{}),f.jsx(Xx,{className:"xappw-chat-footer__suggestions",data:_.suggestions,index:_.index,searchTerms:S,hasWsButton:m,onItemClick:U,onItemUse:F}),i&&o&&a&&f.jsx(Fx,{onAdminJoin:function(e){M(e)}}),f.jsx("div",{style:{pointerEvents:R&&!v?"auto":"none",opacity:R?1:.5},children:f.jsx(Gx,{addClass:"chat-footer__input "+(o&&a?"visible":""),suggestion:_.item,value:D,placeholder:s,sendButtonIcon:l,sendButtonIconHover:c,sendButtonIconDisabled:u,footerConfig:d,inputConfig:h,onSubmit:z,onChange:function(t){B(t),e.onChange(t.text),C(t.text)},onSuggestionCommand:_.execute,onFileUpload:e.onFileUpload})}),O&&P&&f.jsx(Hx,{text:P})]})};var ek=function(e){var t,i,o=e.config,a=e.widgetEnv,s=e.onClose,l=Z.useRef(null),c=Z.useRef(null),u=function(e,t){var n;return e.formConfig?{api:e.formConfig.api,intentId:e.formConfig.intentId,autoGreeting:e.formConfig.autoGreeting}:(null===(n=null==t?void 0:t.connection)||void 0===n?void 0:n.serverUrl)?{api:{url:t.connection.serverUrl,key:t.connection.accountKey},intentId:e.intentId,autoGreeting:e.autoGreeting}:null}(o,a),d=Z.useState("idle"),p=d[0],h=d[1],m=Z.useState(""),v=m[0],g=m[1],y=(null===(i=null===(t=o.formConfig)||void 0===t?void 0:t.api)||void 0===i?void 0:i.key)||(null==a?void 0:a.formWidgetKey),b=Z.useCallback(function(){return n(void 0,void 0,void 0,function(){return r(this,function(e){switch(e.label){case 0:return Wh()?[4,$h(o.preselectChipLabel?{preselectChipLabel:o.preselectChipLabel}:void 0,5,100)]:[3,2];case 1:if(e.sent())return h("success"),s(),[2];e.label=2;case 2:if(!y)return[3,8];h("loading"),e.label=3;case 3:return e.trys.push([3,6,,7]),[4,Hh(y)];case 4:return e.sent(),[4,$h(o.preselectChipLabel?{preselectChipLabel:o.preselectChipLabel}:void 0,30,100)];case 5:return e.sent()?(h("success"),s()):(h("error"),g("Form widget loaded but failed to open. Please try again.")),[3,7];case 6:return e.sent(),h("error"),g("Failed to load form. Please check your connection and try again."),[3,7];case 7:return[3,9];case 8:h("error"),g("Form widget key not configured. Please contact support."),e.label=9;case 9:return[2]}})})},[o.preselectChipLabel,y,s]);Z.useEffect(function(){b()},[b]),Z.useEffect(function(){var e=function(e){"Escape"===e.key&&s()};return document.addEventListener("keydown",e),function(){document.removeEventListener("keydown",e)}},[s]),tg(),Z.useEffect(function(){c.current&&c.current.focus()},[]);var w=Z.useCallback(function(e){e.target===l.current&&s()},[s]),x=Z.useCallback(function(){h("idle"),g(""),b()},[b]);return u||y?f.jsx("div",{className:"xapp-form-modal",ref:l,onClick:w,role:"dialog","aria-modal":"true","aria-label":"Form",children:f.jsxs("div",{className:"xapp-form-modal__content",ref:c,tabIndex:-1,children:[f.jsx("button",{className:"xapp-form-modal__close",onClick:s,"aria-label":"Close form",children:"×"}),f.jsxs("div",{className:"xapp-form-modal__form-container",children:["loading"===p&&f.jsxs("div",{className:"xapp-form-modal__loading",children:[f.jsx("div",{className:"xapp-form-modal__spinner","aria-hidden":"true"}),f.jsx("p",{children:"Loading form..."})]}),"error"===p&&f.jsxs("div",{className:"xapp-form-modal__error",children:[f.jsx("p",{children:v}),f.jsx("button",{className:"xapp-form-modal__retry",onClick:x,children:"Try Again"})]}),"idle"===p&&f.jsxs("div",{className:"xapp-form-modal__loading",children:[f.jsx("div",{className:"xapp-form-modal__spinner","aria-hidden":"true"}),f.jsx("p",{children:"Initializing..."})]})]})]})}):f.jsx("div",{className:"xapp-form-modal",ref:l,onClick:w,role:"dialog","aria-modal":"true","aria-label":"Form",children:f.jsxs("div",{className:"xapp-form-modal__content",ref:c,tabIndex:-1,children:[f.jsx("button",{className:"xapp-form-modal__close",onClick:s,"aria-label":"Close form",children:"×"}),f.jsxs("div",{className:"xapp-form-modal__error",children:[f.jsx("p",{children:"Form configuration not available."}),f.jsx("p",{children:"Please configure the form button with valid settings."})]})]})})},tk=function(e){var t=e.option,n=t.actionUrl?"chat-chip chat-chip-link":"chat-chip";return f.jsx("div",{onClick:function(){return null==e?void 0:e.onClick(t)},className:n,children:f.jsx("span",{children:"object"==typeof t?t.label:t})})},nk=function(e){return f.jsx("div",{className:"chat-chips",children:e.options.map(function(t,n){return f.jsx(tk,{onClick:e.onOptionClick,option:t},n)})})},rk=function(e){var t=cb(),n=Rh(function(e){return e.chips}),r=Cm(),i=Rh(function(e){return e.visuals}),o=wb();return f.jsx("div",{className:"message-list-container__chips ".concat((null==n?void 0:n.length)?"":"message-list-container__chips--empty"),children:f.jsx(nk,{options:n,onOptionClick:function(e){var n,a=Tb(e)&&e.actionUrl;a?o(a,r,i):t(gm(Tb(n=e)?n.label:n,{action:"click",ui:"chip"}))}})})};function ik(e){return"others"===e?"m 80 0 v 240 h -60 c 40 -40 60 -160 60 -240":"m 0 0 v 240 h 60 c -40 -40 -60 -160 -60 -240"}function ok(e){return f.jsx("svg",{className:"chat-text-bubble__tail",xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 80 240",children:f.jsx("path",{d:ik(e),fill:"currentColor"})})}var ak=function(e){var t=e.owner,n=e.onClick,r=Z.useCallback(function(){n&&n()},[n]);return f.jsxs("div",{onClick:r,className:"chat-text-bubble ".concat("mine"===t?"chat-text-bubble--mine":"chat-text-bubble--others"),children:[e.hasTail&&ok(t),e.children]})},sk=function(e){var t=e.onOpenUrl,n=Mh(e.message.user.nick),r=Z.useRef(null),i=Cm(),o=Rh(function(e){return e.visuals}),a=e.message.msg.html,s=Z.useCallback(function(e){if(t){var n=e.target;e.preventDefault(),t(n.href,i,o)}},[t]);return Z.useEffect(function(){if(r.current&&(r.current.innerHTML=a,t)){var e=r.current.querySelectorAll("a");return e.forEach(function(e){e.addEventListener("click",s)}),function(){e.forEach(function(e){e.removeEventListener("click",s)})}}},[r,a,t,s,e.message.timestamp]),f.jsx("div",{className:"chat-msg",children:f.jsx("div",{className:"chat-text-container",children:f.jsxs(ak,{owner:n?"others":"mine",hasTail:n&&!e.sibling,children:[f.jsx("span",{className:"message-sr-only",children:"at "+e.time+(n?" the bot said":" the user said")}),f.jsx("div",{ref:r})]})})})},lk=function(e){var t=e.message,n=e.ctx;if(!n)throw new TypeError("ctx not provided to ".concat(lk.name));var r=n.user,i=t.msg.permissionRequest,o=Mh(e.message.user.nick),a=t.user,s="Deny",l=Z.useCallback(function(e){n.write({type:"msg",user:a,msg:e})},[n,a]),c=Z.useCallback(function(e){n.write({type:"msg",user:r,msg:e})},[n,r]),u=Z.useCallback(function(){n.send({type:"msg",user:void 0,msg:{text:s}})},[n]),d=Z.useCallback(function(e){n.send({type:"permissionGrant",user:a,msg:e})},[a,n]),p=Z.useCallback(function(e,t){d({text:t,location:e?{latitude:e.coords.latitude,longitude:e.coords.longitude}:void 0,permissionRequest:i}),c({text:t});var n=e?null==i?void 0:i.approve:null==i?void 0:i.deny;n&&l(n)},[i,c,l,d]),h=Z.useCallback(function(e){p(void 0,e)},[p]),m=Z.useCallback(function(e){navigator.geolocation&&navigator.geolocation.getCurrentPosition(function(t){p(t,e)},function(){u()})},[u,p]);return i?f.jsxs("div",{className:"chat-msg",children:[f.jsx("span",{className:"message-sr-only",children:"at "+e.time+(o?" the bot said":" the user said")}),f.jsxs("div",{className:"buttons-container",children:[f.jsx(lm,{label:"Allow",addClass:"button",onClick:m}),f.jsx(lm,{label:s,addClass:"button",onClick:h})]})]}):f.jsx(f.Fragment,{})},ck=function(e){var t=e.text,i=Z.useState(!1),o=i[0],a=i[1];return f.jsx("button",{className:"tool-call-item__copy-btn",onClick:function(e){return n(void 0,void 0,void 0,function(){var n;return r(this,function(r){switch(r.label){case 0:e.stopPropagation(),r.label=1;case 1:return r.trys.push([1,3,,4]),[4,navigator.clipboard.writeText(t)];case 2:return r.sent(),a(!0),setTimeout(function(){return a(!1)},1500),[3,4];case 3:return r.sent(),(n=document.createElement("textarea")).value=t,document.body.appendChild(n),n.select(),document.execCommand("copy"),document.body.removeChild(n),a(!0),setTimeout(function(){return a(!1)},1500),[3,4];case 4:return[2]}})})},title:"Copy to clipboard",children:o?"✓":"⧉"})},uk=function(e){var t,n,r;return null!==(r=null!==(n=null!==(t=e.label)&&void 0!==t?t:e.displayName)&&void 0!==n?n:e.name)&&void 0!==r?r:"Working..."},dk=function(e){var t=e.toolCall,n=uk(t);return f.jsxs("div",{className:"tool-progress-item ".concat(t.isExecuting?"tool-progress-item--executing":""," ").concat(t.error?"tool-progress-item--error":""),children:[f.jsx("span",{className:"tool-progress-item__icon",children:t.isExecuting?f.jsx("span",{className:"tool-progress-item__spinner","aria-label":"executing"}):t.error?f.jsx("span",{className:"tool-progress-item__status tool-progress-item__status--error",children:"!"}):f.jsx("span",{className:"tool-progress-item__status tool-progress-item__status--success",children:"✓"})}),f.jsx("span",{className:"tool-progress-item__label",children:n})]})},fk=function(e){var t=e.toolCall,n=Z.useState(!1),r=n[0],i=n[1],o=function(e){if(null==e)return"";try{if("string"==typeof e)try{var t=JSON.parse(e);return JSON.stringify(t,null,2)}catch(t){return e}return JSON.stringify(e,null,2)}catch(t){return String(e)}},a=uk(t),s=t.endTime?"".concat(((t.endTime-t.startTime)/1e3).toFixed(2),"s"):null,l=void 0!==t.input&&null!==t.input,c=void 0!==t.result&&null!==t.result,u=!!t.error;return f.jsxs("div",{className:"tool-call-item ".concat(t.isExecuting?"tool-call-item--executing":""),children:[f.jsxs("button",{className:"tool-call-item__header",onClick:function(){return i(!r)},"aria-expanded":r,children:[f.jsx("span",{className:"tool-call-item__icon",children:t.isExecuting?f.jsx("span",{className:"tool-call-item__spinner","aria-label":"executing"}):t.error?f.jsx("span",{className:"tool-call-item__status tool-call-item__status--error",children:"!"}):f.jsx("span",{className:"tool-call-item__status tool-call-item__status--success",children:"✓"})}),f.jsxs("span",{className:"tool-call-item__info",children:[f.jsx("span",{className:"tool-call-item__label",children:a}),f.jsx("span",{className:"tool-call-item__name",children:t.name})]}),s&&f.jsx("span",{className:"tool-call-item__duration",children:s}),f.jsx("span",{className:"tool-call-item__chevron ".concat(r?"tool-call-item__chevron--expanded":""),children:"▾"})]}),r&&f.jsxs("div",{className:"tool-call-item__content",children:[l&&f.jsxs("div",{className:"tool-call-item__section",children:[f.jsxs("div",{className:"tool-call-item__section-header",children:[f.jsx("span",{className:"tool-call-item__section-label",children:"Input"}),f.jsx(ck,{text:o(t.input)})]}),f.jsx("pre",{className:"tool-call-item__code",children:o(t.input)})]}),c&&f.jsxs("div",{className:"tool-call-item__section",children:[f.jsxs("div",{className:"tool-call-item__section-header",children:[f.jsx("span",{className:"tool-call-item__section-label",children:"Output"}),f.jsx(ck,{text:o(t.result)})]}),f.jsx("pre",{className:"tool-call-item__code",children:o(t.result)})]}),u&&f.jsxs("div",{className:"tool-call-item__section",children:[f.jsxs("div",{className:"tool-call-item__section-header",children:[f.jsx("span",{className:"tool-call-item__section-label tool-call-item__section-label--error",children:"Error"}),f.jsx(ck,{text:t.error||""})]}),f.jsx("pre",{className:"tool-call-item__code tool-call-item__code--error",children:t.error})]}),!l&&!c&&!u&&f.jsx("div",{className:"tool-call-item__empty",children:"No data available"})]})]})},pk=function(e){var t=e.toolCalls,n=e.debugMode,r=void 0!==n&&n;if(!t||0===t.length)return null;if(r)return f.jsxs("div",{className:"tool-call-display",children:[f.jsxs("div",{className:"tool-call-display__header",children:[f.jsx("span",{className:"tool-call-display__icon",children:"⚙"}),f.jsxs("span",{className:"tool-call-display__title",children:["Tool Calls (",t.length,")"]})]}),f.jsx("div",{className:"tool-call-display__list",children:t.map(function(e,t){return f.jsx(fk,{toolCall:e},"".concat(e.name,"-").concat(e.startTime,"-").concat(t))})})]});var i=t.filter(function(e){return!e.hidden});return 0===i.length?null:f.jsx("div",{className:"tool-progress-display",children:i.map(function(e,t){return f.jsx(dk,{toolCall:e},"".concat(e.name,"-").concat(e.startTime,"-").concat(t))})})};function hk(e){return e.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;")}function mk(e){return hk(e).replace(/\*\*(.+?)\*\*/g,"<strong>$1</strong>").replace(/__(.+?)__/g,"<strong>$1</strong>").replace(/\*([^*]+?)\*/g,"<em>$1</em>").replace(/_([^_]+?)_/g,"<em>$1</em>")}function vk(e){if(!e)return"";var t=[],n=e.replace(/```([^\s`]*)\r?\n([\s\S]*?)```/g,function(e,n,r){var i=hk(r.replace(/\n$/,"")),o=n?' data-language="'.concat(hk(n),'"'):"";return t.push("<pre><code".concat(o,">").concat(i,"</code></pre>")),"%%CODEBLOCK".concat(t.length-1,"%%")}),r=[];n=n.replace(/(?:^|\n)(\|.+\|)\n(\|[\s:|-]+\|)\n((?:\|.+\|\n?)+)/g,function(e,t,n,i){return r.push(function(e,t,n){var r=function(e){return e.split("|").slice(1,-1).map(function(e){return mk(e.trim())})},i=t.split("|").slice(1,-1).map(function(e){return e.trim()}).map(function(e){return e.startsWith(":")&&e.endsWith(":")?"center":e.endsWith(":")?"right":"left"}),o=r(e).map(function(e,t){return'<th scope="col" style="text-align:'.concat(i[t]||"left",'">').concat(e,"</th>")}).join(""),a=n.trim().split("\n").filter(function(e){return""!==e.trim()}).map(function(e){return"<tr>"+r(e).map(function(e,t){return'<td style="text-align:'.concat(i[t]||"left",'">').concat(e,"</td>")}).join("")+"</tr>"}).join("");return'<div style="overflow-x:auto"><table><thead><tr>'.concat(o,"</tr></thead><tbody>").concat(a,"</tbody></table></div>")}(t,n,i)),"\n%%TABLE".concat(r.length-1,"%%\n")});var i=[];n=n.replace(/`([^`\n]+)`/g,function(e,t){return i.push("<code>".concat(hk(t),"</code>")),"%%INLINECODE".concat(i.length-1,"%%")});var o=[];return n=n.replace(/\[([^\]]+)\]\(([^)]+)\)/g,function(e,t,n){return o.push('<a href="'.concat(hk(n),'" target="_blank" rel="noopener noreferrer">').concat(mk(t),"</a>")),"%%LINK".concat(o.length-1,"%%")}),n=(n=(n=(n=n.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/^### (.+)$/gm,"<h4>$1</h4>").replace(/^## (.+)$/gm,"<h3>$1</h3>").replace(/^# (.+)$/gm,"<h2>$1</h2>").replace(/\*\*(.+?)\*\*/g,"<strong>$1</strong>").replace(/__(.+?)__/g,"<strong>$1</strong>").replace(/\*([^*]+?)\*/g,"<em>$1</em>").replace(/_([^_]+?)_/g,"<em>$1</em>").replace(/^[-*] (.+)$/gm,"<li>$1</li>").replace(/\n/g,"<br>")).replace(/(<li>.*?<\/li>)(<br>)?/g,"$1")).replace(/(<li>.*?<\/li>)+/g,"<ul>$&</ul>")).replace(/<ul>(.*?)<\/ul>/g,function(e){return e.replace(/<br>/g,"")}),r.forEach(function(e,t){n=n.replace(new RegExp("(?:<br>)?%%TABLE".concat(t,"%%(?:<br>)?")),function(){return e})}),t.forEach(function(e,t){n=n.replace(new RegExp("(?:<br>)?%%CODEBLOCK".concat(t,"%%(?:<br>)?")),function(){return e})}),i.forEach(function(e,t){n=n.replace("%%INLINECODE".concat(t,"%%"),function(){return e})}),o.forEach(function(e,t){n=n.replace("%%LINK".concat(t,"%%"),function(){return e})}),n}var gk=function(e){var t,n=e.message,r=new Date(n.timestamp),i=r.getHours()+":"+r.getMinutes(),o=Mh(null===(t=e.message.user)||void 0===t?void 0:t.nick),a=n.isStreaming,s=Z.useMemo(function(){return o&&n.msg.text?vk(n.msg.text):null},[o,n.msg.text]),l=n.wasStreamed,c=o&&!e.sibling&&!a&&!l,u=e.toolCalls&&e.toolCalls.length>0,d=e.onLinkClick;return f.jsxs("div",{className:"chat-msg".concat(a?" chat-msg--streaming":""),children:[u&&f.jsx(pk,{toolCalls:e.toolCalls,debugMode:e.debugMode}),f.jsx("div",{className:"chat-text-container",children:f.jsxs(ak,{owner:o?"others":"mine",hasTail:c,children:[f.jsx("span",{className:"message-sr-only",children:"at "+i+(o?a?" the bot is typing":" the bot said":" the user said")}),s?f.jsx("span",{className:"chat-msg__content",onClick:function(e){var t,n;if(!(!d||e.metaKey||e.ctrlKey||e.shiftKey||e.altKey)){var r=null===(n=(t=e.target).closest)||void 0===n?void 0:n.call(t,"a");r&&e.currentTarget.contains(r)&&(e.preventDefault(),d(r.href))}},dangerouslySetInnerHTML:{__html:s}}):f.jsx("span",{className:"chat-msg__content",children:n.msg.text}),a&&f.jsx("span",{className:"streaming-cursor","aria-hidden":"true"})]})})]})},yk=function(e){var t=e.display,n=Cm(),r=Rh(function(e){return e.visuals}),i=wb();return f.jsx("div",{className:"chat-schedule-button-container",children:f.jsxs("button",{className:"chat-schedule-button",onClick:function(){i(tm,n,r)},children:[f.jsx("i",{className:"fa fa-lg fa-calendar"}),f.jsx("span",{children:t.label||"Schedule Now!"})]})})},bk=function(e){var t=e.sources,n=e.prefix,r=void 0===n?"Sources:":n,i=e.onSourceClick;if(!t||0===t.length)return null;return f.jsxs("div",{className:"source-links",children:[r&&f.jsx("span",{className:"source-links__prefix",children:r}),f.jsx("span",{className:"source-links__list",children:t.map(function(e,n){return f.jsxs("span",{className:"source-links__item",children:[f.jsx("a",{href:e.url,target:!1!==e.newTab?"_blank":"_self",rel:!1!==e.newTab?"noopener noreferrer":void 0,className:"source-links__link",onClick:function(t){return function(e,t){i&&(t.preventDefault(),i(e))}(e,t)},title:e.url,children:e.title}),n<t.length-1&&f.jsx("span",{className:"source-links__separator",children:"·"})]},n)})})]})};var wk,xk=["text","html","card","list"],kk=function(e){var t,n,r,i,o=e.messageMiddleware||aw,a=Z.useContext(nm),s=e.middlewareContext,l=e.agent,c=Cm(),u=Rh(function(e){return e.visuals}),d=(null===(t=null==a?void 0:a.env)||void 0===t?void 0:t.urls)&&(null==s?void 0:s.openUrl)?function(e){return s.openUrl(e,c,u)}:void 0,p=null===(n=e.agents)||void 0===n?void 0:n[e.message.user.nick],h=(null==p?void 0:p.hideUserInfo)||!1;var m,v=e.message.isStreaming,g=!(!(null===(r=e.message.msg)||void 0===r?void 0:r.text)&&!(null===(i=e.message.msg)||void 0===i?void 0:i.html)),y=!v&&g;return f.jsx("div",{className:"chat-msg-container-wrapper ".concat(Mh(e.message.user.nick)?"agent":"visitor"," ").concat(e.sibling?"sibling":""),children:f.jsxs("div",{className:"chat-msg-container ".concat((m=e.message,Mh(m.user.nick)?"agent":"visitor")),children:[function(){var t,n,r,i,c,u,p,m,v,g,y,b,w,x,k,S,C,_=e.message.msg;if("chat.msg"===e.message.type){var E=xk.find(function(e){return!!_[e]}),N=e.message.isStreaming,I=e.message.wasStreamed,T=e.message.toolCalls,j=T&&T.length>0,O=null!==(i=null===(r=null===(n=null===(t=null==a?void 0:a.env)||void 0===t?void 0:t.connection)||void 0===n?void 0:n.mcp)||void 0===r?void 0:r.debugMode)&&void 0!==i&&i,P=j&&!_.text;return f.jsxs(f.Fragment,{children:[P&&f.jsx(mm,{showAvatar:!0,user:l,avatarPosition:null===(p=null===(u=null===(c=null==a?void 0:a.env)||void 0===c?void 0:c.theme)||void 0===u?void 0:u.messages)||void 0===p?void 0:p.avatarPosition,hideUserInfo:h,isStreaming:!0,children:f.jsx("div",{className:"chat-msg",children:f.jsx(pk,{toolCalls:T,debugMode:O})})}),_.text&&f.jsx(mm,{showAvatar:"text"===E,user:l,avatarPosition:null===(g=null===(v=null===(m=null==a?void 0:a.env)||void 0===m?void 0:m.theme)||void 0===v?void 0:v.messages)||void 0===g?void 0:g.avatarPosition,hideUserInfo:h,isStreaming:N||I,children:f.jsx(gk,{message:e.message,sibling:e.sibling,user:l,toolCalls:j?T:void 0,debugMode:O,onLinkClick:d})}),_.html&&f.jsx(mm,{showAvatar:"html"===E,user:l,avatarPosition:null===(w=null===(b=null===(y=null==a?void 0:a.env)||void 0===y?void 0:y.theme)||void 0===b?void 0:b.messages)||void 0===w?void 0:w.avatarPosition,hideUserInfo:h,children:f.jsx(sk,{message:e.message,sibling:e.sibling,onOpenUrl:null===(x=e.middlewareContext)||void 0===x?void 0:x.openUrl})}),_.displays&&o&&_.displays.map(function(t,n){if("ScheduleButton"===t.type)return f.jsx(yk,{minimizeOnClick:e.minimizeOnClick,display:t},n);var r=o;return f.jsx(r,{msg:t,ctx:e.middlewareContext},n)}),_.permissionRequest&&s&&f.jsx(mm,{showAvatar:"permissionRequest"===E,user:l,avatarPosition:null===(C=null===(S=null===(k=null==a?void 0:a.env)||void 0===k?void 0:k.theme)||void 0===S?void 0:S.messages)||void 0===C?void 0:C.avatarPosition,hideUserInfo:h,children:f.jsx(lk,{message:e.message,sibling:e.sibling,ctx:s})})]})}return f.jsx(f.Fragment,{})}(),y&&function(){var t,n=e.message.timestamp,r=function(e){var t=new Date,n=Math.floor((t.valueOf()-e.valueOf())/1e3);if(n<1)return"now";if(n<60)return"".concat(n," seconds ago");var r=Math.floor(n/60);if(r<60)return"".concat(r," minutes ago");var i=Math.floor(r/60);return i<24?"".concat(i," hours ago"):e.toLocaleString()}(new Date(n)),i=null===(t=e.message.msg)||void 0===t?void 0:t.sources,o=i&&i.length>0,a=Mh(e.message.user.nick);return f.jsxs("div",{className:"chat-msg-footer ".concat(a?"agent":"visitor"),children:[f.jsx("span",{className:"chat-msg-timestamp",children:r}),o&&f.jsx(bk,{sources:i.map(function(e){return{title:e.title,url:e.url,newTab:e.newTab}})})]})}()]})})},Sk=function(e){return f.jsxs("div",{className:"card-container ".concat(e.addClass),children:[(t="string"==typeof e.icon,f.jsx("div",{className:"card-container__icon",children:!t&&e.icon})),f.jsxs("div",{className:"card-container__content ".concat(e.contentAddClass),children:[f.jsx("div",{className:"card-container__title",children:e.title}),e.children]})]});var t},Ck=function(e){var t=e.agent,n=void 0===t?{}:t,r=e.hasRating,i=void 0!==r&&r,o=e.shouldDisplay,a=void 0===o||o,s=e.onRate,l=void 0===s?function(){}:s,c=Z.useCallback(function(){l("bad")},[l]),u=Z.useCallback(function(){l("good")},[l]),d=Z.useCallback(function(){l(void 0)},[l]);return a?i?f.jsxs(Sk,{title:"Chat Rating",addClass:"chat-rating-card",children:["You have rated the chat service.",f.jsx("div",{className:"buttons-container",children:f.jsx(lm,{addClass:"button button-rate-again",label:"Rate again",onClick:d})})]}):f.jsxs(Sk,{title:"Chat Rating",addClass:"chat-rating-card",children:[n.displayName," has requested you to rate the chat service.",f.jsxs("div",{className:"buttons-container",children:[f.jsx(lm,{addClass:"button button-rate-bad",label:"Rate Bad",onClick:c}),f.jsx(lm,{addClass:"button button-rate-good",label:"Rate Good",onClick:u})]})]}):null},_k=function(e){var t=cb(),n=Z.useCallback(function(e){t(function(e){return function(t){return function(){t.sendChatRating(e)}}}(e))},[t]);return f.jsxs(f.Fragment,{children:[f.jsx("span",{className:"message-sr-only",children:"at "+e.time+" system message"}),f.jsx(Ck,{agent:e.agent,hasRating:e.hasRating,shouldDisplay:e.shouldDisplay,onRate:n})]})};function Ek(e,t){var n,r;switch(void 0===t&&(t="ssml"),typeof e){case"string":n=e;break;case"number":n="".concat(e)}return Nk(e)&&(n=Ak(e,t)),(r=e)&&(r.start||r.end)&&(n=function(e,t){void 0===t&&(t="ssml");if(!e)return"";var n=e.start,r=e.end,i="".concat(Ak(n,t)," to ").concat(Ak(r,t));o=Ik(n.date),a=Ik(r.date),o.getFullYear()===a.getFullYear()&&o.getMonth()===a.getMonth()&&o.getDate()===a.getDate()&&(i="on ".concat(Ak({date:n.date},t)," from ").concat(Ak({time:n.time},t)," to ").concat(Ak({time:r.time},t)));var o,a;return i}(e,t)),function(e){return!!e&&"object"==typeof e&&"number"==typeof e.amount&&"string"==typeof e.format}(e)&&(n=function(e,t){void 0===t&&(t="ssml");if(!e)return"";var n=e.amount>1,r="ssml"===t?'<say-as interpret-as="cardinal">'.concat(e.amount,"</say-as>"):e.amount,i=Rk[e.format],o=e.format;Object.keys(Rk).forEach(function(e){Rk[e]===i&&e.length>o.length&&!e.endsWith("s")&&(o=e)});var a=n?"".concat(o,"s"):o;return"".concat(r," ").concat(a)}(e,t)),Array.isArray(e)&&(n=function(e,t){void 0===t&&(t=wk.or);var n=wk[t];if(!e||0===e.length)return"";if(1===e.length)return e[0];if(e.length>=2){var r=e.length-2;return e.reduce(function(e,t,i){return e+=t,i<r?e+=", ":i===r&&(e+=" ".concat(n," ")),e},"")}}(e,wk.and)),n}function Nk(e){return!(!e||!e.date&&!e.time)}function Ik(e){var t=String(e).split("-").map(Number),n=t[0],r=t[1],i=t[2];return new Date(n,r-1,i)}function Tk(e){return e<10?"0".concat(e):String(e)}function jk(e){if(isNaN(e.getTime()))throw new RangeError("Invalid time value")}function Ok(e){return jk(e),"".concat(e.getFullYear(),"-").concat(Tk(e.getMonth()+1),"-").concat(Tk(e.getDate()))}function Pk(e){jk(e);var t=e.getHours();return"".concat(t%12==0?12:t%12,":").concat(Tk(e.getMinutes())," ").concat(t<12?"AM":"PM")}function Ak(e,n){if(void 0===n&&(n="ssml"),!e)return"";var r=t({},e);r.date||(r.date=Ok(new Date));var i=new Date(Date.parse(function(e){if("object"!=typeof e)return"";var t="";try{if(Nk(e)){var n=e.date?Ok(Ik(e.date)):void 0,r=e.time;t="".concat(n||"").concat(n&&r?"T":"").concat(r||"")}else{var i=e.start,o=e.end;if(i){n=i.date?Ok(Ik(i.date)):void 0,r=i.time;t="".concat(n||"").concat(n&&r?"T":"").concat(r||"")}if(i&&o&&(t+=" --\x3e "),o){n=o.date?Ok(Ik(o.date)):void 0,r=o.time;t+="".concat(n||"").concat(n&&r?"T":"").concat(r||"")}}}catch(e){console.error(e)}return t}(r))),o="";return e.date&&(o+="ssml"===n?'<say-as interpret-as="date" format="ymd">'.concat(Ok(i),"</say-as>"):"".concat(function(e){return jk(e),"".concat(e.getMonth()+1,"-").concat(e.getDate(),"-").concat(e.getFullYear())}(i))),e.time&&("ssml"===n?o+='<say-as interpret-as="time">'.concat(Pk(i),"</say-as>"):(o.length>0&&(o+=" "),o+="".concat(Pk(i)))),o}!function(e){e[e.or=0]="or",e[e.and=1]="and"}(wk||(wk={}));var Rk={ms:1,millisecond:1,milliseconds:1,s:1e3,second:1e3,seconds:1e3,m:6e4,minute:6e4,minutes:6e4,h:36e5,hour:36e5,hours:36e5,d:864e5,day:864e5,days:864e5,w:6048e5,week:6048e5,weeks:6048e5,M:2628e6,month:2628e6,months:2628e6,Q:7776e6,quarter:7776e6,quarters:7776e6,y:3154e7,years:3154e7,year:3154e7};var Mk=/\$\{([^\\}]*(?:\\.[^\\}]*)*)\}/g;function Lk(e,t,n,r){for(var i,o=e,a=new RegExp(Mk);null!==(i=a.exec(e));){var s=void 0,l=t[i[1].trim()];l&&(s=Ek(l.value,n)),(s||r)&&(o=o.replace(i[0],s))}return o}var Dk=function(e){var t=e.agents,n=e.text,r=e.delay,i=e.time,o=Z.useState(r),a=o[0],s=o[1],l=Object.values(t).filter(function(e){return e.requestFailed});Z.useEffect(function(){if(0!==r)var e=r,t=setInterval(function(){e--,s(e),0===e&&clearInterval(t)},1e3);else s(5)},[r]);var c=Z.useMemo(function(){return{sec:{name:"sec",value:a}}},[a]),u=Z.useMemo(function(){return function(e,t,n){if(!e||!t)return e;var r=e;if("string"==typeof r)r=Lk(r,t,"displayText",n);else{var i=r;["ssml","displayText"].forEach(function(e){i[e]&&(i[e]=Lk(i[e],t,e,n))})}return r}(n,c)},[n,c]);return 0===a?f.jsx(f.Fragment,{}):f.jsx(f.Fragment,{children:l.map(function(e){var t,n;return f.jsx("div",{className:"chat-msg-container-wrapper",children:f.jsx("div",{className:"chat-msg-container agent",children:f.jsx(mm,{user:null==e?void 0:e.user,showAvatar:!0,children:f.jsx("div",{className:"chat-msg",children:f.jsxs(ak,{owner:"others",hasTail:!0,children:[f.jsx("span",{className:"message-sr-only",children:"at "+i+" the bot said"}),f.jsx("span",{children:"object"==typeof u?u.displayText:u})]})})})},null===(t=null==e?void 0:e.user)||void 0===t?void 0:t.nick)},"failure-msg-".concat(null===(n=null==e?void 0:e.user)||void 0===n?void 0:n.nick))})})},Bk=function(e){return f.jsx("svg",{className:"message-svg",width:"16",height:"12",viewBox:"0 0 16 12",children:f.jsx("path",{d:"M14.4 0H1.6C.72 0 .008.675.008 1.5L0 10.5c0 .825.72 1.5 1.6 1.5h12.8c.88 0 1.6-.675 1.6-1.5v-9c0-.825-.72-1.5-1.6-1.5zm0 3L8 6.75 1.6 3V1.5L8 5.25l6.4-3.75V3z",fill:"#424242",fillRule:"evenodd"})})},zk=function(e){var t=Z.useRef(null),n=Z.useRef(null),r=Z.useRef(null),i=Z.useRef(null),o=Z.useState(!1),a=o[0],s=o[1];function l(){var e,t,r;(null===(e=n.current)||void 0===e?void 0:e.validity.patternMismatch)?null===(t=n.current)||void 0===t||t.setCustomValidity("This doesn't look like an email!"):null===(r=n.current)||void 0===r||r.setCustomValidity("")}function c(o){var a,l,c,u,d;o.preventDefault(),(null===(a=i.current)||void 0===a?void 0:a.checkValidity())?(e.onSubmit({name:null===(c=t.current)||void 0===c?void 0:c.value,email:null===(u=n.current)||void 0===u?void 0:u.value,message:null===(d=r.current)||void 0===d?void 0:d.value}),s(!0)):null===(l=i.current)||void 0===l||l.reportValidity()}function u(){s(!1)}return f.jsx(Sk,{title:e.title,addClass:"offline-card",contentAddClass:a?"sent":"",icon:f.jsx(Bk,{}),children:a?f.jsxs("div",{className:"message-form--sent",children:["Your message has been sent. We will get back to you as soon as possible.",f.jsx(lm,{addClass:"button-resend",label:"Send another",onClick:u})]},"sent"):f.jsxs("form",{ref:i,className:"message-form",onSubmit:c,children:[f.jsxs("div",{className:"content",children:[f.jsxs("div",{className:"section",children:[f.jsx("label",{className:"label",children:"Name"}),f.jsx("input",{ref:t,maxLength:255})]}),f.jsxs("div",{className:"section",children:[f.jsx("label",{className:"label",children:"Email"}),f.jsx("input",{ref:n,onChange:l,type:"email",required:!0,pattern:"^\\w+([\\.-]?\\w+)*@\\w+([\\.-]?\\w+)*(\\.\\w{2,3})+$"})]}),f.jsxs("div",{className:"section",children:[f.jsx("label",{className:"label",children:"Message"}),f.jsx("textarea",{required:!0,ref:r})]})]}),f.jsx("div",{className:"button-container",children:f.jsx(lm,{type:"submit",addClass:"message-form__submit",label:"Send"})})]},"not-sent")})},Uk=function(e){return f.jsx(zk,{title:"Offline message card title",onSubmit:e.onSubmit})},Fk=function(e){var t=cb(),n=Z.useCallback(function(e){t(function(e){return function(t){return function(){t.sendOfflineMsg(e,function(e){e&&Yh(e)})}}}(e))},[t]);return f.jsxs(f.Fragment,{children:[f.jsx("span",{className:"message-sr-only",children:"at "+e.time+" system message"}),f.jsx(Uk,{onSubmit:n})]})},qk=function(e){var t=Z.useState(!1),n=t[0],r=t[1],i=e.onSubmit,o=Z.useCallback(function(e){i(e),r(!0)},[i]);return f.jsx(f.Fragment,{children:!n&&f.jsx(zk,{title:"Introduce yourself!",onSubmit:o})})},Hk=function(e){var t=cb(),n=Rh(function(e){return e.sessionId}),r=Z.useCallback(function(e){e.message&&(t(bm({displayName:e.name,email:e.email},n)),t(gm(e.message)))},[t,n]);return f.jsxs(f.Fragment,{children:[f.jsx("span",{className:"message-sr-only",children:"at "+e.time+" system message"}),f.jsx(qk,{onSubmit:r})]})},Wk=function(e){var t=e.position,n=void 0===t?0:t;return n<=0?null:f.jsx("div",{className:"system-msg-container",children:f.jsxs("span",{className:"system-msg",children:["Queue position: ",n]})})};function Vk(e){switch(e.type){case"chat.memberjoin":return e.message||"".concat(e.user.displayName||"Bot"," has joined the chat");case"chat.memberleave":return e.message||"".concat(e.user.displayName||"Bot"," has left the chat");case"chat.systemmessage":return e.message;case"chat.rating":if(e.newRating){var t=(n=e.newRating)[0].toUpperCase()+n.slice(1);return"You have rated the chat service ".concat(t)}return"You have removed the chat rating";default:return JSON.stringify(e)}var n}var $k=function(e){var t;if(function(e){var t;return null===(t=e.nick)||void 0===t?void 0:t.endsWith(Pg)}(e.message.user))return null;var n=e.message,r=function(e){return"chat.memberjoin"===e.type&&e.showDivider||"chat.memberleave"===e.type&&e.showDivider}(n),i=null===(t=n.user)||void 0===t?void 0:t.avatarPath;return f.jsxs("div",{className:"system-msg-container",children:[r&&i&&f.jsxs("div",{className:"system-msg-divider",children:[f.jsx("div",{className:"divider-line"}),f.jsx("div",{className:"divider-avatar",children:f.jsx("img",{src:i,alt:"".concat(n.user.displayName||"User","'s avatar")})}),f.jsx("div",{className:"divider-line"})]}),f.jsx("span",{className:"message-sr-only",children:"at "+e.time+" system message"}),f.jsx("span",{className:"system-msg",children:Vk(e.message)})]})};var Kk=function(e){return f.jsxs("div",{className:"typing-indicator",children:[f.jsx("div",{className:"typing-indicator-part"}),f.jsx("div",{className:"typing-indicator-part"}),f.jsx("div",{className:"typing-indicator-part"})]})},Qk=function(e){var t=Object.values(e.agents).filter(function(e){return e.typing});return f.jsx(f.Fragment,{children:t.map(function(t,n){var r,i,o=(null===(r=t.user)||void 0===r?void 0:r.nick)||"".concat(n),a=(null===(i=t.user)||void 0===i?void 0:i.displayName)||"Somebody";return f.jsx("span",{children:e.textTypingStatusEnabled?f.jsxs("div",{className:"chat-msg-agent-typing",children:[a," is typing"]},"typing-status-".concat(o)):f.jsx("div",{className:"chat-msg-container-wrapper",children:f.jsx("div",{className:"chat-msg-container agent chat-typing-progress",children:f.jsx(mm,{user:t.user,showAvatar:!0,children:f.jsx("div",{className:"chat-msg",children:f.jsx(ak,{owner:"others",hasTail:!0,children:f.jsx(Kk,{})})})})},o)},"typing-status-".concat(o))},"typing-status-".concat(n))})})},Jk=function(e){e.visible;var n=e.messages,r=void 0===n?[]:n,i=e.agents,o=void 0===i?{}:i;e.isOffline,e.isChatting;var a=e.queuePosition,s=void 0===a?0:a,l=e.lastRatingRequestTimestamp,c=void 0===l?0:l,u=e.hasRating,d=void 0!==u&&u;e.visitorId;var p=e.messageMiddleware,h=e.textTypingStatusEnabled,m=e.agent,v=e.hasWsButton,g=e.disableAutoScroll,y=void 0!==g&&g,b=e.onSend,w=void 0===b?function(){return Promise.resolve()}:b,x=e.onWrite,k=void 0===x?function(){return Promise.resolve()}:x,S=e.onOpenUrl,C=void 0===S?function(){}:S,_=e.minimizeOnClick,E=void 0===_?function(){}:_;e.children;var N=Z.useRef(null),I=Z.useRef(null),T=Z.useRef(v),j=Z.useCallback(function(){if(!I.current)return!0;var e=I.current,t=e.scrollTop,n=e.scrollHeight,r=e.clientHeight;return Math.abs(n-r-t)<10},[]),O=Z.useCallback(function(e){void 0===e&&(e="smooth");var t=I.current;t&&("function"!=typeof t.scrollTo?t.scrollTop=t.scrollHeight:t.scrollTo({top:t.scrollHeight,behavior:e}))},[]);Z.useEffect(function(){y||O("smooth")},[r,o,O,y]),Z.useEffect(function(){if(!y){var e=T.current,t=v;if(T.current=t,e&&!t)if(j()){var n=setTimeout(function(){O("smooth")},350);return function(){return clearTimeout(n)}}}},[v,j,O,y]);var P=Z.useCallback(function(e){w(e),y||O("smooth")},[w,y,O]),A=Z.useCallback(function(e){k(e),y||O("smooth")},[k,y,O]),R=Z.useMemo(function(){return new Xb({send:P,write:A,openUrl:C})},[P,A,C]),M=new Date,L=M.getHours()+":"+M.getMinutes();function D(e,n){var r,i,a,s;switch((null===(i=null===(r=e.user)||void 0===r?void 0:r.nick)||void 0===i?void 0:i.startsWith("visitor:"))?s=e.user:(s=(null===(a=o[e.user.nick])||void 0===a?void 0:a.user)||m)||(Yh('Could not get a user from agents list with nick: "'.concat(e.user.nick,'"')),s=e.user),e.type){case"chat.file":case"chat.msg":return f.jsx(kk,{message:e,sibling:n,agent:s,messageMiddleware:p,middlewareContext:R.resolve(s),minimizeOnClick:E},"cm-".concat(e.type,"-").concat(e.timestamp));case"chat.failureMsg":return f.jsx(Dk,t({agents:o,time:L},e.failureMsg),"fm-".concat(e.type,"-").concat(e.timestamp));case"chat.memberjoin":case"chat.memberleave":case"chat.systemmessage":case"chat.rating":case"chat.typing":return f.jsx($k,{time:L,message:e},"sm-".concat(e.type,"-").concat(e.timestamp));case"chat.request.rating":return f.jsx(_k,{agent:s,hasRating:d,time:L,shouldDisplay:e.timestamp===c},"cr-".concat(e.type,"-").concat(e.timestamp));case"chat.offline":return f.jsx(Fk,{time:L},"offline-".concat(e.timestamp));case"chat.prechat":return f.jsx(Hk,{time:L},"prechat");default:return f.jsxs("span",{children:[f.jsx("span",{className:"message-sr-only",children:"at "+L+" system message"}),f.jsxs("div",{"data-testid":"unhandled-message",children:["Unhandled message: ",JSON.stringify(e)]},"uhm-".concat(e.timestamp))]},"default-".concat(e.timestamp))}}return f.jsxs("div",{className:"message-list-container",ref:I,children:[f.jsxs("div",{className:"message-list-container__msgs",children:[function(){for(var e=-1,t=r.length-1;t>0;t--)if("chat.msg"===r[t].type){e=t;break}return r.map(function(t,n){var i,o,a=!1;if(["chat.file","chat.msg","chat.memberjoin","chat.memberleave","chat.rating","chat.request.rating","chat.offline","chat.prechat"].includes(t.type)&&!(null===(o=null===(i=t.user)||void 0===i?void 0:i.nick)||void 0===o?void 0:o.endsWith(Pg)))if(0===n||n===r.length-1||n===e)a=!0;else{var s=r[n-1];t.timestamp&&s.timestamp&&(a=t.timestamp-s.timestamp>3e5)}0===n&&"chat.memberjoin"===t.type&&(a=!1);var l=a?new Date(t.timestamp).toLocaleString():void 0;return f.jsxs("span",{children:[a&&f.jsx("div",{className:"ts-msg-container",children:f.jsx("span",{className:"ts-msg",children:l})}),D(t,!1)]},"message-list-render-all-".concat(n))})}(),f.jsx("div",{ref:N,style:{float:"left",clear:"both"}}),f.jsx(Wk,{position:s}),f.jsx(Qk,{agents:o,textTypingStatusEnabled:h})]}),f.jsx(rk,{})]})},Yk=function(){return f.jsxs("div",{className:"server-offline",children:[f.jsx("h2",{children:"We can't reach the chat right now"}),f.jsx("h3",{children:"Check your connection and try again in a moment."})]})},Gk=function(e){var t=e.children,n=e.className,r=void 0===n?"":n;return f.jsx("div",{className:"button-group ".concat(r),children:t})},Xk=function(e){return f.jsx("div",{id:"xapp-widget-close","aria-label":"close widget","aria-hidden":!1,tabIndex:e.tabIndex?Number(e.tabIndex):0,className:"cancel-button",onClick:e.onClick})};function Zk(e){return Tb(e)?e.actionUrl?"[".concat(e.label,"](").concat(e.actionUrl,")"):e.label:e}var eS=function(e){var t=Rh(function(e){return e.chats});return f.jsx("div",{id:"xapp-widget-export","aria-label":"export conversation","aria-hidden":!1,tabIndex:e.tabIndex?Number(e.tabIndex):0,className:"export-button",onClick:function(){return n(void 0,void 0,void 0,function(){var e,n;return r(this,function(r){switch(r.label){case 0:e=function(e){return e.filter(jw).map(function(e){var t,n,r,i=(null===(t=e.user.nick)||void 0===t?void 0:t.startsWith("visitor:"))?"User":"Assistant",o=(null===(n=e.msg)||void 0===n?void 0:n.text)||"",a="".concat(i,": ").concat(o),s=null===(r=e.msg)||void 0===r?void 0:r.options;if(s&&s.length>0){var l=s.map(Zk).join(", ");a+="\nSuggestions: ".concat(l)}return a}).join("\n")}(t),r.label=1;case 1:return r.trys.push([1,3,,4]),[4,navigator.clipboard.writeText(e)];case 2:return r.sent(),[3,4];case 3:return r.sent(),console.warn("[ExportButton] Using deprecated execCommand fallback for clipboard copy"),(n=document.createElement("textarea")).value=e,document.body.appendChild(n),n.select(),document.execCommand("copy"),document.body.removeChild(n),[3,4];case 4:return[2]}})})}})},tS=function(e){return f.jsx("div",{id:"xapp-widget-menu","aria-label":"open menu","aria-hidden":!1,tabIndex:e.tabIndex?Number(e.tabIndex):0,className:"menu-button",onClick:e.onClick})},nS=function(e){return f.jsx("div",{id:"xapp-widget-minimize","aria-label":"minimize widget","aria-hidden":!1,tabIndex:e.tabIndex?Number(e.tabIndex):0,className:"minimize-button ".concat(e.showInRight?"positionRight":""),onClick:e.onClick})},rS=function(e){return f.jsx("div",{id:"xapp-widget-refresh","aria-label":"refresh chat","aria-hidden":!1,tabIndex:e.tabIndex?Number(e.tabIndex):0,className:"refresh-button ".concat(e.showInRight?"positionRight":e.showInLeft?"positionLeft":""),onClick:e.onClick})},iS="Virtual Assistant",oS="Leave us a message",aS="We're away!",sS="Connecting...";function lS(e,t){var n,r,i,o;switch(Yh('getStatusText called with status: "'.concat(e,'"')),e){case"online":return null!==(n=null==t?void 0:t.online)&&void 0!==n?n:iS;case"offline":return null!==(r=null==t?void 0:t.offline)&&void 0!==r?r:oS;case"away":return null!==(i=null==t?void 0:t.away)&&void 0!==i?i:aS;default:return null!==(o=null==t?void 0:t.connecting)&&void 0!==o?o:sS}}function cS(e){if(function(e){return"string"==typeof e&&/<\/?[a-z][\s\S]*>/i.test(e)}(e)){var t=function(e){try{if("undefined"==typeof DOMParser)return Yh("DOMParser not available, returning text content only"),e.replace(/<[^>]*>/g,"");var t=(new DOMParser).parseFromString(e,"text/html");if(!t||!t.body)return Yh("DOMParser failed to parse HTML, returning text content only"),e.replace(/<[^>]*>/g,"");var n=["span","div","p","strong","em","b","i","u","br"],r=["color","background-color","font-size","font-weight","font-style","text-align","display","flex","align-items","justify-content","gap","margin","padding","width","height","border-radius"],i=function(e){if(e.nodeType===Node.ELEMENT_NODE){var o=e,a=o.tagName.toLowerCase();if(!n.includes(a)){var s=t.createTextNode(o.textContent||"");return void o.replaceWith(s)}if(Array.from(o.attributes).forEach(function(e){"style"!==e.name&&o.removeAttribute(e.name)}),o.hasAttribute("style")){var l=o.getAttribute("style")||"",c=[];l.split(";").forEach(function(e){var t=e.split(":"),n=t[0],i=t.slice(1).join(":").trim(),o=n.trim();o&&i&&r.includes(o.toLowerCase())&&(/javascript:|expression\(|@import|behavior:/i.test(i)||c.push("".concat(o,": ").concat(i)))}),c.length>0?o.setAttribute("style",c.join("; ")):o.removeAttribute("style")}Array.from(o.childNodes).forEach(function(e){return i(e)})}};return Array.from(t.body.childNodes).forEach(function(e){return i(e)}),t.body.innerHTML}catch(t){return Yh("Error sanitizing HTML: ".concat(t)),e.replace(/<[^>]*>/g,"")}}(e);return f.jsx("span",{dangerouslySetInnerHTML:{__html:t}})}return e}var uS=function(e){var t,n,r,i,o,a,s,l,c,u,d,p,h,m,v,g=Cm(),y=e.menuConfig,b=e.onSubmit,w=e.debugMode,x=Z.useState(!1),k=x[0],S=x[1],C=(null==y?void 0:y.menuButtonLocation)||"FOOTER",_="HEADER_LEFT"===C,E="HEADER_RIGHT"===C,N=null==y?void 0:y.items,I=null==y?void 0:y.itemsTabIndex,T=null===(t=null==y?void 0:y.button)||void 0===t?void 0:t.tabIndex,j=Z.useMemo(function(){return N||[]},[N]),O=E&&j.length>0;function P(){var e=!k;S(e),g(fb({drawer:e}))}var A="",R=e.canRefresh,M=e.canMinimize,L=e.canCancel;return R&&(A="To refresh chat click on clockwise gapped circle arrow icon in top right side of widget. "),M&&(A="".concat(A).concat("To minimize widget click on minus icon in top right side of widget. ")),L&&(A="".concat(A).concat("To close widget click on close icon in top right side of widget.")),f.jsxs(f.Fragment,{children:[f.jsxs("div",{className:"status-container background-header","aria-label":A,"aria-hidden":!1,children:[_&&j.length?f.jsx(f.Fragment,{children:f.jsx("div",{className:"chat-footer__menu-icon",children:f.jsx($x,{bars:3,tabIndex:T,onToggle:P})})}):f.jsx(f.Fragment,{}),void 0===(null===(n=null==e?void 0:e.agent)||void 0===n?void 0:n.avatarPath)?f.jsx("div",{}):f.jsx("div",{className:"status-container__avatar",children:f.jsx(pm,{entity:e.agent})}),f.jsxs("div",{className:"\n ".concat("status-text","\n ").concat(_&&j.length?"status-text-positionWithMenu":void 0===(null===(r=null==e?void 0:e.agent)||void 0===r?void 0:r.avatarPath)?"status-text-positionLeftNoAvatar":"status-text-positionLeft","\n ").concat((null===(i=e.config)||void 0===i?void 0:i.alignTextCenter)?"status-text-positionCenter":""," \n "),children:[f.jsx("span",{className:"status-text-title",children:lS(e.accountStatus,null===(o=e.config)||void 0===o?void 0:o.status)}),(null===(s=null===(a=e.config)||void 0===a?void 0:a.subtitle)||void 0===s?void 0:s.enabled)&&f.jsx("span",{className:"status-text-subtitle",children:cS(null===(c=null===(l=e.config)||void 0===l?void 0:l.subtitle)||void 0===c?void 0:c.text)})]}),f.jsxs(Gk,{children:[O&&f.jsx(tS,{onClick:P,tabIndex:T}),w&&f.jsx(eS,{}),e.canRefresh&&f.jsx(rS,{onClick:e.refreshOnClick,tabIndex:null===(d=null===(u=e.config)||void 0===u?void 0:u.actions)||void 0===d?void 0:d.refreshTabIndex,showInLeft:!1,showInRight:!1}),e.canMinimize&&f.jsx(nS,{onClick:e.minimizeOnClick,tabIndex:null===(h=null===(p=e.config)||void 0===p?void 0:p.actions)||void 0===h?void 0:h.minimizeTabIndex,showInRight:!1}),e.canCancel&&f.jsx(Xk,{onClick:e.cancelOnClick,tabIndex:null===(v=null===(m=e.config)||void 0===m?void 0:m.actions)||void 0===v?void 0:v.cancelTabIndex})]})]}),k?f.jsx("div",{className:"xa-chat-menu-container",children:f.jsx(Vx,{openFrom:E?"right":"left",opened:k,tabIndex:I,onItemClick:function(e){S(!1),b(e)},items:j})}):f.jsx(f.Fragment,{})]})};function dS(e){var t,n,i,o,a;return hS("--xapp-",mS(vS("primary-color",null==e?void 0:e.primaryColor),hS("widget-",mS(bS(null==e?void 0:e.size),wS(null==e?void 0:e.margin),_S(null==e?void 0:e.border),function(e){return r(this,function(t){switch(t.label){case 0:return e?[4,["z-index",e]]:[3,2];case 1:t.sent(),t.label=2;case 2:return[2]}})}(null==e?void 0:e.zIndex))),function(e){if(!e)return gS();return hS("chat-button-",mS(wS(e.margin),SS(e.background),hS("image-",bS(e.imageSize)),function(e){var t,n,i,o,a;return r(this,function(r){switch(r.label){case 0:return e?(t=e.primaryColor||"0, 117, 170",n=e.secondaryColor||"110, 178, 209",i=e.opacity||.75,[4,["animation-primary-color","".concat(t)]]):[2];case 1:return r.sent(),[4,["animation-secondary-color","".concat(n)]];case 2:return r.sent(),[4,["animation-opacity","".concat(i)]];case 3:return r.sent(),[4,["animation-primary-rgba","rgba(".concat(t,", ").concat(i,")")]];case 4:return r.sent(),[4,["animation-secondary-rgba","rgba(".concat(n,", ").concat(i,")")]];case 5:return r.sent(),o="radial-gradient(40.83% 40.83% at 47.92% 52.5%, rgba(".concat(t,", ").concat(i,") 78.85%, rgba(").concat(n,", ").concat(i,") 92.07%)"),a="radial-gradient(40.83% 40.83% at 47.92% 52.5%, rgba(".concat(t,", ").concat(i,") 20.46%, rgba(").concat(n,", ").concat(i,") 92.07%)"),[4,["animation-pulse-intense",o]];case 6:return r.sent(),[4,["animation-pulse-less-intense",a]];case 7:return r.sent(),[2]}})}(e.animation)))}(null==e?void 0:e.chatButton),hS("header-",function(e){if(!e)return gS();return mS(SS(e.background),kS(e.text),hS("subtitle-",kS(e.subtitle)),_S(e.border),xS(e.padding),vS("avatar-background",e.avatarBackground))}(null==e?void 0:e.header)),hS("footer-",function(e){var t;if(!e)return gS();return mS(SS(e.background),_S(e.border),hS("branding-",kS(null===(t=e.branding)||void 0===t?void 0:t.text)))}(null==e?void 0:e.footer)),hS("content-",mS(SS(null===(t=null==e?void 0:e.content)||void 0===t?void 0:t.background))),hS("messages-",function(e){if(!e)return gS();return mS(hS("mine-",yS(e.mine)),hS("others-",yS(e.others)),xS(null==e?void 0:e.padding),vS("max-width",null==e?void 0:e.maxWidth))}(null==e?void 0:e.messages)),hS("text-typing-status-",kS(null===(n=null==e?void 0:e.textTypingStatus)||void 0===n?void 0:n.text)),hS("send-",CS(null==e?void 0:e.sendButton)),hS("menu-",CS(null==e?void 0:e.menuButton)),hS("menu-",function(e){return mS(hS("item-",function(e){return mS(kS(null==e?void 0:e.text),hS("subtitle-",kS(null==e?void 0:e.subtitle)),_S(null==e?void 0:e.border),SS(null==e?void 0:e.background),vS("height",null==e?void 0:e.height))}(null==e?void 0:e.item)))}(null==e?void 0:e.menu)),hS("refresh-",CS(null==e?void 0:e.refreshButton)),hS("minimize-",CS(null==e?void 0:e.minimizeButton)),hS("cancel-",CS(null==e?void 0:e.cancelButton)),hS("carousel-",mS(hS("title-",kS(null===(i=null==e?void 0:e.carousel)||void 0===i?void 0:i.title)),hS("subtitle-",kS(null===(o=null==e?void 0:e.carousel)||void 0===o?void 0:o.subtitle)),hS("action-",CS(null===(a=null==e?void 0:e.carousel)||void 0===a?void 0:a.button)))),hS("input-",function(e){if(!e)return gS();return mS(SS(e.background),_S(e.border),kS(e.text),hS("placeholder-",kS(e.placeholder)))}(null==e?void 0:e.input)),hS("cta-",function(e){if(!e)return gS();return mS(SS(e.background),kS(e.text))}(null==e?void 0:e.cta)),hS("action-bar-",function(e){if(!e)return gS();return mS(SS(e.background),_S(e.border),xS(e.padding),wS(e.margin),vS("box-shadow",e.boxShadow),vS("border-radius",e.borderRadius),hS("button-",function(e){if(!e)return gS();return mS(SS(e.background),vS("hover-background",e.hoverBackground),hS("icon-",bS(e.iconSize)),vS("icon-color",e.iconColor),hS("label-",kS(e.label)),vS("gap",e.gap),vS("border-radius",e.borderRadius),xS(e.padding))}(e.button)))}(null==e?void 0:e.actionBar))))}var fS=new Map;function pS(e){var t=e.theme,n=JSON.stringify(function(e){for(var t=[],n=dS(e),r=n.next();!1===r.done;){var i=r.value,o=i[0],a=i[1];null!=a&&""!==a&&t.push([o,a]),r=n.next()}return t}(t));return ee.useLayoutEffect(function(){var e=JSON.parse(n);return function(e){for(var t,n=document.documentElement,r=0,i=e;r<i.length;r++){var o=i[r],a=o[0],s=o[1];n.style.setProperty(a,s),fS.set(a,(null!==(t=fS.get(a))&&void 0!==t?t:0)+1)}}(e),function(){return function(e){for(var t,n=document.documentElement,r=0,i=e;r<i.length;r++){var o=i[r][0],a=(null!==(t=fS.get(o))&&void 0!==t?t:1)-1;a<=0?(fS.delete(o),n.style.removeProperty(o)):fS.set(o,a)}}(e)}},[n]),null}function hS(e,t){var n;return r(this,function(r){switch(r.label){case 0:n=t.next(),r.label=1;case 1:return n.done?[3,3]:[4,["".concat(e).concat(n.value[0]),n.value[1]]];case 2:return r.sent(),n=t.next(),[3,1];case 3:return[2]}})}function mS(){var e,t,n,i,o,a=[];for(e=0;e<arguments.length;e++)a[e]=arguments[e];return r(this,function(e){switch(e.label){case 0:t=0,n=a,e.label=1;case 1:if(!(t<n.length))return[3,5];i=n[t],o=i.next(),e.label=2;case 2:return!1!==o.done?[3,4]:[4,o.value];case 3:return e.sent(),o=i.next(),[3,2];case 4:return t++,[3,1];case 5:return[2]}})}function vS(e,t){return r(this,function(n){switch(n.label){case 0:return[4,[e,t]];case 1:return n.sent(),[2]}})}function gS(){return r(this,function(e){return[2]})}function yS(e){return mS(vS("bubble-color",null==e?void 0:e.bubbleColor),kS(null==e?void 0:e.text))}function bS(e){return r(this,function(t){switch(t.label){case 0:return[4,["width",null==e?void 0:e.width]];case 1:return t.sent(),[4,["height",null==e?void 0:e.height]];case 2:return t.sent(),[2]}})}function wS(e){return r(this,function(t){switch(t.label){case 0:return e?[4,["margin-top",e.top]]:[3,5];case 1:return t.sent(),[4,["margin-right",e.right]];case 2:return t.sent(),[4,["margin-bottom",e.bottom]];case 3:return t.sent(),[4,["margin-left",e.left]];case 4:t.sent(),t.label=5;case 5:return[2]}})}function xS(e){return r(this,function(t){switch(t.label){case 0:return e?[4,["padding-top",e.top]]:[3,5];case 1:return t.sent(),[4,["padding-right",e.right]];case 2:return t.sent(),[4,["padding-bottom",e.bottom]];case 3:return t.sent(),[4,["padding-left",e.left]];case 4:t.sent(),t.label=5;case 5:return[2]}})}function kS(e){return r(this,function(t){switch(t.label){case 0:return e?[4,["text-color",e.color]]:[3,6];case 1:return t.sent(),[4,["font-size",e.fontSize]];case 2:return t.sent(),[4,["font-family",e.fontFamily]];case 3:return t.sent(),[4,["font-weight",e.fontWeight]];case 4:return t.sent(),[4,["font-style",e.fontStyle]];case 5:t.sent(),t.label=6;case 6:return[2]}})}function SS(e){return r(this,function(t){switch(t.label){case 0:return[4,["background",e]];case 1:return t.sent(),[2]}})}function CS(e){return r(this,function(t){switch(t.label){case 0:return[4,["button-color",null==e?void 0:e.color]];case 1:return t.sent(),[4,["button-width",null==e?void 0:e.width]];case 2:return t.sent(),[4,["button-bg",null==e?void 0:e.background]];case 3:return t.sent(),[4,["button-hover-bg",null==e?void 0:e.hoverBackground]];case 4:return t.sent(),[4,["button-disabled-bg",null==e?void 0:e.disabledBackground]];case 5:return t.sent(),[2]}})}function _S(e){return r(this,function(t){switch(t.label){case 0:return e?[4,["border-color",e.color]]:[3,4];case 1:return t.sent(),[4,["border-width",e.width]];case 2:return t.sent(),[4,["border-radius",e.radius]];case 3:t.sent(),t.label=4;case 4:return[2]}})}var ES=function(e){if(null===e)return"null";if(void 0===e)return"undefined";if("object"!=typeof e)return String(e);try{var t=new WeakSet;return JSON.stringify(e,function(e,n){if("object"==typeof n&&null!==n){if(t.has(n))return"[Circular]";t.add(n)}return n},2)}catch(t){return"[Object: ".concat(Object.prototype.toString.call(e),"]")}},NS=function(e){var o=e.enableErrorOverlay,a=Z.useState([]),s=a[0],l=a[1],c=Z.useState(!1),u=c[0],d=c[1],p=Z.useState(!0),h=p[0],m=p[1],v=Z.useState(!1),g=v[0],y=v[1],b=Z.useState("bottom"),w=b[0],x=b[1];Z.useEffect(function(){var e,t=function(){var e;if("undefined"==typeof window)return!1;var t=null===(e=window.localStorage)||void 0===e?void 0:e.getItem("xaErrorOverlay");return"enabled"===t?(console.log("[ErrorOverlay] Enabled via localStorage"),!0):"disabled"===t?(console.log("[ErrorOverlay] Disabled via localStorage"),!1):void 0!==o?(console.log("[ErrorOverlay] Using config setting:",o),o):!(void 0===globalThis.__DEV__||!globalThis.__DEV__)&&(console.log("[ErrorOverlay] Enabled via __DEV__"),!0)}();y(t);var n=null===(e=window.localStorage)||void 0===e?void 0:e.getItem("xaErrorOverlayPosition");"top"!==n&&"bottom"!==n||x(n),console.log("[ErrorOverlay] Component mounted, enabled:",t,"position:",n||"bottom")},[o]);var k=Z.useCallback(function(e){console.log("[ErrorOverlay] Adding error:",e),l(function(n){var r=(new Date).toISOString(),o=n[n.length-1];if(o&&o.message===e.message)return i(i([],n.slice(0,-1),!0),[t(t({},o),{count:o.count+1,timestamp:r})],!1);var a=t({id:"".concat(r,"-").concat(Math.random()),timestamp:r,count:1},e);return i(i([],n,!0),[a],!1).slice(-50)})},[]);Z.useEffect(function(){if(g){console.log("[ErrorOverlay] Setting up error interception");var e=console.error,t=console.warn;console.error=function(){for(var t=[],n=0;n<arguments.length;n++)t[n]=arguments[n];var r=t.map(function(e){return ES(e)}).join(" "),i=new Error;k({message:r,type:"error",stack:i.stack}),e.apply(console,t)},console.warn=function(){for(var e=[],n=0;n<arguments.length;n++)e[n]=arguments[n];var r=e.map(function(e){return ES(e)}).join(" ");k({message:r,type:"warning"}),t.apply(console,e)};var n=function(e){var t;k({message:e.message,type:"error",stack:null===(t=e.error)||void 0===t?void 0:t.stack})},r=function(e){var t;k({message:"Unhandled Promise Rejection: ".concat(e.reason),type:"error",stack:null===(t=e.reason)||void 0===t?void 0:t.stack})};return window.addEventListener("error",n),window.addEventListener("unhandledrejection",r),function(){console.log("[ErrorOverlay] Cleaning up error interception"),console.error=e,console.warn=t,window.removeEventListener("error",n),window.removeEventListener("unhandledrejection",r)}}console.log("[ErrorOverlay] Not enabled, skipping error interception")},[g,k]);return g&&h?0===s.length?null:f.jsxs("div",{className:"error-overlay error-overlay--".concat(w," ").concat(u?"minimized":""),children:[f.jsxs("div",{className:"error-overlay-header",children:[f.jsxs("span",{className:"error-overlay-title",children:["Debug Console (",s.length,")"]}),f.jsxs("div",{className:"error-overlay-actions",children:[f.jsx("button",{onClick:function(){return n(void 0,void 0,void 0,function(){var e,t,n;return r(this,function(r){switch(r.label){case 0:e=s.map(function(e){return"[".concat(e.timestamp,"] ").concat(e.type.toUpperCase(),": ").concat(e.message).concat(e.stack?"\n"+e.stack:"")}).join("\n\n"),r.label=1;case 1:return r.trys.push([1,3,,4]),[4,navigator.clipboard.writeText(e)];case 2:return r.sent(),console.log("[ErrorOverlay] Errors copied to clipboard"),[3,4];case 3:t=r.sent(),console.error("[ErrorOverlay] Failed to copy to clipboard:",t),(n=document.createElement("textarea")).value=e,n.style.position="fixed",n.style.opacity="0",document.body.appendChild(n),n.select();try{document.execCommand("copy"),console.log("[ErrorOverlay] Errors copied to clipboard using fallback method")}catch(e){console.error("[ErrorOverlay] Fallback copy method also failed:",e)}return document.body.removeChild(n),[3,4];case 4:return[2]}})})},title:"Copy all to clipboard",children:"📋"}),f.jsx("button",{onClick:function(){l([])},title:"Clear all",children:"🗑️"}),f.jsx("button",{onClick:function(){var e="bottom"===w?"top":"bottom";x(e),"undefined"!=typeof window&&window.localStorage&&window.localStorage.setItem("xaErrorOverlayPosition",e)},title:"Move to ".concat("bottom"===w?"top":"bottom"),children:"bottom"===w?"⬆️":"⬇️"}),f.jsx("button",{onClick:function(){var e=!g;y(e),"undefined"!=typeof window&&window.localStorage&&window.localStorage.setItem("xaErrorOverlay",e?"enabled":"disabled"),console.log("[ErrorOverlay] Toggled enabled state to:",e),e||l([])},title:"Disable Error Overlay",children:"🔧"}),f.jsx("button",{onClick:function(){return d(!u)},title:"Minimize/Maximize",children:u?"▲":"▼"}),f.jsx("button",{onClick:function(){return m(!1)},title:"Close",children:"✕"})]})]}),!u&&f.jsx("div",{className:"error-overlay-content",children:s.map(function(e){return f.jsxs("div",{className:"error-entry error-".concat(e.type),children:[f.jsxs("div",{className:"error-header",children:[f.jsx("span",{className:"error-time",children:new Date(e.timestamp).toLocaleTimeString()}),e.count>1&&f.jsxs("span",{className:"error-count",children:["(",e.count,"x)"]}),f.jsx("span",{className:"error-badge error-badge-".concat(e.type),children:e.type})]}),f.jsx("div",{className:"error-message",children:e.message}),e.stack&&f.jsxs("details",{className:"error-stack",children:[f.jsx("summary",{children:"Stack trace"}),f.jsx("pre",{children:e.stack})]})]},e.id)})})]}):null},IS=function(e){var t=e.button,n=e.onPress,r=Z.useCallback(function(){"disabled"===t.pressBehavior||t.isPressed||n(t.id)},[t.pressBehavior,t.isPressed,t.id,n]),i=Z.useMemo(function(){var e=["ws-button"];return("disabled"===t.pressBehavior||t.isPressed)&&e.push("ws-button--disabled"),t.isPressed&&"spinning"===t.pressBehavior&&e.push("ws-button--spinning"),e.join(" ")},[t.pressBehavior,t.isPressed]),o=Z.useMemo(function(){var e=["ws-button-container"];return t.isDismissing&&e.push("ws-button-container--dismissing"),e.join(" ")},[t.isDismissing]);return f.jsx("div",{className:o,children:f.jsxs("button",{className:i,onClick:r,disabled:"disabled"===t.pressBehavior||t.isPressed,"aria-label":t.text,"aria-busy":t.isPressed&&"spinning"===t.pressBehavior,children:[t.isPressed&&"spinning"===t.pressBehavior&&f.jsx("span",{className:"ws-button__spinner"}),f.jsx("span",{className:"ws-button__text",children:t.text})]})})},TS=function(e){var t=e.onClose,n=e.onReset;return f.jsxs("div",{className:"modalContent",children:[f.jsxs("div",{className:"modalBody",children:[f.jsx("h2",{children:"Restart Conversation"}),f.jsx("p",{children:"Would you like to refresh and return to the starting point of the conversation?"})]}),f.jsxs("div",{className:"modalActions",children:[f.jsx("button",{onClick:t,className:"cancelBtn",children:"Cancel"}),f.jsx("button",{onClick:n,className:"restartBtn",children:"Restart"})]})]})};function jS(e){var t=function(e){return function(t,n){return void 0===t&&(t=e),Yh("static reducer",t,n),t}}(e);return kw({reducer:t,middleware:function(e){return e({thunk:!0})},devTools:!1})}var OS=function(e){var n=e.state,r=Z.useMemo(function(){return jS(n)},[n]),i=Z.useMemo(function(){return t(t({},e.config),{connection:{serverUrl:"",type:"local"}})},[e.config]);return f.jsx(_h,{store:r,children:f.jsx(BS,t({},e,{config:i,disableAutoScroll:e.disableAutoScroll,preview:e.preview}))})},PS=function(e){var n=e.messages,r=Z.useMemo(function(){return function(e){var n,r=Nw(),o=e.length>0?e[e.length-1]:void 0,a="chat.msg"===(null==o?void 0:o.type)?o.msg:null,s=(null===(n=null==a?void 0:a.options)||void 0===n?void 0:n.length)?a.options:[];return t(t({},r),{connection:t(t({},r.connection),{connectionStatus:"online"}),accountStatus:"online",chats:i([],e,!0),chips:s,isChatting:!0,visuals:{visible:!0,opened:!0}})}(n)},[n]);return f.jsx(OS,{state:r,mode:e.mode,config:e.config,disableAutoScroll:e.disableAutoScroll,preview:e.preview})},AS="undefined"==typeof window?Z.useEffect:Z.useLayoutEffect;"undefined"!=typeof process&&process.env;var RS=function(e){var t,n=null!==(t=e.mode)&&void 0!==t?t:"preview",r=Z.useMemo(function(){return t=e.previewMessages||[],n=e.config,r=Date.now(),t.map(function(e,t){var i,o;return{type:"chat.msg",user:{nick:"agent:robot",display_name:(null==n?void 0:n.botName)||"Assistant",avatarPath:null==n?void 0:n.avatarUrl},timestamp:r+t,msg:{text:e.displayText,html:e.html,options:null===(i=e.suggestions)||void 0===i?void 0:i.map(function(e){return{label:e.title,actionUrl:e.url||"#"}}),list:e.list?{type:e.list.type,title:e.list.title,items:e.list.items.map(function(e){return{title:e.title,subTitle:e.description,url:e.url,imageUrl:e.imageUrl,hideUrl:e.hideUrl}})}:void 0,displays:e.list?[(o={type:e.list.type,title:e.list.title,items:e.list.items.map(function(e){return{title:e.title,subTitle:e.description,url:e.url,imageUrl:e.imageUrl,hideUrl:e.hideUrl}})},{type:o.type,title:o.title,items:(o.items||[]).map(function(e){var t={title:e.title,description:e.subTitle,token:e.token,url:e.url,hideUrl:e.hideUrl,image:{url:e.imageUrl,imageActionUrl:e.imageActionUrl,accessibilityText:""}},n=e.buttons;return n&&n.length>0&&(t.buttons=n.map(function(e){return{openUrlAction:e.actionUrl,title:e.label}})),t})})]:void 0}}});var t,n,r},[e.previewMessages,e.config]);return f.jsx(PS,{messages:r,mode:n,config:e.config,disableAutoScroll:e.disableAutoScroll,preview:!0})},MS=function(e){var n,r=null!==(n=e.mode)&&void 0!==n?n:"normal",i=Z.useState(e.config),o=i[0],a=i[1],s=Z.useState(!!e.getConfig),l=s[0],c=s[1],u=Z.useState(),d=u[0],p=u[1];Z.useEffect(function(){var t=!1;return e.getConfig?(c(!0),p(void 0),e.getConfig().then(function(e){t||(a(e),c(!1),Yh("[ChatWidget] Config loaded from getConfig callback"))}).catch(function(e){t||(p(e),c(!1),Gh("[ChatWidget] Failed to load config: ".concat(e.message)))})):e.config&&(a(e.config),c(!1)),function(){t=!0}},[e.getConfig,e.config]);var h,m,v=(h=o,m=Rh(function(e){return e.connection.nonce}),Yh("nonce from Redux: ".concat(m)),om(h,m)),g=Z.useMemo(function(){var e;return t(t({},o),{connection:v,assetUrl:null!==(e=null==v?void 0:v.serverUrl)&&void 0!==e?e:Zh,env:o})},[v,o]),y=Rh(function(e){return e.connection.token}),b=Z.useMemo(function(){var e={items:[{delay:5,text:"We are having trouble communicating with the assistant right now. Re-trying in ${sec} seconds..."},{delay:5,text:"We are still having trouble communicating with the assistant right now. Re-trying in ${sec} seconds..."},{delay:0,text:"Sorry, we cannot communicate with the assistant right now. Please check your connection or try again later."}]};return(null==o?void 0:o.configurableMessages)&&Array.isArray(o.configurableMessages.items)&&o.configurableMessages.items.length>0&&(e=o.configurableMessages),{token:y,bot:{nick:"Bot",displayName:null==o?void 0:o.botName,avatarPath:null==o?void 0:o.avatarUrl},configurableMessages:e,hooks:null==o?void 0:o.hooks,env:o}},[y,null==o?void 0:o.botName,null==o?void 0:o.avatarUrl,null==o?void 0:o.configurableMessages,null==o?void 0:o.hooks]),w=function(e,t){var n=Z.useState(),r=n[0],i=n[1],o=Cm(),a=[t,e,o],s=Z.useRef(void 0);return Z.useEffect(function(){if(s.current){var n=s.current,r=n[0],a=n[1],l=n[2],c=[];r!==t&&c.push("options"),a!==e&&c.push("config"),l!==o&&c.push("dispatch"),c.length>0&&Yh("[useChatServer] Effect re-running due to: ".concat(c.join(", ")))}else Yh("[useChatServer] Effect running for first time");if(s.current=[t,e,o],!e||!t)return Yh("[useChatServer] Config or options null, not creating server"),void i(void 0);Yh("Creating new chat server - type: ".concat(e.type));var u=sb(e,t);return u.init(o),i(u),function(){Yh("Cleanup - disposing old server"),u.dispose()}},a),r}(l||d?null:v,l||d?null:b),x="widget-container--".concat(r);return l?f.jsx("div",{className:"widget-container widget-container--loading ".concat(x),children:f.jsx("div",{className:"xa-spinner-container visible",children:f.jsx("div",{className:"xa-spinner"})})}):d?f.jsx("div",{className:"widget-container widget-container--error ".concat(x),children:f.jsxs("div",{className:"widget-error-message",children:["Failed to load chat configuration: ",d.message]})}):f.jsx(nm.Provider,{value:g,children:f.jsx(lb.Provider,{value:w,children:f.jsx(BS,t({},e,{config:o}))})})};function LS(e){var t,n;return _x(e)&&(null===(n=null===(t=e.formConfig)||void 0===t?void 0:t.api)||void 0===n?void 0:n.key)||void 0}function DS(){return Fh()||Wh()}var BS=function(e){var n,r,i,o,a,s,l,c,u,d,p,h,m,v,g,y,b,w,x,k,S,C,_,E,N,I,T,j,O,P,A,R,M,L,D,B,z,U,F,q,H,W,V,$,K,Q,J,Y,G=Cm(),X=cb();rg();var ee=Rh(function(e){return e}),te=Z.useRef({}),ne=null!==(n=e.mode)&&void 0!==n?n:"normal",re="docked"===ne,ie="static"===ne,oe=!0===e.preview||"preview"===ne,ae="widget-container--".concat(ne),se=Uw(oe),le=vb(ee.chats),ce=Z.useMemo(function(){var t;return gb(null===(t=e.config)||void 0===t?void 0:t.cta,{hasConversation:le,arrivedViaChatLink:se})},[null===(r=e.config)||void 0===r?void 0:r.cta,le,se]),de=re&&!0===(null===(i=e.config.popOut)||void 0===i?void 0:i.enabled),fe=null!==(a=null===(o=e.config.popOut)||void 0===o?void 0:o.minWidth)&&void 0!==a?a:640,pe=Z.useRef(null),he=Z.useState(!1),me=he[0],ve=he[1],ge=Z.useState(!1),ye=ge[0],be=ge[1],we=Z.useState(!1),xe=we[0],ke=we[1],Se=Z.useState(!1),Ce=Se[0],_e=Se[1],Ee=Z.useState("undefined"==typeof window?0:window.innerWidth),Ne=Ee[0],Ie=Ee[1];Z.useEffect(function(){if(de&&"undefined"!=typeof window){var e=function(){return Ie(window.innerWidth)};return e(),window.addEventListener("resize",e),function(){return window.removeEventListener("resize",e)}}},[de]),Z.useEffect(function(){if(de&&"undefined"!=typeof IntersectionObserver&&pe.current){var e=new IntersectionObserver(function(e){var t=e[e.length-1];t&&(ve(!t.isIntersecting),t.isIntersecting&&(be(!0),ke(!1),_e(!1)))});return e.observe(pe.current),function(){return e.disconnect()}}},[de]);var Te,je="message"!==(null===(s=e.config.popOut)||void 0===s?void 0:s.after)||!!(null==(Te=ee.chats)?void 0:Te.some(function(e){var t,n;return"chat.msg"===e.type&&!!(null===(n=null===(t=e.user)||void 0===t?void 0:t.nick)||void 0===n?void 0:n.startsWith("visitor:"))})),Oe=de&&ye&&me&&!xe&&je,Pe=Ne>=fe,Ae=null!==(c=null===(l=e.config.popOut)||void 0===l?void 0:l.mobile)&&void 0!==c?c:"auto",Re=Oe&&!Pe&&"none"!==Ae&&!Ce,Me=Oe&&(Pe||Ce);function Le(){_e(!0)}var De=Z.useMemo(function(){return de&&"undefined"!=typeof document?document.createElement("div"):null},[de]),Be=Z.useRef({fromBottom:0,latest:!0});Z.useEffect(function(){if(De){var e=function(e){var t=e.target;if(t instanceof HTMLElement&&t.classList.contains("message-list-container")){var n=t.scrollHeight-t.clientHeight-t.scrollTop;Be.current={fromBottom:n,latest:n<=t.clientHeight}}};return De.addEventListener("scroll",e,!0),function(){return De.removeEventListener("scroll",e,!0)}}},[De]),AS(function(){if(De){De.className="widget-portal";var e=Me?document.body:pe.current;if(e&&De.parentElement!==e){var t=document.activeElement,n=t instanceof HTMLElement&&De.contains(t)?t:void 0,r=De.querySelector(".message-list-container");e.appendChild(De);var i=function(){if(r){var e=Be.current,t=e.fromBottom,n=e.latest,i=r.scrollHeight-r.clientHeight;r.scrollTop=n?i:Math.max(0,i-t)}};i(),null==n||n.focus({preventScroll:!0});var o=requestAnimationFrame(i),a=window.setTimeout(i,250);return function(){cancelAnimationFrame(o),window.clearTimeout(a)}}}},[De,Me]),Z.useEffect(function(){return function(){return null==De?void 0:De.remove()}},[De]);var ze,Ue=!0===(null===(u=e.config.header)||void 0===u?void 0:u.hidden)&&(re||ie)&&!Me,Fe=Z.useMemo(function(){return Ue&&e.config.menu&&"FOOTER"!==e.config.menu.menuButtonLocation?t(t({},e.config.menu),{menuButtonLocation:"FOOTER"}):e.config.menu},[Ue,e.config.menu]),qe=null===(p=null===(d=e.config.header)||void 0===d?void 0:d.actions)||void 0===p?void 0:p.refresh,He=!re&&!ie&&!oe&&(null===(m=null===(h=e.config.header)||void 0===h?void 0:h.actions)||void 0===m?void 0:m.minimize);Yh("docked: ".concat(re," static: ").concat(ie," preview: ").concat(oe," minimized: ").concat(null===(g=null===(v=e.config.header)||void 0===v?void 0:v.actions)||void 0===g?void 0:g.minimize)),ze="boolean"==typeof(null===(b=null===(y=e.config.header)||void 0===y?void 0:y.actions)||void 0===b?void 0:b.cancel)?!re&&!ie&&!oe&&(null===(x=null===(w=e.config.header)||void 0===w?void 0:w.actions)||void 0===x?void 0:x.cancel):!re&&!ie&&!oe,ee.visuals||(ee.visuals={});var We=(null===(k=e.config)||void 0===k?void 0:k.autoOpenOnWidth)?parseInt(e.config.autoOpenOnWidth,10):NaN,Ve=!isNaN(We)&&window.innerWidth>=We,$e=Z.useState(!He&&!ze||(isNaN(We)?ee.visuals.visible:Ve)),Ke=$e[0],Qe=$e[1],Je=Z.useState(!1);Je[0];var Ye=Je[1],Ge=Z.useRef(!1),Xe=Z.useRef(null),Ze=Z.useRef(Ve),et=Z.useContext(lb),tt=null===(C=null===(S=e.config)||void 0===S?void 0:S.autoOpenOnPattern)||void 0===C?void 0:C.patterns,nt=window.location.href,rt=tt&&tt.length>0,it=null==tt?void 0:tt.some(function(e){return nt.includes(e)}),ot=null===(E=null===(_=e.config)||void 0===_?void 0:_.autoOpenOnPattern)||void 0===E?void 0:E.minimumWidth,at=window.innerWidth,st=Z.useCallback(function(e){ie||oe||(Yh("setVisible: ".concat(e)),Qe(e),G(fb({visible:e})))},[G,ie,oe]);Z.useEffect(function(){var t,n,r=function(e){var t=document.getElementsByTagName("body")[0];t.tabIndex=-1,"Escape"===e.key&&t.focus()};return document.addEventListener("keydown",r),zw((null==ee?void 0:ee.sessionExpiration)||(null===(t=e.config)||void 0===t?void 0:t.sessionExpiration),null===(n=null==ee?void 0:ee.chats[ee.chats.length-1])||void 0===n?void 0:n.timestamp,null==ee||ee.lastTimestamp)&&(G(yg(void 0)),G({type:"reset"})),function(){document.removeEventListener("keydown",r),Xe.current&&clearTimeout(Xe.current)}},[]);var lt=Z.useState(!document.hidden),ct=lt[0],ut=lt[1];Z.useEffect(function(){var e=function(){ut(!document.hidden)};return document.addEventListener("visibilitychange",e),function(){document.removeEventListener("visibilitychange",e)}},[]),Z.useEffect(function(){et?ct?(Yh("Tab is VISIBLE - calling wakeup()"),et.wakeup()):(Yh("Tab is HIDDEN - calling sleep()"),et.sleep()):Yh("Tab visibility changed but no chatServer yet")},[et,G,ct]),Z.useEffect(function(){if(et){var e=function(){Yh("beforeunload - notifying router of user disconnecting"),et.notifyDisconnecting&&et.notifyDisconnecting("close_tab")};return window.addEventListener("beforeunload",e),function(){window.removeEventListener("beforeunload",e)}}},[et]),Z.useEffect(function(){ee.visuals.opened?st(!0):"normal"!==ne||Ve||st(!1),rt&&it&&st(!0),at<+ot&&st(!1),Ve&&!Ze.current&&(Ze.current=!0,st(!0))},[at,rt,it,ot,st,ee.visuals.opened,ne,Ve]);var dt=Z.useCallback(function(){Ge.current&&(Xe.current&&(clearTimeout(Xe.current),Xe.current=null),X(ym(!1)),Ye(!1),Ge.current=!1)},[X]),ft=Z.useCallback(function(){Ge.current||(X(ym(!0)),Ye(!0),Ge.current=!0),Xe.current&&clearTimeout(Xe.current),Xe.current=window.setTimeout(function(){dt()},2e3)},[X,dt]);var pt=wb();function ht(e){oe||("offline"!==ee.accountStatus||ee.isChatting)&&e&&(dt(),et.flush(),X(gm(e)))}function mt(){G({type:"reset"})}function vt(){te.current.style.display="none"}function gt(){G(fb({opened:!1,hasInteracted:!0})),st(!1)}function yt(){G(fb({opened:!0,hasInteracted:!0})),st(!0),setTimeout(function(){var e;null===(e=document.getElementById("chatWidgetInput"))||void 0===e||e.focus({preventScroll:!0})},100)}function bt(){G(fb({hasInteracted:!0}))}var wt=Z.useState(!1),xt=wt[0],kt=wt[1],St=Z.useState(null),Ct=St[0],_t=St[1],Et=Z.useCallback(function(e){$h(e.preselectChipLabel?{preselectChipLabel:e.preselectChipLabel}:void 0).then(function(t){t||(Yh("Form widget not available, showing modal fallback"),_t(e),kt(!0))})},[]),Nt=Z.useCallback(function(){kt(!1),_t(null)},[]);var It="offline"===ee.accountStatus&&!ee.isChatting,Tt=ee&&ee.chats;Yh('Rendering - accountStatus: "'.concat(ee.accountStatus,'", connectionStatus: "').concat(ee.connection.connectionStatus,'"'));var jt=e.config,Ot=e.onConnectionStatusChange,Pt=!0===(null===(N=null==jt?void 0:jt.actionBar)||void 0===N?void 0:N.enabled),At=Vw(),Rt=null!==(T=null===(I=null==jt?void 0:jt.actionBar)||void 0===I?void 0:I.buttons)&&void 0!==T?T:[],Mt=!(null==jt?void 0:jt.formWidgetKey)&&Rt.some(_x)&&!Rt.some(LS),Lt=Z.useState(function(){return Mt&&DS()}),Dt=Lt[0],Bt=Lt[1];Z.useEffect(function(){if(Mt&&!Dt){var e=0,t=setInterval(function(){e++,DS()?(Bt(!0),clearInterval(t)):e>=30&&clearInterval(t)},500);return function(){return clearInterval(t)}}},[Mt,Dt]);var zt=Z.useMemo(function(){var e=null==jt?void 0:jt.actionBar;return e&&Mt&&!Dt?t(t({},e),{buttons:e.buttons.filter(function(e){return!_x(e)})}):e},[null==jt?void 0:jt.actionBar,Mt,Dt]),Ut=Z.useMemo(function(){return Pt&&zt?Ex(zt.buttons,{chatDisabled:jt.disabled,formDisabled:At}):[]},[Pt,zt,null==jt?void 0:jt.disabled,At]),Ft=Pt&&Ut.length>0;$w(!It&&!e.preChatFormEnabled&&Ke&&!oe);var qt=ee.connection.connectionStatus;Z.useEffect(function(){Ot&&Ot(qt)},[qt,Ot]),Fw(null===(j=e.config)||void 0===j?void 0:j.middlewareUrl);var Ht=!At&&(!Pt||Ut.some(_x)),Wt=null!==(O=null==jt?void 0:jt.formWidgetKey)&&void 0!==O?O:Ut.map(LS).find(Boolean);Z.useEffect(function(){var e;Wt&&Ht&&(e=Wt)&&Hh(e).catch(function(e){console.warn("[chat-widget] Failed to preload form-widget script:",e)})},[Wt,Ht]),Z.useEffect(function(){if(Ft){var e=parseInt(document.body.getAttribute("data-xapp-action-bar-count")||"0",10);document.body.setAttribute("data-xapp-action-bar-count",String(e+1)),document.body.setAttribute("data-xapp-action-bar-enabled","true")}return function(){if(Ft){var e=parseInt(document.body.getAttribute("data-xapp-action-bar-count")||"0",10),t=Math.max(0,e-1);0===t?(document.body.removeAttribute("data-xapp-action-bar-enabled"),document.body.removeAttribute("data-xapp-action-bar-count")):document.body.setAttribute("data-xapp-action-bar-count",String(t))}}},[Ft]);var Vt=(null===(P=ee.agents["agent:robot"])||void 0===P?void 0:P.user)||(null==jt?void 0:jt.agent)||{nick:"agent:robot",avatarPath:jt.avatarUrl,display_name:"Agent"},$t=f.jsxs("div",{className:"widget-container ".concat(ae," ").concat(function(){var e;return Ke?"visible":(null===(e=ee.visuals)||void 0===e?void 0:e.hasInteracted)?"":"widget-container--initial-hidden"}()).concat(Ft?" widget-container--with-action-bar":"").concat(Me?" widget-container--popped":"").concat(Re?" widget-container--collapsed":""),children:[f.jsx(pS,{theme:null==jt?void 0:jt.theme}),!Ue&&f.jsx(uS,{accountStatus:ee.accountStatus,refreshOnClick:function(){jt.header.actions.refreshShowConfirmation?te.current.style.display="block":mt()},minimizeOnClick:Me?function(){Pe?ke(!0):_e(!1)}:gt,cancelOnClick:function(){(null==et?void 0:et.notifyDisconnecting)&&et.notifyDisconnecting("widget_close"),G({type:"reset"}),G(fb({opened:!1,hasInteracted:!0})),st(!1)},agent:Vt,canRefresh:qe,canMinimize:Me||He,canCancel:ze,config:null==jt?void 0:jt.header,menuConfig:jt.menu,debugMode:null===(M=null===(R=null===(A=e.config)||void 0===A?void 0:A.connection)||void 0===R?void 0:R.mcp)||void 0===M?void 0:M.debugMode,onSubmit:ht}),f.jsx(Jk,{visible:Ke,queuePosition:ee.queuePosition,isChatting:ee.isChatting,isOffline:It,messages:Tt,agents:ee.agents,agent:null==jt?void 0:jt.agent,lastRatingRequestTimestamp:ee.lastRatingRequestTimestamp,hasRating:ee.hasRating,visitorId:ee.visitorId,hasWsButton:!!ee.wsButton,messageMiddleware:e.messageMiddleware,textTypingStatusEnabled:null===(D=null===(L=e.config)||void 0===L?void 0:L.typingStatus)||void 0===D?void 0:D.textTypingStatusEnabled,disableAutoScroll:e.disableAutoScroll,onSend:function(e){oe||X(function(e){return function(t){return function(n,r){var i=r();("offline"!==i.accountStatus||i.isChatting)&&(e.msg&&n(vm(e.msg,i.visitor,+new Date)),t.sendChatMsgRequest(e,function(){}))}}}(e))},onWrite:function(e){oe||G(vm(e.msg,e.user))},onOpenUrl:pt,minimizeOnClick:gt}),f.jsx("div",{className:"xa-spinner-container ".concat(Ke&&"pending"===qt?"visible":""),children:f.jsx("div",{className:"xa-spinner"})}),"offline"===qt&&f.jsx(Yk,{}),ee.wsButton&&Ke&&f.jsx(IS,{button:ee.wsButton,onPress:function(e){var n,r;Yh("WS Button pressed: ".concat(e)),"spinning"===(null===(n=ee.wsButton)||void 0===n?void 0:n.pressBehavior)&&G({type:"ws_button_display",detail:t(t({},ee.wsButton),{isPressed:!0,timestamp:+new Date})}),et&&et.sendButtonPressed&&et.sendButtonPressed(e).catch(function(e){Gh("Failed to send button press: ".concat(e)),ee.wsButton&&G({type:"ws_button_display",detail:t(t({},ee.wsButton),{isPressed:!1,timestamp:+new Date})})}),"disabled"===(null===(r=ee.wsButton)||void 0===r?void 0:r.pressBehavior)&&(G({type:"ws_button_display",detail:t(t({},ee.wsButton),{isDismissing:!0,timestamp:+new Date})}),setTimeout(function(){G({type:"ws_button_dismiss",detail:{id:e,timestamp:+new Date}})},300))}}),f.jsx(Zx,{isAdmin:null==jt?void 0:jt.isAdmin,isChatting:ee.isChatting,placeholder:null===(B=null==jt?void 0:jt.input)||void 0===B?void 0:B.placeholder,sendButtonIcon:null===(U=null===(z=null==jt?void 0:jt.footer)||void 0===z?void 0:z.sendButton)||void 0===U?void 0:U.icon,sendButtonIconHover:null===(q=null===(F=null==jt?void 0:jt.footer)||void 0===F?void 0:F.sendButton)||void 0===q?void 0:q.iconHover,sendButtonIconDisabled:null===(W=null===(H=null==jt?void 0:jt.footer)||void 0===H?void 0:H.sendButton)||void 0===W?void 0:W.iconDisabled,visible:Ke,hasWsButton:!!ee.wsButton,menuConfig:Fe,footerConfig:null===(V=e.config)||void 0===V?void 0:V.footer,inputConfig:null===($=e.config)||void 0===$?void 0:$.input,disabled:oe,onChange:ft,onSubmit:ht,onFileUpload:function(e){var t;if(e.preventDefault(),!oe){var n=null===(t=null==e?void 0:e.dataTransfer)||void 0===t?void 0:t.files[0];n&&X(function(e){return function(t){return function(n,r){var i=r();if("offline"!==i.accountStatus||i.isChatting){var o={mimeType:e.type,name:e.name,size:e.size,url:window.URL.createObjectURL(e)};t.sendFile(e,function(e){e&&Yh("Error sending file",e)}),n({type:"synthetic",detail:{type:"visitor.send.file",attachment:o,user:{nick:""},attributes:{currentUrl:window.location.href},timestamp:+new Date}})}}}}(n))}}}),f.jsx("div",{className:"restartModal",ref:te,onClick:vt,children:f.jsx(TS,{onClose:vt,onReset:mt})})]});return f.jsxs(f.Fragment,{children:[de?f.jsx("div",{className:"widget-anchor",ref:pe,children:De&&ue.createPortal($t,De)}):$t,!Ft||!zt||Re&&"button"===Ae?f.jsx(zx,{addClass:Ke&&!Re?"visible":"",onClick:Re?Le:yt,config:ce,imageUrl:null===(J=null==jt?void 0:jt.chatButton)||void 0===J?void 0:J.imageUrl,visible:!Re&&Ke,hasInteracted:null===(Y=ee.visuals)||void 0===Y?void 0:Y.hasInteracted,onCtaDismiss:bt}):f.jsxs(f.Fragment,{children:[f.jsx(Nx,{config:t(t({},zt),{cta:gb(null!==(K=zt.cta)&&void 0!==K?K:jt.cta,{hasConversation:le,arrivedViaChatLink:se})}),visible:!Re&&Ke,chatDisabled:jt.disabled,formDisabled:At,hasUserInteracted:null===(Q=ee.visuals)||void 0===Q?void 0:Q.hasInteracted,onChatClick:Re?Le:yt,onChatMinimize:gt,onFormClick:Et,onCtaDismiss:bt}),xt&&Ct&&f.jsx(ek,{config:Ct,widgetEnv:jt,onClose:Nt})]}),f.jsx(NS,{enableErrorOverlay:null==jt?void 0:jt.enableErrorOverlay})]})},zS=function(e){var n,r=null!==(n=e.mode)&&void 0!==n?n:"normal",i="preview"===r?"static":r;return!0===e.preview||"preview"===r?f.jsx(RS,t({},e,{mode:i})):f.jsx(MS,t({},e))},US=function(e){var n=ow(),r=t(t({},e),{messageMiddleware:n});return f.jsx(zS,t({},r))},FS=function(e){var n,r,i,o,a,s,l=ow(),c=om(e.config),u=Z.useMemo(function(){var t,n,r,i,o;return Dw({connection:c,userId:null===(t=e.config)||void 0===t?void 0:t.userId,accessToken:null===(n=e.config)||void 0===n?void 0:n.accessToken,attributes:null===(r=e.config)||void 0===r?void 0:r.attributes,sessionExpiration:null===(i=e.config)||void 0===i?void 0:i.sessionExpiration,enableErrorOverlay:null===(o=e.config)||void 0===o?void 0:o.enableErrorOverlay})},[c,null===(n=e.config)||void 0===n?void 0:n.userId,null===(r=e.config)||void 0===r?void 0:r.accessToken,null===(i=e.config)||void 0===i?void 0:i.attributes,null===(o=e.config)||void 0===o?void 0:o.sessionExpiration,null===(a=e.config)||void 0===a?void 0:a.enableErrorOverlay]);if(null===(s=e.config)||void 0===s?void 0:s.disabled)return f.jsx(f.Fragment,{});var d=t(t({},e),{messageMiddleware:l,getConfig:e.getConfig});return f.jsx(_h,{store:u,children:f.jsx(zS,t({},d))})},qS=function(e){var n,r=null!==(n=e.mode)&&void 0!==n?n:"normal";return!0===e.preview||"preview"===r?f.jsx(US,t({},e)):f.jsx(FS,t({},e))};function HS(e){return e.split("-").map(function(e,t){return e.length?t?e[0].toUpperCase()+e.substring(1).toLowerCase():e.toLowerCase():""}).join("")}function WS(e){return Object.keys(e).reduce(function(t,n){var r=n,i="string";n.endsWith("-FLAG")?(r=n.substring(0,n.length-5),i="boolean"):n.endsWith("-MSEC")&&(r=n.substring(0,n.length-5),i="number");for(var o=r.split("_").map(HS),a=t;o.length>1;){var s=o.shift();"object"==typeof a&&(a[s]||(a[s]={}),a=a[s])}return"object"==typeof a&&(a[o.shift()]=function(e,t){return"string"===t?e:"boolean"===t?"TRUE"===e:"number"===t?parseFloat(e):e}(e[n],i)),t},{})}function VS(e,n){if(!n)return e;var r=t({},e);for(var o in n)if(n.hasOwnProperty(o)){var a=n[o],s=r[o];if(void 0===a)continue;null===a?r[o]=a:Array.isArray(a)?r[o]=i([],a,!0):"object"!=typeof a||Array.isArray(a)?r[o]=a:s&&"object"==typeof s&&!Array.isArray(s)?r[o]=VS(s,a):r[o]=t({},a)}return r}function $S(e){try{return localStorage.getItem(e)||void 0}catch(e){return}}function KS(){var e=$S(xg),t=$S(wg);if(!t){t=function(){var e=new Uint8Array(8);try{crypto.getRandomValues(e)}catch(t){e.forEach(function(t,n){return e[n]=Math.floor(256*Math.random())})}var t=Array.from(e,function(e){return e.toString(16).padStart(2,"0")}).join("");return"usr_".concat(Date.now().toString(36)).concat(t)}();try{localStorage.setItem(wg,t)}catch(e){}}return{sessionId:e,userId:t}}function QS(e){return"mcp"===im(e).type?KS():function(e){var t;try{var n=im(e),r="xappchat.".concat(n.serverUrl),i=$S(n.accountKey?"".concat(r,".").concat(n.accountKey):r);t=i?JSON.parse(i):void 0}catch(e){t=void 0}return{sessionId:"string"==typeof(null==t?void 0:t.sessionId)?t.sessionId:void 0,userId:"string"==typeof(null==t?void 0:t.userId)?t.userId:_w()}}(e)}function JS(){try{var e="1.108.1";return e||void 0}catch(e){return}}function YS(e){var t=function(){try{var e=document.getElementById("xapp-js");return(null==e?void 0:e.src)||void 0}catch(e){return}}();return Jv({eventsUrl:Gv(im(e).serverUrl),key:Xh().key||void 0,widgetType:"chat",source:"chat-widget",version:JS(),bundles:t?[t]:[],metadata:function(){var t=QS(e);return{sessionId:t.sessionId||"unknown",userId:t.userId}}})}var GS="{{INJECT}}";function XS(e){var t=e||GS;try{var n=JSON.parse(t),r=window.xaConfig||{};window.xaConfig=VS(n,r)}catch(e){t!==GS&&Gh("Chat Widget: injected config could not be parsed",{injected:t,error:e})}}function ZS(){return n(this,arguments,void 0,function(e){var t;return void 0===e&&(e=1e4),r(this,function(n){switch(n.label){case 0:t=Date.now(),n.label=1;case 1:return tC(window)?[3,3]:Date.now()-t>e?(console.warn("[xapp-chat-widget] Timeout waiting for window.xaConfig"),[2,{}]):[4,new Promise(function(e){return setTimeout(e,50)})];case 2:return n.sent(),[3,1];case 3:return[2,window.xaConfig]}})})}function eC(){var e=WS(process.env),n="true"===new URL(window.location.href).searchParams.get("isAdmin"),r=tC(window)?window.xaConfig:{};return t(t(t(t({},e),{isAdmin:n}),r),{attributes:t(t({},null==e?void 0:e.attributes),null==r?void 0:r.attributes)})}function tC(e){return!!e&&null!=e.xaConfig&&"object"==typeof e.xaConfig}var nC="chat-config-error";var rC=function(e){var t,n=e.env,r=function(){var e=Z.useState(!1),t=e[0],n=e[1];return Z.useEffect(function(){if(!document.getElementById("xapp-style")){var e=Xh(),t=document.createElement("link");t.id="xapp-style",t.href="".concat(e.path,"/xapp-chat-widget.css"),t.rel="stylesheet",document.head.appendChild(t),t.addEventListener("load",function(){n(!0)})}},[]),[t]}()[0];if(n.disabled)return f.jsx(f.Fragment,{});var i=n.mode,o=null===(t=window.xaConfig)||void 0===t?void 0:t.getConfig;return r?f.jsx(qS,{config:n,mode:i,getConfig:o}):f.jsx(f.Fragment,{})},iC=!1,oC=null;function aC(){return n(this,void 0,void 0,function(){var e,n,i;return r(this,function(r){switch(r.label){case 0:if(iC)return[2];iC=!0,r.label=1;case 1:return r.trys.push([1,,4,5]),XS(),tC(window)||window.xaSkipConfigWait?[3,3]:[4,ZS()];case 2:r.sent(),r.label=3;case 3:if(!function(e,t){return void 0===t&&(t={}),!!(null==e?void 0:e.disabled)||!!t.hasAsyncConfigLoader||!!sm(e).serverUrl}(e=eC(),{hasAsyncConfigLoader:!!(null===(i=window.xaConfig)||void 0===i?void 0:i.getConfig)}))return Gh("Chat Widget: not rendering, the configuration has no server URL",function(e){var t=sm(e);return{serverUrl:t.serverUrl,accountKey:t.accountKey,connectionType:t.type}}(e)),function(){if("debug"===window.xaLogLevel&&!document.getElementById(nC)){var e=document.createElement("div");e.id=nC,e.textContent="Chat Load Error",e.style.cssText="\n position: fixed;\n bottom: 20px;\n right: 20px;\n background-color: #f44336;\n color: white;\n padding: 12px 16px;\n border-radius: 4px;\n font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;\n font-size: 14px;\n font-weight: 500;\n z-index: 10000;\n box-shadow: 0 2px 8px rgba(0,0,0,0.2);\n transition: opacity ".concat(300,"ms ease-in-out;\n "),document.body.appendChild(e),setTimeout(function(){e.style.opacity="0",setTimeout(function(){return e.remove()},300)},2e3)}}(),[2];(n=document.getElementById("xapp-widget"))||((n=document.createElement("div")).id="xapp-widget",document.body.appendChild(n));try{YS(e)}catch(e){}return oC||(oC=ah.createRoot(n)),oC.render(f.jsx(rC,{env:e})),function(e){try{var n=Zv({mcp:e.disabled?void 0:e,notice:!0===e.agentNotice,siteTools:!0===e.webmcp,channelId:e.channelId}).verdict;if(!Vv("chat"))return;var r=QS(e),i=r.sessionId,o=r.userId,a=Wv({pageUrl:window.location.href,referrer:document.referrer,nav:navigator,verdict:n,screen:window.screen,viewport:{width:window.innerWidth,height:window.innerHeight}});Xv({eventsUrl:Gv(im(e).serverUrl),key:Xh().key||void 0,widgetType:"chat",metadata:t({sessionId:i||"unknown",userId:o},a)})}catch(e){}}(e),[3,5];case 4:return iC=!1,[7];case 5:return[2]}})})}return window.addEventListener("load",function(){aC()}),"complete"===document.readyState&&aC(),e.ChatMessagePart=mm,e.INJECT_PLACEHOLDER=GS,e.React=ee,e.injectConfig=XS,e.renderWidget=aC,e}({});
8
8
  //# sourceMappingURL=xapp-chat-widget.js.map