1 2!function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:{},n=(new e.Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="56306b27-900d-5b39-a438-5e00710508cd")}catch(e){}}(); 3import"./chunk-DSHWJW7U.js";import{a as Pt}from"./chunk-FLZNG7WM.js";import{b as yt}from"./chunk-Y53ZYOIU.js";import{a as b}from"./chunk-3YM57F2T.js";import{f as St}from"./chunk-Z5M2FKAZ.js";import"./chunk-5NDSS4DO.js";import"./chunk-TTUVP5SZ.js";import"./chunk-5CMUHLSG.js";import"./chunk-TNAGEFXD.js";import"./chunk-YH4N3M4B.js";import"./chunk-BHOSW24E.js";import{a as xt}from"./chunk-56LBQIQP.js";import"./chunk-IKWIL4NU.js";import"./chunk-5K5PYV5V.js";import"./chunk-TDGVUJZJ.js";import"./chunk-MWF7JXGK.js";import"./chunk-UJXOZNZV.js";import"./chunk-KS3Q7H57.js";import"./chunk-DAOAKQM2.js";import"./chunk-MGCQ5S6F.js";import"./chunk-MJXNRHWH.js";import"./chunk-BUOPWRDV.js";import{a as Ct,b as bt,d as Mt,e as wt}from"./chunk-UQU3EU23.js";import"./chunk-346ISJSG.js";import"./chunk-CNRKNNWP.js";import"./chunk-L6Z7ZO7O.js";import"./chunk-TLCCWCNW.js";import{a as ft}from"./chunk-5SJALNJN.js";import{a as pt,b as ut,i as _t}from"./chunk-XEY266ER.js";import"./chunk-SEDEP525.js";import"./chunk-SECBI6OV.js";import"./chunk-LXBG4CPT.js";import"./chunk-56KVT3OQ.js";import{I as mt,b as lt,d as $,g as dt,l as ht,q as gt}from"./chunk-MF7VZYLI.js";import{a as st,b as at,c as rt,e as ct}from"./chunk-NFMDOWTR.js";import"./chunk-QE6DXY66.js";import"./chunk-B5YZVWIB.js";import"./chunk-HCSN2NMS.js";import"./chunk-FDIRDMLL.js";import"./chunk-XQLUXGKM.js";import"./chunk-3JHJJCIF.js";import"./chunk-J4X36CU5.js";import"./chunk-X3ZU2Z3D.js";import"./chunk-QZXCI4ZV.js";import"./chunk-VO633UWN.js";import{f as ot}from"./chunk-XIKGSSI2.js";import"./chunk-MNZQGPDO.js";import"./chunk-NK2KZLT6.js";import"./chunk-MU5APV2L.js";import"./chunk-KRFZY2QT.js";import"./chunk-DFSGG2NH.js";import"./chunk-MREDPIUE.js";import"./chunk-BWICLBYB.js";import"./chunk-TYTNPDEC.js";import{f as it}from"./chunk-WAPZ5LEW.js";import{B as nt,L as T,z as et}from"./chunk-746D4QTP.js";import{Ac as C,Ba as q,Dc as d,Fd as tt,Ib as G,Lc as Y,Mc as J,Oc as Q,Pc as w,Sc as g,Tc as x,Ua as O,Uc as R,cc as m,dc as p,ec as K,f as A,g as P,gc as E,hc as W,ic as M,jc as s,kc as a,la as N,lb as L,lc as l,nd as j,od as X,pd as Z,qa as u,qb as r,uc as v,va as _,wa as f}from"./chunk-BZJI6Z2X.js";import{a as V,b as U}from"./chunk-CS7K6LXP.js";var I={logger:typeof console<"u"?console:void 0,WebSocket:typeof WebSocket<"u"?WebSocket:void 0},c={log(...i){this.enabled&&(i.push(Date.now()),I.logger.log("[ActionCable]",...i))}},y=()=>new Date().getTime(),k=i=>(y()-i)/1e3,Et=(()=>{class i{constructor(t){this.visibilityDidChange=this.visibilityDidChange.bind(this),this.connection=t,this.reconnectAttempts=0}start(){this.isRunning()||(this.startedAt=y(),delete this.stoppedAt,this.startPolling(),addEventListener("visibilitychange",this.visibilityDidChange),c.log(`ConnectionMonitor started. stale threshold = ${this.constructor.staleThreshold} s`))}stop(){this.isRunning()&&(this.stoppedAt=y(),this.stopPolling(),removeEventListener("visibilitychange",this.visibilityDidChange),c.log("ConnectionMonitor stopped"))}isRunning(){return this.startedAt&&!this.stoppedAt}recordMessage(){this.pingedAt=y()}recordConnect(){this.reconnectAttempts=0,delete this.disconnectedAt,c.log("ConnectionMonitor recorded connect")}recordDisconnect(){this.disconnectedAt=y(),c.log("ConnectionMonitor recorded disconnect")}startPolling(){this.stopPolling(),this.poll()}stopPolling(){clearTimeout(this.pollTimeout)}poll(){this.pollTimeout=setTimeout(()=>{this.reconnectIfStale(),this.poll()},this.getPollInterval())}getPollInterval(){let{staleThreshold:t,reconnectionBackoffRate:n}=this.constructor,o=Math.pow(1+n,Math.min(this.reconnectAttempts,10)),At=(this.reconnectAttempts===0?1:n)*Math.random();return t*1e3*o*(1+At)}reconnectIfStale(){this.connectionIsStale()&&(c.log(`ConnectionMonitor detected stale connection. reconnectAttempts = ${this.reconnectAttempts}, time stale = ${k(this.refreshedAt)} s, stale threshold = ${this.constructor.staleThreshold} s`),this.reconnectAttempts++,this.disconnectedRecently()?c.log(`ConnectionMonitor skipping reopening recent disconnect. time disconnected = ${k(this.disconnectedAt)} s`):(c.log("ConnectionMonitor reopening"),this.connection.reopen()))}get refreshedAt(){return this.pingedAt?this.pingedAt:this.startedAt}connectionIsStale(){return k(this.refreshedAt)>this.constructor.staleThreshold}disconnectedRecently(){return this.disconnectedAt&&k(this.disconnectedAt)<this.constructor.staleThreshold}visibilityDidChange(){document.visibilityState==="visible"&&setTimeout(()=>{(this.connectionIsStale()||!this.connection.isOpen())&&(c.log(`ConnectionMonitor reopening stale connection on visibilitychange. visibilityState = ${document.visibilityState}`),this.connection.reopen())},200)}}return i.staleThreshold=6,i.reconnectionBackoffRate=.15,i})(),vt={message_types:{welcome:"welcome",disconnect:"disconnect",ping:"ping",confirmation:"confirm_subscription",rejection:"reject_subscription"}
3,disconnect_reasons:{unauthorized:"unauthorized",invalid_request:"invalid_request",server_restart:"server_restart",remote:"remote"},default_mount_path:"/cable",protocols:["actioncable-v1-json","actioncable-unsupported"]},{message_types:S,protocols:z}=vt,Wt=z.slice(0,z.length-1),Ot=[].indexOf,Tt=(()=>{class i{constructor(t){this.open=this.open.bind(this),this.consumer=t,this.subscriptions=this.consumer.subscriptions,this.monitor=new Et(this),this.disconnected=!0}send(t){return this.isOpen()?(this.webSocket.send(JSON.stringify(t)),!0):!1}open(){if(this.isActive())return c.log(`Attempted to open WebSocket, but existing socket is ${this.getState()}`),!1;{let t=[...z,...this.consumer.subprotocols||[]];return c.log(`Opening WebSocket, current state is ${this.getState()}, subprotocols: ${t}`),this.webSocket&&this.uninstallEventHandlers(),this.webSocket=new I.WebSocket(this.consumer.url,t),this.installEventHandlers(),this.monitor.start(),!0}}close({allowReconnect:t}={allowReconnect:!0}){if(t||this.monitor.stop(),this.isOpen())return this.webSocket.close()}reopen(){if(c.log(`Reopening WebSocket, current state is ${this.getState()}`),this.isActive())try{return this.close()}catch(t){c.log("Failed to reopen WebSocket",t)}finally{c.log(`Reopening WebSocket in ${this.constructor.reopenDelay}ms`),setTimeout(this.open,this.constructor.reopenDelay)}else return this.open()}getProtocol(){if(this.webSocket)return this.webSocket.protocol}isOpen(){return this.isState("open")}isActive(){return this.isState("open","connecting")}triedToReconnect(){return this.monitor.reconnectAttempts>0}isProtocolSupported(){return Ot.call(Wt,this.getProtocol())>=0}isState(...t){return Ot.call(t,this.getState())>=0}getState(){if(this.webSocket){for(let t in I.WebSocket)if(I.WebSocket[t]===this.webSocket.readyState)return t.toLowerCase()}return null}installEventHandlers(){for(let t in this.events){let n=this.events[t].bind(this);this.webSocket[`on${t}`]=n}}uninstallEventHandlers(){for(let t in this.events)this.webSocket[`on${t}`]=function(){}}}return i.reopenDelay=500,i})();Tt.prototype.events={message(i){if(!this.isProtocolSupported())return;let{identifier:e,message:t,reason:n,reconnect:o,type:h}=JSON.parse(i.data);switch(this.monitor.recordMessage(),h){case S.welcome:return this.triedToReconnect()&&(this.reconnectAttempted=!0),this.monitor.recordConnect(),this.subscriptions.reload();case S.disconnect:return c.log(`Disconnecting. Reason: ${n}`),this.close({allowReconnect:o});case S.ping:return null;case S.confirmation:return this.subscriptions.confirmSubscription(e),this.reconnectAttempted?(this.reconnectAttempted=!1,this.subscriptions.notify(e,"connected",{reconnected:!0})):this.subscriptions.notify(e,"connected",{reconnected:!1});case S.rejection:return this.subscriptions.reject(e);default:return this.subscriptions.notify(e,"received",t)}},open(){if(c.log(`WebSocket onopen event, using '${this.getProtocol()}' subprotocol`),this.disconnected=!1,!this.isProtocolSupported())return c.log("Protocol is unsupported. Stopping monitor and disconnecting."),this.close({allowReconnect:!1})},close(i){if(c.log("WebSocket onclose event"),!this.disconnected)return this.disconnected=!0,this.monitor.recordDisconnect(),this.subscriptions.notifyAll("disconnected",{willAttemptReconnect:this.monitor.isRunning()})},error(){c.log("WebSocket onerror event")}};var Rt=function(i,e){if(e!=null)for(let t in e){let n=e[t];i[t]=n}return i},B=class{constructor(e,t={},n){this.consumer=e,this.identifier=JSON.stringify(t),Rt(this,n)}perform(e,t={}){return t.action=e,this.send(t)}send(e){return this.consumer.send({command:"message",identifier:this.identifier,data:JSON.stringify(e)})}unsubscribe(){return this.consumer.subscriptions.remove(this)}},D=class{constructor(e){this.subscriptions=e,this.pendingSubscriptions=[]}guarantee(e){this.pendingSubscriptions.indexOf(e)==-1?(c.log(`SubscriptionGuarantor guaranteeing ${e.identifier}`),this.pendingSubscriptions.push(e)):c.log(`SubscriptionGuarantor already guaranteeing ${e.identifier}`),this.startGuaranteeing()}forget(e){c.log(`SubscriptionGuarantor forgetting ${e.identifier}`),this.pendingSubscriptions=this.pendingSubscriptions.filter(t=>t!==e)}startGuaranteeing(){this.stopGuaranteeing(),this.retrySubscribing()}stopGuaranteeing(){clearTimeout(this.retryTimeout)}retrySubscribing(){this.retryTimeout=setTimeout(()=>{this.subscriptions&&typeof this.subscriptions.subscribe=="function"&&this.pendingSubscriptions.map(e=>{c.log(`SubscriptionGuarantor resubscribing ${e.identifier}`),this.subscriptions.subscribe(e)})},500)}},H=class{constructor(e){this.consumer=e,this.guarantor=new D(this),this.subscriptions=[]}create(e,t){let n=e,o=typeof n=="object"?n:{channel:n},h=new B(this.consumer,o,t);return this.add(h)}add(e){return this.subscriptions.push(e),this.consumer.ensureActiveConnection(),this.notify(e,"initialized"),this.subscribe(e),e}remove(e){return this.forget(e),this.findAll(e.identifier).length||this.sendCommand(e,"unsubscribe"),e}reject(e){return this.findAll(e).map(t=>(this.forget(t),this.notify(t,"rejected"),t))}forget(e){return this.guarantor.forget(e),this.subscriptions=this.subscriptions.filter(t=>t!==e),e}findAll(e){return this.subscriptions.filter(t=>t.identifier===e)}reload(){return this.subscriptions.map(e=>this.subscribe(e))}notifyAll(e,...t){return this.subscriptions.map(n=>this.notify(n,e,...t))}notify(e,t,...n){let o;return typeof e=="string"?o=this.findAll(e):o=[e],o.map(h=>typeof h[t]=="function"?h[t](...n):void 0)}subscribe(e){this.sendCommand(e,"subscribe")&&this.guarantor.guarantee(e)}confirmSubscription(e){c.log(`Subscription confirmed ${e}`),this.findAll(e).map(t=>this.guarantor.forget(t))}sendCommand(e,t){let{identifier:n}=e;return this.consumer.send({command:t,identifier:n})}},F=class{constructor(e){this._url=e,this.subscriptions=new H(this),this.connection=new Tt(this),this.subprotocols=[]}get url(){return jt(this._url)}send(e){return this.connection.send(e)}connect(){return this.connection.open()}disconnect(){return this.connection.close({allowReconnect:!1})}ensureActiveConnection(){if(!this.connection.isActive())return this.connection.open()}addSubProtocol(e){this.subprotocols=[...this.subprotocols,e]}};function jt(i){if(typeof i=="function"&&(i=i()),i&&!/^wss?:/i.test(i)){let e=document.createElement("a");return e.href=i,e.href=e.href,e.protocol=e.protocol.replace("http","ws"),e.href}else return i}function kt(i=$t("url")||vt.default_mount_path){return new F(i)}function $t(i){let e=document.head.querySelector(`meta[name='action-cable-${i}']`);if(e)return e.getAttribute("content")}var It=(()=>{class i{http=u(it);utilsService=u(xt);cable=null;chatChannel=null;sessionId=null;userId=null;isBrowser;
3messagesSubject=new P([]);messages$=this.messagesSubject.asObservable();sessionSubject=new P(null);session$=this.sessionSubject.asObservable();typingSubject=new A;typing$=this.typingSubject.asObservable();connectionStatusSubject=new P("disconnected");connectionStatus$=this.connectionStatusSubject.asObservable();responseTimeoutSubject=new A;responseTimeout$=this.responseTimeoutSubject.asObservable();responseTimeoutTimer=null;RESPONSE_TIMEOUT_MS=3e4;platformId=u(O);constructor(){this.isBrowser=T(this.platformId),c.enabled=!0}initializeChat(t,n=!1){this.userId=t,this.sessionId=this.getOrCreateSessionId(),this.connectToCable(),n||this.loadChatHistory()}sendMessage(t){let n={content:t,role:"user",timestamp:new Date,sessionId:this.sessionId};return this.addMessageToState(n),this.startResponseTimeout(),this.http.post("/api/v4/chat.json",{message:t,session_id:this.sessionId})}escalateToHuman(t){return this.http.post("/api/v4/chat/escalate.json",{session_id:this.sessionId,reason:t||"User requested human assistance"})}loadChatHistory(){if(!this.sessionId)return;let t=this.http.get(`/api/v4/chat/history/${this.sessionId}.json`);this.utilsService.withoutHttpErrorInSnackbar(t).subscribe({next:n=>{let o=(n?.messages||[]).map(h=>this.transformMessage(h));this.messagesSubject.next(o),n.session_id&&this.sessionSubject.next({id:n.id||"",sessionId:n.session_id,userId:"",status:n.status,currentHandler:n.current_handler,createdAt:new Date,updatedAt:new Date})},error:n=>{n.status===404||console.error("Failed to load chat history:",n)}})}connectToCable(){if(!this.sessionId){console.error("Cannot connect to cable: sessionId is null");return}if(!this.isBrowser)return;this.connectionStatusSubject.next("connecting");let t=window.location.protocol==="https:"?"wss:":"ws:",n=window.location.host,o=`${t}//${n}/cable`;this.cable=kt(o),this.chatChannel=this.cable.subscriptions.create({channel:"ChatChannel",session_id:this.sessionId},{connected:()=>{this.connectionStatusSubject.next("connected")},disconnected:()=>{this.connectionStatusSubject.next("disconnected")},received:h=>{this.handleIncomingMessage(h)}})}handleIncomingMessage(t){switch(t.type){case"message":{let n=this.transformMessage(t.message);this.addMessageToState(n),this.typingSubject.next(!1),this.clearResponseTimeout();break}case"typing":this.typingSubject.next(!0);break;case"escalated":this.handleEscalation(t),this.clearResponseTimeout();break;case"escalation_suggestion":this.handleEscalationSuggestion(t);break;case"connected":break;default:}}handleEscalation(t){let n={id:`system-${Date.now()}`,content:t.message||"You have been connected with a human agent.",role:"system",timestamp:new Date,sessionId:this.sessionId,isTransition:!0};this.addMessageToState(n);let o=this.sessionSubject.value;o&&this.sessionSubject.next(U(V({},o),{status:"escalated",currentHandler:"human",zendeskTicketId:t.ticket_id}))}handleEscalationSuggestion(t){let n={id:`suggestion-${Date.now()}`,content:`Would you like to speak with a human agent? ${t.reason||""}`,role:"system",timestamp:new Date,sessionId:this.sessionId,suggestEscalation:!0,escalationReason:t.reason};this.addMessageToState(n)}transformMessage(t){return{id:t.id?.toString()||`msg-${Date.now()}`,content:t.content,role:t.role,timestamp:new Date(t.created_at||t.timestamp),sessionId:this.sessionId,citations:t.metadata?.citations,isError:t.metadata?.is_error,isHuman:t.metadata?.is_human,agentName:t.metadata?.agent_name,agentId:t.metadata?.agent_id,isAgentIntroduction:t.metadata?.is_agent_introduction,isTransition:t.metadata?.is_transition,suggestEscalation:t.metadata?.is_escalation_suggestion,escalationReason:t.metadata?.escalation_reason}}addMessageToState(t){let n=this.messagesSubject.value;this.messagesSubject.next([...n,t])}addErrorMessage(t){let n={id:`error-${Date.now()}`,content:t,role:"system",timestamp:new Date,sessionId:this.sessionId||"",isError:!0};this.addMessageToState(n)}getOrCreateSessionId(){if(!this.isBrowser)return this.generateSessionId();try{let t=this.userId?`chat_session_id_${this.userId}`:"chat_session_id_anonymous",n=localStorage.getItem(t);return n||(n=this.generateSessionId(),localStorage.setItem(t,n)),n}catch(t){return console.warn("localStorage unavailable, generating temporary session ID:",t),this.generateSessionId()}}generateSessionId(){return`session-${Date.now()}-${Math.random().toString(36).substring(2,11)}`}disconnect(){this.chatChannel&&(this.chatChannel.unsubscribe(),this.chatChannel=null),this.cable&&(this.cable.disconnect(),this.cable=null),this.connectionStatusSubject.next("disconnected")}clearHistory(){if(this.messagesSubject.next([]),this.sessionSubject.next(null),this.isBrowser)try{let t=this.userId?`chat_session_id_${this.userId}`:"chat_session_id_anonymous";localStorage.removeItem(t)}catch(t){console.warn("Failed to clear localStorage:",t)}this.sessionId=null}startResponseTimeout(){this.clearResponseTimeout(),this.responseTimeoutTimer=setTimeout(()=>{console.warn("Chat response timeout - no response received within 30 seconds"),this.typingSubject.next(!1),this.responseTimeoutSubject.next();let t={id:`timeout-${Date.now()}`,content:"I'm taking longer than expected to respond. Please try again.",role:"system",timestamp:new Date,sessionId:this.sessionId,isError:!0};this.addMessageToState(t)},this.RESPONSE_TIMEOUT_MS)}clearResponseTimeout(){this.responseTimeoutTimer&&(clearTimeout(this.responseTimeoutTimer),this.responseTimeoutTimer=null)}cancelWaitingForResponse(){this.clearResponseTimeout(),this.typingSubject.next(!1)}static \u0275fac=function(n){return new(n||i)};static \u0275prov=N({token:i,factory:i.\u0275fac,providedIn:"root"})}return i})();var Bt=["messagesContainer"],Dt=(i,e)=>e.id;function Ht(i,e){if(i&1){let t=v();s(0,"button",5),C("click",function(){_(t);let o=d();return f(o.toggleChat())}),l(1,"i",6),a()}}function Ft(i,e){i&1&&l(0,"i",11)}function Vt(i,e){i&1&&l(0,"i",6)}function Ut(i,e){i&1&&l(0,"i",16)}function Nt(i,e){i&1&&l(0,"i",17)}function qt(i,e){i&1&&l(0,"i",18)}function Lt(i,e){i&1&&l(0,"i",19)}function Gt(i,e){i&1&&(s(0,"span"),l(1,"i",11),a())}function Kt(i,e){i&1&&(s(0,"span"),l(1,"i",42),a())}function Yt(i,e){i&1&&(s(0,"span"),l(1,"i",43),a())}function Jt(i,e){if(i&1&&(s(0,"div",38),m(1,Gt,2,0,"span")(2,Kt,2,0,"span")(3,Yt,2,0,"span"),s(4,"span"),g(5),a()()),i&2){let t=d().$implicit,n=d(2);r(),p(n.isHumanMessage(t)?1:n.isAssistantMessage(t)?2:3),r(4),x(n.getSenderName(t))}}function Qt(i,e){if(i&1&&(s(0,"a",46)(1,"span",47),g(2),a(),s(3,"span"),l(4,"i",48),a()()),i&2){let t=e.$implicit;M("href",t.url,L),r(2),x(t.title)}}function Xt(i,e){if(i&1&&(s(0,"div",40)(1,"div",44)(2,"span",10),l(3,"i",45),a(),s(4,"span"),g(5,"Related Articles:"),a()(),E(6,Qt,5,2,"a",46,K),a()),i&2){let t=d().$implicit;r(6),W(t.citations)}}function Zt(i,e){if(i&1&&(s(0,"div",36)(1,"div",37),m(2,Jt,6,2,"div",38),s(3,"div",39),g(4),a(),m(5,Xt,8,0,"div",40),s(6,"div",41),g(7),j(8,"date"),a()()()),i&2){let t=e.$implicit,n=d(2);
3w("user-message",n.isUserMessage(t))("assistant-message",n.isAssistantMessage(t))("human-message",n.isHumanMessage(t))("system-message",n.isSystemMessage(t)),r(),w("error-message",t.isError),r(),p(n.isUserMessage(t)?-1:2),r(2),R(" ",t.content," "),r(),p(t.citations&&t.citations.length>0?5:-1),r(2),R(" ",Z(8,14,t.timestamp,"short")," ")}}function te(i,e){i&1&&(s(0,"div",28)(1,"span",49),l(2,"i",50),a(),s(3,"h3"),g(4,"Welcome to Support Chat"),a(),s(5,"p"),g(6,"Ask me anything! I'm here to help you with your questions."),a()())}function ee(i,e){if(i&1&&(s(0,"div",29)(1,"div",51)(2,"div",38)(3,"span",10),l(4,"i",42),a(),s(5,"span"),g(6),a()(),s(7,"div",52),l(8,"span",53)(9,"span",53)(10,"span",53),a()()()),i&2){let t=d(2);r(6),x(t.isHandledByHuman()?"Support Agent":"AI Assistant")}}function ne(i,e){i&1&&(s(0,"mat-error"),g(1,"Message is too long (max 1000 characters)"),a())}function ie(i,e){if(i&1){let t=v();s(0,"div",3)(1,"div",7)(2,"div",8)(3,"div",9)(4,"span",10),m(5,Ft,1,0,"i",11)(6,Vt,1,0,"i",6),a(),s(7,"span",12),g(8),a()(),s(9,"div",13)(10,"div",14)(11,"span",15),j(12,"titlecase"),m(13,Ut,1,0,"i",16)(14,Nt,1,0,"i",17)(15,qt,1,0,"i",18)(16,Lt,1,0,"i",19),a(),s(17,"button",20),C("click",function(){_(t);let o=d();return f(o.resetConversation())}),l(18,"i",21),a(),s(19,"button",22),C("click",function(){_(t);let o=d();return f(o.minimizeChat())}),l(20,"i",23),a(),s(21,"button",24),C("click",function(){_(t);let o=d();return f(o.closeChat())}),l(22,"i",25),a()()()()(),s(23,"div",26,0),E(25,Zt,9,17,"div",27,Dt,!1,te,7,0,"div",28),m(28,ee,11,1,"div",29),a(),s(29,"div",30)(30,"div",31)(31,"mat-form-field",32)(32,"mat-label"),g(33,"Type your message..."),a(),s(34,"textarea",33),C("keypress",function(o){_(t);let h=d();return f(h.onKeyPress(o))}),a(),m(35,ne,2,0,"mat-error"),a(),s(36,"button",34),C("click",function(){_(t);let o=d();return f(o.sendMessage())}),l(37,"i",35),a()()()()}if(i&2){let t,n=d();r(),Q("background-color","var(--mc-primary-500)"),r(4),p(n.isHandledByHuman()?5:6),r(3),x(n.isHandledByHuman()?"Support":"Support Chat"),r(3),w("text-warning",n.connectionStatus==="disconnected"),M("matTooltip",X(12,13,n.connectionStatus)),r(2),p((t=n.connectionStatus)==="connected"?13:t==="connecting"?14:t==="disconnected"?15:16),r(12),W(n.messages),r(3),p(n.isTyping?28:-1),r(6),M("formControl",n.messageControl),r(),p(n.messageControl.hasError("maxlength")?35:-1),r(),M("disabled",n.messageControl.invalid||n.isTyping)}}function oe(i,e){i&1&&l(0,"i",11)}function se(i,e){i&1&&l(0,"i",6)}function ae(i,e){if(i&1){let t=v();s(0,"button",54),C("click",function(){_(t);let o=d();return f(o.restoreChat())})("keydown.enter",function(){_(t);let o=d();return f(o.restoreChat())})("keydown.space",function(){_(t);let o=d();return f(o.restoreChat())}),s(1,"span",55),m(2,oe,1,0,"i",11)(3,se,1,0,"i",6),a(),s(4,"span"),g(5,"Support Chat"),a()()}if(i&2){let t=d();r(2),p(t.isHandledByHuman()?2:3)}}var $e=(()=>{class i{chatService=u(It);userService=u(St);appService=u(ot);platformId=u(O);messagesContainer=tt.required("messagesContainer");isOpen=!1;isMinimized=!1;isTyping=!1;connectionStatus="disconnected";currentUser;messages=[];session=null;messageControl=new ht("",[$.required,$.maxLength(1e3)]);shouldScrollToBottom=!1;destroyRef=u(q);constructor(){this.currentUser=this.userService.currentUser}ngOnInit(){this.appService.currentBrand?.enable_ai_chat_bot===!0&&(this.chatService.messages$.pipe(b(this.destroyRef)).subscribe(t=>{this.messages=t,this.shouldScrollToBottom=!0}),this.chatService.session$.pipe(b(this.destroyRef)).subscribe(t=>{this.session=t}),this.chatService.typing$.pipe(b(this.destroyRef)).subscribe(t=>{this.isTyping=t,t&&(this.shouldScrollToBottom=!0)}),this.chatService.connectionStatus$.pipe(b(this.destroyRef)).subscribe(t=>{this.connectionStatus=t}),this.chatService.responseTimeout$.pipe(b(this.destroyRef)).subscribe(()=>{this.isTyping=!1,this.shouldScrollToBottom=!0}),this.userService.currentUserResolved?this.initializeChat():this.userService.changeCurrentUser.subscribe(()=>{this.initializeChat()}))}ngAfterViewChecked(){this.shouldScrollToBottom&&(this.scrollToBottom(),this.shouldScrollToBottom=!1)}ngOnDestroy(){this.chatService.disconnect(),this.lockBodyScroll(!1)}toggleChat(){this.isOpen=!this.isOpen,this.isOpen?(this.isMinimized=!1,this.shouldScrollToBottom=!0,this.lockBodyScroll(!0)):this.lockBodyScroll(!1)}minimizeChat(){this.isMinimized=!0}restoreChat(){this.isMinimized=!1,this.shouldScrollToBottom=!0}closeChat(){this.isOpen=!1,this.isMinimized=!1,this.lockBodyScroll(!1)}resetConversation(){this.session=null,this.isTyping=!1,this.chatService.clearHistory(),this.chatService.disconnect(),this.initializeChat(!0),this.shouldScrollToBottom=!0}
3sendMessage(){if(this.messageControl.invalid||!this.messageControl.value?.trim())return;let t=this.messageControl.value.trim();this.messageControl.setValue(""),this.isTyping=!0,this.chatService.sendMessage(t).subscribe({next:()=>{},error:n=>{console.error("Failed to send message:",n),this.chatService.cancelWaitingForResponse(),this.isTyping=!1,this.chatService.addErrorMessage("Failed to send message. Please try again.")}})}onKeyPress(t){t.key==="Enter"&&!t.shiftKey&&(t.preventDefault(),this.sendMessage())}escalateToHuman(){this.chatService.escalateToHuman().subscribe({next:()=>{},error:t=>{console.error("Failed to escalate:",t)}})}scrollToBottom(){try{let t=this.messagesContainer();t&&(t.nativeElement.scrollTop=t.nativeElement.scrollHeight)}catch(t){console.error("Scroll to bottom failed:",t)}}isUserMessage(t){return t.role==="user"}isAssistantMessage(t){return t.role==="assistant"&&!t.isHuman}isHumanMessage(t){return t.role==="assistant"&&t.isHuman===!0}isSystemMessage(t){return t.role==="system"}getSenderName(t){return this.isUserMessage(t)?"You":this.isHumanMessage(t)?t.agentName||"Support Agent":this.isAssistantMessage(t)?"AI Assistant":"System"}isHandledByHuman(){return this.session?.currentHandler==="human"}isEscalated(){return this.session?.status==="escalated"}initializeChat(t=!1){let n=this.currentUser?.id?String(this.currentUser.user_id):null;this.chatService.initializeChat(n,t)}scrollPosition=0;lockBodyScroll(t){T(this.platformId)&&(window.innerWidth>768||(t?(this.scrollPosition=window.scrollY,document.body.classList.add("chat-widget-open"),document.body.style.setProperty("--chat-scroll-position",`-${this.scrollPosition}px`)):(document.body.classList.remove("chat-widget-open"),document.body.style.removeProperty("--chat-scroll-position"),window.scrollTo(0,this.scrollPosition))))}static \u0275fac=function(n){return new(n||i)};static \u0275cmp=G({type:i,selectors:[["app-chat-widget"]],viewQuery:function(n,o){n&1&&Y(o.messagesContainer,Bt,5),n&2&&J()},decls:4,vars:7,consts:[["messagesContainer",""],[1,"chat-widget-container"],["mat-fab","","aria-label","Open chat",1,"custom","lg","primary"],[1,"chat-window"],["tabindex","0","mat-raised-button","","aria-label","Restore chat window",1,"custom","pill","primary"],["mat-fab","","aria-label","Open chat",1,"custom","lg","primary",3,"click"],[1,"fa-regular","fa-message-bot"],[1,"chat-header"],[1,"header-content","d-flex","align-items-center","justify-content-between"],[1,"header-title"],[1,"me-1"],[1,"fa-solid","fa-user"],[1,"title-text"],[1,"header-actions"],[1,"d-flex","align-items-center"],["matTooltipClass","tooltip shadow-sm",1,"me-1",3,"matTooltip"],[1,"fa-solid","fa-circle-check"],[1,"fa-solid","fa-spinner","fa-spin"],[1,"fa-solid","fa-circle-xmark"],[1,"fa-solid","fa-circle-question"],["mat-icon-button","","matTooltip","Start new conversation","matTooltipClass","tooltip shadow-sm","aria-label","Reset conversation",1,"custom","white","me-1",3,"click"],[1,"fa-solid","fa-arrows-rotate"],["mat-icon-button","","aria-label","Minimize chat",1,"custom","white","me-1",3,"click"],[1,"fa-solid","fa-window-minimize"],["mat-icon-button","","aria-label","Close chat",1,"custom","white",3,"click"],[1,"fa-solid","fa-xmark"],[1,"messages-container"],[1,"message-wrapper",3,"user-message","assistant-message","human-message","system-message"],[1,"welcome-message"],[1,"message-wrapper","assistant-message"],[1,"input-area"],[1,"input-container"],["appearance","outline",1,"message-input"],["matInput","","rows","1","cdkTextareaAutosize","","cdkAutosizeMinRows","1","cdkAutosizeMaxRows","4","placeholder","Ask a question...",3,"keypress","formControl"],["mat-icon-button","","aria-label","Send message",1,"custom","primary",3,"click","disabled"],[1,"fa-solid","fa-paper-plane-top"],[1,"message-wrapper"],[1,"message-bubble"],[1,"sender-name"],[1,"message-content"],[1,"citations"],[1,"message-timestamp"],[1,"fa-solid","fa-robot"],[1,"fa-solid","fa-circle-info"],[1,"citations-label"],[1,"fa-solid","fa-link"],["target","_blank","rel","noopener noreferrer",1,"citation-link",3,"href"],[1,"citation-title"],[1,"fa-solid","fa-external-link-alt"],[1,"welcome-icon"],[1,"fa-regular","fa-message"],[1,"message-bubble","typing-indicator"],[1,"typing-dots"],[1,"dot"],["tabindex","0","mat-raised-button","","aria-label","Restore chat window",1,"custom","pill","primary",3,"click","keydown.enter","keydown.space"],[1,"left-icon"]],template:function(n,o){n&1&&(s(0,"div",1),m(1,Ht,2,0,"button",2),m(2,ie,38,15,"div",3),m(3,ae,6,1,"button",4),a()),n&2&&(w("open",o.isOpen)("minimized",o.isMinimized),r(),p(o.isOpen?-1:1),r(),p(o.isOpen&&!o.isMinimized?2:-1),r(),p(o.isMinimized?3:-1))},dependencies:[mt,lt,dt,gt,ct,at,st,rt,ft,_t,pt,ut,wt,Mt,Ct,Pt,yt,bt,nt,et],styles:['.chat-widget-container[_ngcontent-%COMP%]{position:fixed;bottom:1rem;right:calc(.5rem + var(--mc-mat-fab-size) + .5rem);z-index:1030;font-family:var(--mc-font-family, "Roboto", sans-serif);transition-duration:.4s;transition-timing-function:cubic-bezier(.25,.8,.25,1);transition-property:right}.chat-widget-container[_ngcontent-%COMP%] .chat-window[_ngcontent-%COMP%]{width:384px;height:600px;max-height:calc(100vh - 100px);background:#fff;border-radius:12px;box-shadow:0 8px 24px #0003;display:flex;flex-direction:column;overflow:hidden;animation:_ngcontent-%COMP%_slideUp .3s ease-out}.chat-widget-container[_ngcontent-%COMP%] .chat-header[_ngcontent-%COMP%]{padding:12px 16px;color:#fff;box-shadow:0 2px 4px #0000001a}.chat-widget-container[_ngcontent-%COMP%] .chat-header[_ngcontent-%COMP%] .header-actions[_ngcontent-%COMP%] button[mat-icon-button].white[_ngcontent-%COMP%]{--mat-icon-button-icon-color: var(--mc-white);--mat-icon-button-disabled-icon-color: var(--mc-white)}.chat-widget-container[_ngcontent-%COMP%] .chat-header[_ngcontent-%COMP%] .header-actions[_ngcontent-%COMP%] button[mat-icon-button].white[_ngcontent-%COMP%]:hover{--mat-icon-button-icon-color: var(--mc-white)}.chat-widget-container[_ngcontent-%COMP%] .chat-header[_ngcontent-%COMP%] .header-actions[_ngcontent-%COMP%] button[mat-icon-button].white[_ngcontent-%COMP%]:active, .chat-widget-container[_ngcontent-%COMP%] .chat-header[_ngcontent-%COMP%] .header-actions[_ngcontent-%COMP%] button[mat-icon-button].white.is-active[_ngcontent-%COMP%]{--mat-icon-button-icon-color: var(--mc-white);background:radial-gradient(50% 50% at 50% 50%,var(--mc-white) 0%,var(--mc-white) 100%)}.chat-widget-container[_ngcontent-%COMP%] .chat-header[_ngcontent-%COMP%] .header-actions[_ngcontent-%COMP%] button[mat-icon-button].white[_ngcontent-%COMP%]:focus{--mat-icon-button-icon-color: var(--mc-white)}.chat-widget-container[_ngcontent-%COMP%] .chat-header[_ngcontent-%COMP%] .header-actions[_ngcontent-%COMP%] .connection-status[_ngcontent-%COMP%]{font-size:16px;width:16px;height:16px;margin-right:4px;color:#fff;display:flex;align-items:center;justify-content:center}.chat-widget-container[_ngcontent-%COMP%] .chat-header[_ngcontent-%COMP%] .header-actions[_ngcontent-%COMP%] .connection-status.spinning[_ngcontent-%COMP%]{animation:_ngcontent-%COMP%_spin 1s linear infinite}.chat-widget-container[_ngcontent-%COMP%] .messages-container[_ngcontent-%COMP%]{flex:1;overflow-y:auto;padding:16px;background:#f5f5f5;scroll-behavior:smooth}.chat-widget-container[_ngcontent-%COMP%] .messages-container[_ngcontent-%COMP%]::-webkit-scrollbar{width:6px}.chat-widget-container[_ngcontent-%COMP%] .messages-container[_ngcontent-%COMP%]::-webkit-scrollbar-track{background:transparent}.chat-widget-container[_ngcontent-%COMP%] .messages-container[_ngcontent-%COMP%]::-webkit-scrollbar-thumb{background:#0003;border-radius:3px}.chat-widget-container[_ngcontent-%COMP%] .messages-container[_ngcontent-%COMP%]::-webkit-scrollbar-thumb:hover{background:#0000004d}.chat-widget-container[_ngcontent-%COMP%] .welcome-message[_ngcontent-%COMP%]{text-align:center;padding:40px 20px;color:#666}.chat-widget-container[_ngcontent-%COMP%] .welcome-message[_ngcontent-%COMP%] .welcome-icon[_ngcontent-%COMP%]{font-size:50px;color:var(--mc-primary-500, #1976d2)}.chat-widget-container[_ngcontent-%COMP%] .welcome-message[_ngcontent-%COMP%] h3[_ngcontent-%COMP%]{color:#333}.chat-widget-container[_ngcontent-%COMP%] .welcome-message[_ngcontent-%COMP%] .hint-text[_ngcontent-%COMP%]{font-size:12px;color:#999;font-style:italic}.chat-widget-container[_ngcontent-%COMP%] .message-wrapper[_ngcontent-%COMP%]{margin-bottom:16px;display:flex}.chat-widget-container[_ngcontent-%COMP%] .message-wrapper.user-message[_ngcontent-%COMP%]{justify-content:flex-end}.chat-widget-container[_ngcontent-%COMP%] .message-wrapper.user-message[_ngcontent-%COMP%] .message-bubble[_ngcontent-%COMP%]{background:var(--mc-primary-500, #1976d2);color:#fff;border-radius:18px 18px 4px}.chat-widget-container[_ngcontent-%COMP%] .message-wrapper.assistant-message[_ngcontent-%COMP%], .chat-widget-container[_ngcontent-%COMP%] .message-wrapper.human-message[_ngcontent-%COMP%]{justify-content:flex-start}.chat-widget-container[_ngcontent-%COMP%] .message-wrapper.assistant-message[_ngcontent-%COMP%] .message-bubble[_ngcontent-%COMP%], .chat-widget-container[_ngcontent-%COMP%] .message-wrapper.human-message[_ngcontent-%COMP%] .message-bubble[_ngcontent-%COMP%]{background:#fff;color:#333;border-radius:18px 18px 18px 4px;box-shadow:0 1px 2px #0000001a}.chat-widget-container[_ngcontent-%COMP%] .message-wrapper.system-message[_ngcontent-%COMP%]{justify-content:center}.chat-widget-container[_ngcontent-%COMP%] .message-wrapper.system-message[_ngcontent-%COMP%] .message-bubble[_ngcontent-%COMP%]{background:#fff3cd;color:#856404;border-radius:12px;border:1px solid #ffeaa7;text-align:center;font-size:13px}.chat-widget-container[_ngcontent-%COMP%] .message-wrapper.system-message[_ngcontent-%COMP%] .message-bubble.error-message[_ngcontent-%COMP%]{background:#ffebee;color:#c62828;border-color:#ef9a9a}.chat-widget-container[_ngcontent-%COMP%] .message-bubble[_ngcontent-%COMP%]{max-width:75%;padding:12px 16px;position:relative}.chat-widget-container[_ngcontent-%COMP%] .message-bubble[_ngcontent-%COMP%] .sender-name[_ng
3content-%COMP%]{display:flex;align-items:center;gap:4px;font-size:12px;font-weight:500;margin-bottom:4px;opacity:.8}.chat-widget-container[_ngcontent-%COMP%] .message-bubble[_ngcontent-%COMP%] .sender-name[_ngcontent-%COMP%] .sender-icon[_ngcontent-%COMP%]{font-size:16px;width:16px;height:16px}.chat-widget-container[_ngcontent-%COMP%] .message-bubble[_ngcontent-%COMP%] .message-content[_ngcontent-%COMP%]{font-size:14px;line-height:1.5;word-wrap:break-word;white-space:pre-wrap}.chat-widget-container[_ngcontent-%COMP%] .message-bubble[_ngcontent-%COMP%] .message-timestamp[_ngcontent-%COMP%]{font-size:11px;opacity:.6;margin-top:4px}.chat-widget-container[_ngcontent-%COMP%] .citations[_ngcontent-%COMP%]{margin-top:12px;padding-top:12px;border-top:1px solid rgba(0,0,0,.1)}.chat-widget-container[_ngcontent-%COMP%] .citations[_ngcontent-%COMP%] .citations-label[_ngcontent-%COMP%]{font-size:12px;font-weight:500;margin-bottom:8px}.chat-widget-container[_ngcontent-%COMP%] .citations[_ngcontent-%COMP%] .citation-link[_ngcontent-%COMP%]{display:flex;align-items:center;gap:8px;margin:6px 0;padding:8px 12px;min-height:40px;font-size:13px;font-weight:500;text-decoration:none;color:var(--mc-primary-500, #1976d2);background-color:#1976d20a;border:1px solid rgba(25,118,210,.2);border-radius:6px;transition:all .2s ease;cursor:pointer}.chat-widget-container[_ngcontent-%COMP%] .citations[_ngcontent-%COMP%] .citation-link[_ngcontent-%COMP%]:hover{background-color:#1976d21f;border-color:#1976d266;transform:translate(2px)}.chat-widget-container[_ngcontent-%COMP%] .citations[_ngcontent-%COMP%] .citation-link[_ngcontent-%COMP%]:active{transform:translate(0)}.chat-widget-container[_ngcontent-%COMP%] .citations[_ngcontent-%COMP%] .citation-link[_ngcontent-%COMP%] .citation-title[_ngcontent-%COMP%]{flex:1;line-height:1.4}.chat-widget-container[_ngcontent-%COMP%] .escalation-suggestion[_ngcontent-%COMP%]{margin-top:12px;padding-top:12px;border-top:1px solid rgba(0,0,0,.1)}.chat-widget-container[_ngcontent-%COMP%] .typing-indicator[_ngcontent-%COMP%]{padding:8px 16px}.chat-widget-container[_ngcontent-%COMP%] .typing-indicator[_ngcontent-%COMP%] .typing-dots[_ngcontent-%COMP%]{display:flex;align-items:center;gap:4px;padding:4px 0}.chat-widget-container[_ngcontent-%COMP%] .typing-indicator[_ngcontent-%COMP%] .typing-dots[_ngcontent-%COMP%] .dot[_ngcontent-%COMP%]{width:8px;height:8px;border-radius:50%;background-color:#999;animation:_ngcontent-%COMP%_typing 1.4s infinite}.chat-widget-container[_ngcontent-%COMP%] .typing-indicator[_ngcontent-%COMP%] .typing-dots[_ngcontent-%COMP%] .dot[_ngcontent-%COMP%]:nth-child(1){animation-delay:0s}.chat-widget-container[_ngcontent-%COMP%] .typing-indicator[_ngcontent-%COMP%] .typing-dots[_ngcontent-%COMP%] .dot[_ngcontent-%COMP%]:nth-child(2){animation-delay:.2s}.chat-widget-container[_ngcontent-%COMP%] .typing-indicator[_ngcontent-%COMP%] .typing-dots[_ngcontent-%COMP%] .dot[_ngcontent-%COMP%]:nth-child(3){animation-delay:.4s}@keyframes _ngcontent-%COMP%_typing{0%,60%,to{opacity:.3;transform:scale(.8)}30%{opacity:1;transform:scale(1)}}.chat-widget-container[_ngcontent-%COMP%] .input-area[_ngcontent-%COMP%]{padding:16px;background:#fff;border-top:1px solid #e0e0e0}.chat-widget-container[_ngcontent-%COMP%] .input-area[_ngcontent-%COMP%] .escalation-hint[_ngcontent-%COMP%]{display:flex;align-items:center;gap:8px;padding:8px 12px;background:#e3f2fd;border-radius:8px;margin-bottom:12px;font-size:12px;color:#1976d2}.chat-widget-container[_ngcontent-%COMP%] .input-area[_ngcontent-%COMP%] .input-container[_ngcontent-%COMP%]{display:flex;gap:8px;align-items:flex-end}.chat-widget-container[_ngcontent-%COMP%] .input-area[_ngcontent-%COMP%] .input-container[_ngcontent-%COMP%] .message-input[_ngcontent-%COMP%]{flex:1;margin-bottom:0}.chat-widget-container[_ngcontent-%COMP%] .input-area[_ngcontent-%COMP%] .input-container[_ngcontent-%COMP%] .message-input[_ngcontent-%COMP%] .mat-mdc-form-field-subscript-wrapper{display:none}.chat-widget-container[_ngcontent-%COMP%] .input-area[_ngcontent-%COMP%] .quick-actions[_ngcontent-%COMP%]{margin-top:12px;display:flex;justify-content:center}.chat-widget-container[_ngcontent-%COMP%] .input-area[_ngcontent-%COMP%] .quick-actions[_ngcontent-%COMP%] .escalate-button[_ngcontent-%COMP%]{font-size:13px!important;height:36px!important;padding:0 16px!important;color:var(--mc-primary-500, #1976d2)!important;border-color:var(--mc-primary-500, #1976d2)!important;font-weight:500!important}.chat-widget-container[_ngcontent-%COMP%] .input-area[_ngcontent-%COMP%] .quick-actions[_ngcontent-%COMP%] .escalate-button[_ngcontent-%COMP%]:hover:not(:disabled){background-color:#1976d214!important}@media (max-width: 768px){.chat-widget-container.open[_ngcontent-%COMP%]{inset:0}.chat-widget-container[_ngcontent-%COMP%]:not(.open){bottom:20px;right:20px;left:auto}.chat-widget-container[_ngcontent-%COMP%] .chat-window[_ngcontent-%COMP%]{width:100%;height:100%;max-height:100%;border-radius:0;overscroll-behavior:contain;touch-action:pan-y}.chat-widget-container[_ngcontent-%COMP%] .messages-container[_ngcontent-%COMP%]{overscroll-behavior:contain;touch-action:pan-y;-webkit-overflow-scrolling:touch}}@keyframes _ngcontent-%COMP%_slideUp{0%{opacity:0;transform:translateY(20px)}to{opacity:1;transform:translateY(0)}}@keyframes _ngcontent-%COMP%_spin{0%{transform:rotate(0)}to{transform:rotate(360deg)}}']})}return i})();export{$e as ChatWidgetComponent}; 4
5//# debugId=56306b27-900d-5b39-a438-5e00710508cd
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.