!function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{},n=(new e.Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="3104311c-ca76-3430-90af-049dc5c96020")}catch(e){}}(); define(["require","exports","./c_flux_action_type","./c_pap-events_enums_flexible_sharing_entry_point_variant-utils","./c_core_notify","./e_file_viewer_static_scl_page_folder","./c_core_i18n","react-dom","react","./e_core_exception","./c_src_sink_index"],(function(t,e,a,i,s,n,r,o,h,c,d){"use strict";function p(t){return t&&t.__esModule?t:{default:t}}function m(t){if(t&&t.__esModule)return t;var e=Object.create(null);return t&&Object.keys(t).forEach((function(a){if("default"!==a){var i=Object.getOwnPropertyDescriptor(t,a);Object.defineProperty(e,a,i.get?i:{enumerable:!0,get:function(){return t[a]}})}})),e.default=t,Object.freeze(e)}var g,l,_,u,C=m(o),S=p(h);e.ChatProviderType=void 0,(g=e.ChatProviderType||(e.ChatProviderType={}))[g.SNAPENGAGE=0]="SNAPENGAGE",g[g.DIALOGUE_CHAT=1]="DIALOGUE_CHAT",g[g.SOLVVY=2]="SOLVVY",a.proto3.util.setEnumType(e.ChatProviderType,"chat.ChatProviderType",[{no:0,name:"SNAPENGAGE"},{no:1,name:"DIALOGUE_CHAT"},{no:2,name:"SOLVVY"}]),e.ProactiveMessageType=void 0,function(t){t[t.DEFAULT=0]="DEFAULT",t[t.MINIMIZED_PROACTIVE=1]="MINIMIZED_PROACTIVE"}(e.ProactiveMessageType||(e.ProactiveMessageType={})),a.proto3.util.setEnumType(e.ProactiveMessageType,"chat.ProactiveMessageType",[{no:0,name:"DEFAULT"},{no:1,name:"MINIMIZED_PROACTIVE"}]),e.ChatInitialState=void 0,(l=e.ChatInitialState||(e.ChatInitialState={}))[l.HIDDEN=0]="HIDDEN",l[l.SHOW_PROVIDER_REACTIVE_BUTTON=1]="SHOW_PROVIDER_REACTIVE_BUTTON",a.proto3.util.setEnumType(e.ChatInitialState,"chat.ChatInitialState",[{no:0,name:"HIDDEN"},{no:1,name:"SHOW_PROVIDER_REACTIVE_BUTTON"}]),function(t){t[t.UNKNOWN=0]="UNKNOWN",t[t.LEX=1]="LEX",t[t.RASA=2]="RASA"}(_||(_={})),a.proto3.util.setEnumType(_,"chat.DialogueBotProvider",[{no:0,name:"UNKNOWN"},{no:1,name:"LEX"},{no:2,name:"RASA"}]),function(t){t[t.CX_SUPPORT=0]="CX_SUPPORT",t[t.BUSINESS=1]="BUSINESS",t[t.CX_SPECIALIZED=2]="CX_SPECIALIZED",t[t.SCALED_ONBOARDING=3]="SCALED_ONBOARDING"}(u||(u={})),a.proto3.util.setEnumType(u,"chat.DialogueBotType",[{no:0,name:"CX_SUPPORT"},{no:1,name:"BUSINESS"},{no:2,name:"CX_SPECIALIZED"},{no:3,name:"SCALED_ONBOARDING"}]);class T extends a.Message{constructor(t){super(),this.cookieDomain="",this.cookieCampaignName="",this.legacyCookieCampaignName="",a.proto3.util.initPartial(t,this)}static fromBinary(t,e){return(new T).fromBinary(t,e)}static fromJson(t,e){return(new T).fromJson(t,e)}static fromJsonString(t,e){return(new T).fromJsonString(t,e)}static equals(t,e){return a.proto3.util.equals(T,t,e)}}T.runtime=a.proto3,T.typeName="chat.ChatMetadata",T.fields=a.proto3.util.newFieldList((()=>[{no:1,name:"cookie_domain",kind:"scalar",T:9},{no:2,name:"cookie_campaign_name",kind:"scalar",T:9},{no:3,name:"legacy_cookie_campaign_name",kind:"scalar",T:9}]));class E extends a.Message{constructor(t){super(),this.snapengageIframeOrigin="",a.proto3.util.initPartial(t,this)}static fromBinary(t,e){return(new E).fromBinary(t,e)}static fromJson(t,e){return(new E).fromJson(t,e)}static fromJsonString(t,e){return(new E).fromJsonString(t,e)}static equals(t,e){return a.proto3.util.equals(E,t,e)}}E.runtime=a.proto3,E.typeName="chat.SnapengageChatMetadata",E.fields=a.proto3.util.newFieldList((()=>[{no:4,name:"snapengage_iframe_origin",kind:"scalar",T:9}]));class v extends a.Message{constructor(t){super(),this.solvvyIframeOrigin="",a.proto3.util.initPartial(t,this)}static fromBinary(t,e){return(new v).fromBinary(t,e)}static fromJson(t,e){return(new v).fromJson(t,e)}static fromJsonString(t,e){return(new v).fromJsonString(t,e)}static equals(t,e){return a.proto3.util.equals(v,t,e)}}v.runtime=a.proto3,v.typeName="chat.SolvvyChatMetadata",v.fields=a.proto3.util.newFieldList((()=>[{no:1,name:"solvvy_iframe_origin",kind:"scalar",T:9}]));class A extends a.Message{constructor(t){super(),this.chatHmac="",this.email="",this.firstName="",this.lastName="",this.pageLoadTs="",this.pricings=[],this.sessionId="",this.userId="",this.serviceTier="",this.experiments={},this.locale="",this.countryCode="",this.authToken="",a.proto3.util.initPartial(t,this)}static fromBinary(t,e){return(new A).fromBinary(t,e)}static fromJson(t,e){return(new A).fromJson(t,e)}static fromJsonString(t,e){return(new A).fromJsonString(t,e)}static equals(t,e){return a.proto3.util.equals(A,t,e)}}A.runtime=a.proto3,A.typeName="chat.UserProperties",A.fields=a.proto3.util.newFieldList((()=>[{no:1,name:"chat_hmac",kind:"scalar",T:9},{no:2,name:"email",kind:"scalar",T:9},{no:3,name:"first_name",kind:"scalar",T:9},{no:4,name:"last_name",kind:"scalar",T:9},{no:5,name:"page_load_ts",kind:"scalar",T:9},{no:6,name:"pricings",kind:"scalar",T:9,repeated:!0},{no:7,name:"session_id",kind:"scalar",T:9},{no:8,name:"user_id",kind:"scalar",T:9},{no:9,name:"service_tier",kind:"scalar",T:9},{no:10,name:"experiments",kind:"map",K:9,V:{kind:"scalar",T:9}},{no:11,name:"locale",kind:"scalar",T:9},{no:12,name:"country_code",kind:"scalar",T:9},{no:13,name:"auth_token",kind:"scalar",T:9}]));class O extends a.Message{constructor(t){super(),this.widgetId="",a.proto3.util.initPartial(t,this)}static fromBinary(t,e){return(new O).fromBinary(t,e)}static fromJson(t,e){return(new O).fromJson(t,e)}static fromJsonString(t,e){return(new O).fromJsonString(t,e)}static equals(t,e){return a.proto3.util.equals(O,t,e)}}O.runtime=a.proto3,O.typeName="chat.SnapengageChatSystemSettings",O.fields=a.proto3.util.newFieldList((()=>[{no:1,name:"widget_id",kind:"scalar",T:9}]));class I extends a.Message{constructor(t){super(),this.name="",this.active=!1,a.proto3.util.initPartial(t,this)}static fromBinary(t,e){return(new I).fromBinary(t,e)}static fromJson(t,e){return(new I).fromJson(t,e)}static fromJsonString(t,e){return(new I).fromJsonString(t,e)}static equals(t,e){return a.proto3.util.equals(I,t,e)}}I.runtime=a.proto3,I.typeName="chat.DialogueExperiment",I.fields=a.proto3.util.newFieldList((()=>[{no:1,name:"name",kind:"scalar",T:9},{no:2,name:"active",kind:"scalar",T:8}]));class f extends a.Message{constructor(t){super(),this.botProvider=_.UNKNOWN,this.environment="",this.settingsHmac="",this.experiments=[],this.botType=u.CX_SUPPORT,this.proactiveIntent="",this.portaled=!1,a.proto3.util.initPartial(t,this)}static fromBinary(t,e){return(new f).fromBinary(t,e)}static fromJson(t,e){return(new f).fromJson(t,e)}static fromJsonString(t,e){return(new f).fromJsonString(t,e)}static equals(t,e){return a.proto3.util.equals(f,t,e)}}f.runtime=a.proto3,f.typeName="chat.DialogueChatSystemSettings",f.fields=a.proto3.util.newFieldList((()=>[{no:2,name:"bot_provider",kind:"enum",T:a.proto3.getEnumType(_)},{no:3,name:"environment",kind:"scalar",T:9},{no:4,name:"settings_hmac",kind:"scalar",T:9},{no:5,name:"experiments",kind:"message",T:I,repeated:!0},{no:6,name:"bot_type",kind:"enum",T:a.proto3.getEnumType(u)},{no:7,name:"proactive_intent",kind:"scalar",T:9},{no:8,name:"portaled",kind:"scalar",T:8}]));class R extends a.Message{constructor(t){super(),this.proactiveType=e.ProactiveMessageType.DEFAULT,this.whenToShowControlledByProvider=!1,this.secondsUntilShown=a.protoInt64.zero,this.coolOffPeriodMinutes=a.protoInt64.zero,a.proto3.util.initPartial(t,this)}static fromBinary(t,e){return(new R).fromBinary(t,e)}static fromJson(t,e){return(new R).fromJson(t,e)}static fromJsonString(t,e){return(new R).fromJsonString(t,e)}static equals(t,e){return a.proto3.util.equals(R,t,e)}}R.runtime=a.proto3,R.typeName="chat.ProactiveSettings",R.fields=a.proto3.util.newFieldList((()=>[{no:1,name:"proactive_type",kind:"enum",T:a.proto3.getEnumType(e.ProactiveMessageType)},{no:2,name:"when_to_show_controlled_by_provider",kind:"scalar",T:8},{no:3,name:"seconds_until_shown",kind:"scalar",T:4},{no:4,name:"cool_off_period_minutes",kind:"scalar",T:4}]));class N extends a.Message{constructor(t){super(),this.widgetId="",a.proto3.util.initPartial(t,this)}static fromBinary(t,e){return(new N).fromBinary(t,e)}static fromJson(t,e){return(new N).fromJson(t,e)}static fromJsonString(t,e){return(new N).fromJsonString(t,e)}static equals(t,e){return a.proto3.util.equals(N,t,e)}}N.runtime=a.proto3,N.typeName="chat.ChatHmacInput",N.fields=a.proto3.util.newFieldList((()=>[{no:1,name:"widget_id",kind:"scalar",T:9}]));class P extends a.Message{constructor(t){super(),this.campaignId=a.protoInt64.zero,this.versionId=a.protoInt64.zero,this.campaignName="",this.versionName="",this.systemSettings={case:void 0},this.mustHaveAvailableAgents=!1,this.greetingMessage="",this.chatInitialState=e.ChatInitialState.HIDDEN,this.persistenceCookie="",this.deprecatedExperimentNameToLog="",this.deprecatedExperimentVariantToLog="",this.isControl=!1,a.proto3.util.initPartial(t,this)}static fromBinary(t,e){return(new P).fromBinary(t,e)}static fromJson(t,e){return(new P).fromJson(t,e)}static fromJsonString(t,e){return(new P).fromJsonString(t,e)}static equals(t,e){return a.proto3.util.equals(P,t,e)}}P.runtime=a.proto3,P.typeName="chat.CampaignResult",P.fields=a.proto3.util.newFieldList((()=>[{no:1,name:"campaign_id",kind:"scalar",T:4},{no:2,name:"version_id",kind:"scalar",T:4},{no:3,name:"campaign_name",kind:"scalar",T:9},{no:4,name:"version_name",kind:"scalar",T:9},{no:5,name:"snapengage_chat_system_settings",kind:"message",T:O,oneof:"system_settings"},{no:14,name:"dialogue_chat_system_settings",kind:"message",T:f,oneof:"system_settings"},{no:6,name:"must_have_available_agents",kind:"scalar",T:8},{no:7,name:"proactive_settings",kind:"message",T:R},{no:8,name:"greeting_message",kind:"scalar",T:9},{no:9,name:"chat_initial_state",kind:"enum",T:a.proto3.getEnumType(e.ChatInitialState)},{no:10,name:"persistence_cookie",kind:"scalar",T:9},{no:11,name:"deprecated_experiment_name_to_log",kind:"scalar",T:9},{no:12,name:"deprecated_experiment_variant_to_log",kind:"scalar",T:9},{no:13,name:"is_control",kind:"scalar",T:8},{no:15,name:"chat_hmac_input",kind:"message",T:N}]));class y extends a.Message{constructor(t){super(),a.proto3.util.initPartial(t,this)}static fromBinary(t,e){return(new y).fromBinary(t,e)}static fromJson(t,e){return(new y).fromJson(t,e)}static fromJsonString(t,e){return(new y).fromJsonString(t,e)}static equals(t,e){return a.proto3.util.equals(y,t,e)}}y.runtime=a.proto3,y.typeName="chat.ChatProviderMetadata",y.fields=a.proto3.util.newFieldList((()=>[{no:1,name:"snapengage",kind:"message",T:E}]));class L extends a.Message{constructor(t){super(),this.resume=!1,this.chatProviderType=e.ChatProviderType.SNAPENGAGE,this.chatProviderMetadata={case:void 0},this.loggingCorrelationId="",this.featureGates={},a.proto3.util.initPartial(t,this)}static fromBinary(t,e){return(new L).fromBinary(t,e)}static fromJson(t,e){return(new L).fromJson(t,e)}static fromJsonString(t,e){return(new L).fromJsonString(t,e)}static equals(t,e){return a.proto3.util.equals(L,t,e)}}L.runtime=a.proto3,L.typeName="chat.ChatInitializerProperties",L.fields=a.proto3.util.newFieldList((()=>[{no:1,name:"chat_metadata",kind:"message",T:T},{no:2,name:"user_properties",kind:"message",T:A},{no:3,name:"campaign_result",kind:"message",T:P},{no:4,name:"resume",kind:"scalar",T:8},{no:5,name:"chat_provider_type",kind:"enum",T:a.proto3.getEnumType(e.ChatProviderType)},{no:6,name:"snapengage_chat_metadata",kind:"message",T:E,oneof:"chat_provider_metadata"},{no:10,name:"solvvy_chat_metadata",kind:"message",T:v,oneof:"chat_provider_metadata"},{no:7,name:"logging_correlation_id",kind:"scalar",T:9},{no:8,name:"feature_gates",kind:"map",K:9,V:{kind:"scalar",T:8}},{no:9,name:"provider_metadata",kind:"message",T:y}]));const D=t=>void 0!==t.campaignId,w=t=>"string"==typeof t,U=(t,e)=>!!t&&(D(t)&&D(e)?t.campaignId===e.campaignId:!(!w(t)||!w(e))&&t===e),M=t=>D(t)?t.systemSettings&&"snapengageChatSystemSettings"===t.systemSettings.case?t.systemSettings.value.widgetId:null:t;var V,H;!function(t){t.UNKNOWN="unknown",t.OFFLINE="offline",t.ONLINE="online"}(V||(V={})),function(t){t.START_TRANSFER="startTransfer",t.END_TRANSFER="endTransfer",t.ERROR_ON_TRANSFER="errorOnTransfer"}(H||(H={}));class b{constructor(t){}}class B{constructor(t,e){this.setupChatEnvironment=t=>{},this.startReactiveChat=()=>{},this.startSupportChat=t=>{},this.setCookieBannerInfo=t=>{},this.regsiterVisibilityChangeCallback=t=>{}}}const G={NAMER:["US","CA"],APAC:["AU","BD","KH","C2","FJ","GU","HK","IN","ID","JP","MY","MV","NP","NZ","PK","PH","SG","KR","LK","TW","TH","VN"],EMEA:["AL","DZ","AO","AT","AZ","BH","BY","BE","BA","BW","BG","CM","HR","CY","CZ","DK","EG","EE","ET","FI","FR","GE","DE","GH","GI","GR","HU","IS","IQ","IE","IL","IT","CI","JO","KE","KW","LV","LB","LT","LU","MK","MG","MT","MQ","MU","MD","MC","MA","MZ","NA","NL","NG","NO","OM","PS","PL","PT","QA","RO","RU","RW","SA","SN","RS","SK","SI","ZA","ES","SE","CH","TZ","TN","TR","UG","UA","AE","GB","YE","ZM","ZW"],LATAM:["AG","AN","AR","AW","BB","BO","BR","BS","BZ","CL","CO","CR","CU","DM","DO","EC","GT","GY","HN","HT","JM","KN","LC","MX","NI","PA","PE","PR","PY","SR","SV","TT","UY","VC","VE"]},k={en:"",en_GB:"",da_DK:"dutch",de:"german",es:"spanish, spanish-la",es_ES:"spanish, spanish-es",fr:"french",id:"",it:"italian",ja:"japanese",ko:"korean",ms:"",nb_NO:"norwegian",nl_NL:"dutch",pl:"",pt_BR:"portuguese",ru:"russian",sv_SE:"swedish",th_TH:"thai",zh_CN:"chinese, chinese-sim",zh_TW:"chinese, chinese-trad"},W=t=>{if(void 0!==t)return G.NAMER.indexOf(t)>=0?"namer":G.APAC.indexOf(t)>=0?"apac":G.EMEA.indexOf(t)>=0?"emea":G.LATAM.indexOf(t)>=0?"latam":void 0};class F{constructor(t){}}var x=e.ProactiveMessageType;class z extends F{constructor(t){super(t),this.isLoaded=()=>this._isLoaded,this.requestAgentStatusUpdate=()=>{this.checkChatStatus()},this.showReactiveButton=()=>{this.showSnapEngageIframe(),this.minimizeSnapEngageIframe(),this.onProviderReactiveButtonShownListener(this.chatCampaign)},this.startChat=()=>{this.showSnapEngageIframe(),this.sendMessage("startChatV2")},this.startProactiveChat=()=>{this.showSnapEngageIframe(),this.sendMessage("startProactiveChat")},this.handleProviderDrivenOpen=()=>{this.showSnapEngageIframe()},this.switchCampaign=t=>{this.chatCampaign=t,this.chatId=M(this.chatCampaign),this.sendMessage("switchCampaign")},this.updateHmac=()=>{this.sendMessage("updateHmac")},this.addBottomMargin=()=>{this.iframe&&this.iframe.style.setProperty("transform","translateY(calc(-1 * var(--privacy-consent-banner-height, 0px)))")},this.removeBottomMargin=()=>{this.iframe&&this.iframe.style.removeProperty("transform")},this.initialize=()=>{window.addEventListener("message",this.receiveMessage,!1),s.require_css("/static/metaserver/static/css/business/components/snap_engage-vfldJUS6n.css",(()=>{this.createIframe()}))},this.createIframe=()=>{const t=n.get_uri(),e=i.URI.parse(this.metadata.snapengageIframeOrigin);this.iframe=document.createElement("iframe"),t.setScheme(e.getScheme()),t.setAuthority(e.getAuthority()),this.iframe.src=t.toString(),this.iframe.setAttribute("sandbox","allow-scripts allow-same-origin allow-popups allow-forms"),this.iframe.setAttribute("class","snapengage-iframe"),this.iframe.setAttribute("id",this.iframeId),this.iframe.setAttribute("allowTransparency","true"),this.iframe.setAttribute("title",r.intl.formatMessage({id:"/nsbvt",defaultMessage:"Live chat box"})),this.iframe.addEventListener("load",this.handleIframeLoad);const a=document.querySelector("main");null!==a?a.insertBefore(this.iframe,a.firstChild):(this.iframe.setAttribute("tabindex","1"),document.body.insertBefore(this.iframe,document.body.childNodes[0])),setInterval(this.checkChatStatus,13e4)},this.handleIframeLoad=()=>{this.iFrameLeftStyle=this.iframe&&this.iframe.style.left,this.sendMessage("createSnapEngageScriptV2")},this.showSnapEngageIframe=(t=!1)=>{this.iframe&&(this.iframe.style.display="inline",this.iframe.style.left=this.iFrameLeftStyle,this.isVisible=!0)},this.onCloseChat=t=>{let e,a;this.iframe&&(this.iframe.style.display="none"),this.isVisible=!1,t&&(a=t.type,e="online"===t.agentStatus?V.ONLINE:V.OFFLINE),this.onChatClosedListener(this.chatCampaign,{agentStatus:e,chatType:a})},this.onMinimized=()=>{this.onChatMinimizedListener(this.chatCampaign),this.minimizeSnapEngageIframe()},this.onMaximized=t=>{this.onChatMaximizedListener(this.chatCampaign),this.maximizeSnapEngageIframe(t)},this.minimizeSnapEngageIframe=()=>{this.iframe&&this.isVisible&&(this.iframe.style.width="80px",this.iframe.style.height="80px")},this.maximizeSnapEngageIframe=t=>{if(this.iframe){const e=(t||{}).width,a=(t||{}).height;this.iframe.style.width=e?`${e}px`:"",this.iframe.style.height=a?`${a}px`:""}},this.checkChatStatus=()=>{this.sendMessage("checkChatStatusV2")},this.onOpenProactive=()=>{this.onProviderDrivenOpenProactiveListener(this.chatCampaign)},this.onAgentStatusUpdate=t=>{this.onAgentStatusUpdateListener(this.chatCampaign,t)},this.isValidSource=t=>t.origin===this.metadata.snapengageIframeOrigin,this.onOpen=()=>{this.onChatShownListener(this.chatCampaign)},this.onChatMessageReceived=()=>{},this.onStartChat=()=>{this.onChatStartedListener(this.chatCampaign)},this.onSwitchCampaign=()=>{this.onSwitchCampaignListener(this.chatCampaign)},this.onSnapEngageInitialized=()=>{this._isLoaded=!0,this.onChatLoadListener(this.chatCampaign,!0)},this.buildChatData=()=>{const t=((t,e)=>{const a=[],i=k[t],s=W(e);return void 0!==i&&a.push(i),void 0!==s&&a.push(s),a.join(", ")})(this.userProperties.locale,this.userProperties.countryCode),e=D(this.chatCampaign)&&!this.chatCampaign.isControl&&void 0!==this.chatCampaign.proactiveSettings&&null!==this.chatCampaign.proactiveSettings&&this.chatCampaign.proactiveSettings.whenToShowControlledByProvider;let a,i=!1;return D(this.chatCampaign)&&(a=this.chatCampaign.greetingMessage,this.chatCampaign.proactiveSettings&&(i=this.chatCampaign.proactiveSettings.proactiveType===x.MINIMIZED_PROACTIVE)),{FirstName:this.userProperties.firstName,LastName:this.userProperties.lastName,Email:this.userProperties.email,locale:this.userProperties.locale,SessionID:this.userProperties.sessionId,Country:this.userProperties.countryCode,pricing:this.userProperties.pricings.join(),user_id:this.userProperties.userId,pageLoadTs:this.userProperties.pageLoadTs,chatHmac:this.userProperties.chatHmac,authToken:this.userProperties.authToken,ncct:"",serviceTier:this.userProperties.serviceTier,tags:t,phoneSupportForPlusUsers:this.userProperties.experiments.phoneSupportForPlusUsers,supportExperimentShowOnboardingNumber:this.userProperties.experiments.supportExperimentShowOnboardingNumber,supportExperimentHideEmailOption:this.userProperties.experiments.supportExperimentHideEmailOption,supportExperimentBasic36HourSla:this.userProperties.experiments.supportExperimentBasic36HourSla,phoneSupportForProfessionalUsers:this.userProperties.experiments.phoneSupportForProfessionalUsers,supportExperimentProfessionalPhoneSupportedLanguages:this.userProperties.experiments.supportExperimentProfessionalPhoneSupportedLanguages,cxChatbotName:"",allowProactive:e,greetingMessage:a,minimizedProactive:i}},this.receiveMessage=t=>{this.isValidSource(t)&&("SnapEngageInitialized"===t.data.message_type?this.onSnapEngageInitialized():"UpdateChatStatus"===t.data.message_type?this.onAgentStatusUpdate(t.data.online):"Close"===t.data.message_type?this.onCloseChat(t.data):"Minimize"===t.data.message_type?this.onMinimized():"Maximize"===t.data.message_type?this.onMaximized(t.data.rect):"OpenProactive"===t.data.message_type?this.onOpenProactive():"StartChat"===t.data.message_type?this.onStartChat():"Open"===t.data.message_type?this.onOpen():"EndProactiveChat"===t.data.message_type?this.onCloseChat():"ChatMessageReceived"===t.data.message_type?this.onChatMessageReceived():"onSwitchCampaign"===t.data.message_type&&this.onSwitchCampaign())},this.sendMessage=t=>{const e={message_type:t,chatId:this.chatId,chatData:this.chatData};this.iframe&&this.iframe.contentWindow&&this.iframe.contentWindow.postMessage(e,this.metadata.snapengageIframeOrigin)},this._isLoaded=!1,this.chatCampaign=t.campaignResult,this.metadata=t.metadata,this.userProperties=t.userProperties,this.onAgentStatusUpdateListener=t.onAgentStatusUpdate,this.onChatLoadListener=t.onChatLoadStatusUpdate,this.onChatShownListener=t.onChatShown,this.onChatStartedListener=t.onChatStarted,this.onChatClosedListener=t.onChatClosed,this.onSwitchCampaignListener=t.onSwitchCampaign,this.onProviderDrivenOpenProactiveListener=t.onProviderDrivenOpenProactive,this.onProviderReactiveButtonShownListener=t.onProviderReactiveButtonShown,this.onChatMinimizedListener=t.onChatMinimized,this.onChatMaximizedListener=t.onChatMaximized,this.isVisible=!1,this.iframeId="snapengage-iframe",this.chatData=this.buildChatData(),this.chatId=M(this.chatCampaign),this.initialize()}}class q extends b{constructor(t){super(t),this.DEFAULT_WIDGET_ID="d5c1efed-d0ef-4fca-8c7d-faff398ad272",this.getDefaultChatIdentifier=()=>this.DEFAULT_WIDGET_ID,this.loadChatIfNecessary=t=>{U(this.currentChatCampaign,t)?this.handler.isLoaded()&&this.onChatLoadStatusUpdate(this.currentChatCampaign,!0):this.handler.switchCampaign(t)},this.onSwitchCampaign=t=>{const e=this.currentChatCampaign;this.currentChatCampaign=t,this.onChatLoadStatusUpdate(e,!1),this.onAgentStatusUpdateListener(e,V.UNKNOWN),this.onChatLoadStatusUpdate(t,!0),this.handler.requestAgentStatusUpdate()},this.requestAgentStatusUpdate=t=>{if(!U(this.currentChatCampaign,t))throw new Error("Requesting agent status for a chat campaign that is not loaded");this.handler.requestAgentStatusUpdate()},this.showProviderReactiveChatButton=()=>{this.handler.showReactiveButton()},this.handleProviderDrivenOpen=()=>{this.handler.handleProviderDrivenOpen()},this.startChat=(t,e)=>{if(!U(this.currentChatCampaign,t))throw new Error("Requesting to start chat for a chat campaign that is not loaded");e?this.handler.startProactiveChat():this.handler.startChat()},this.updateHmac=()=>{this.handler.updateHmac()},this.addBottomMargin=()=>{this.handler.addBottomMargin()},this.removeBottomMargin=()=>{this.handler.removeBottomMargin()},this.onAgentStatusUpdate=(t,e)=>{this.onAgentStatusUpdateListener(t,e?V.ONLINE:V.OFFLINE)},this.handleTransferEvent=t=>{},this.onAgentStatusUpdateListener=t.onAgentStatusUpdate,this.onChatLoadStatusUpdate=t.onChatLoadStatusUpdate,this.onChatShown=t.onChatShown,this.onChatStarted=t.onChatStarted,this.onChatClosed=t.onChatClosed,this.onProviderDrivenOpenProactive=t.onProviderDrivenOpenProactive,this.onProviderReactiveButtonShown=t.onProviderReactiveButtonShown,this.metadata=t.metadata,this.userProperties=t.userProperties,this.onChatMinimized=t.onChatMinimized,this.onChatMaximized=t.onChatMaximized,t.chatCampaign?(this.currentChatCampaign=t.chatCampaign,this.handler=this.createHandler(t.chatCampaign)):(this.currentChatCampaign=this.DEFAULT_WIDGET_ID,this.handler=this.createHandler(this.DEFAULT_WIDGET_ID))}createHandler(t){return new z({campaignResult:t,metadata:this.metadata,userProperties:this.userProperties,onAgentStatusUpdate:this.onAgentStatusUpdate,onChatLoadStatusUpdate:this.onChatLoadStatusUpdate,onChatShown:this.onChatShown,onChatStarted:this.onChatStarted,onChatClosed:this.onChatClosed,onProviderDrivenOpenProactive:this.onProviderDrivenOpenProactive,onProviderReactiveButtonShown:this.onProviderReactiveButtonShown,onSwitchCampaign:this.onSwitchCampaign,onChatMinimized:this.onChatMinimized,onChatMaximized:this.onChatMaximized})}}var J;e.DialogueActionType=void 0,(J=e.DialogueActionType||(e.DialogueActionType={})).INIT_PROVIDER="DIALOGUE/INIT_PROVIDER",J.SET_TRANSFER_PROPS="DIALOGUE/SET_TRANSFER_PROPS",J.START_TRANSFER="DIALOGUE/START_TRANSFER",J.END_CHAT="DIALOGUE/END_CHAT",J.GET_CHAT="DIALOGUE/GET_CHAT",J.TOGGLE_CHAT_WINDOW="DIALOGUE/TOGGLE_CHAT_WINDOW",J.TOGGLE_REACTIVE_BUTTON="DIALOGUE/TOGGLE_REACTIVE_BUTTON",J.TOGGLE_END_CHAT_MODAL="DIALOGUE/TOGGLE_END_CHAT_MODAL",J.TOGGLE_TRANSFER_MODAL="DIALOGUE/TOGGLE_TRANSFER_MODAL",J.SET_LOGGING_ID="DIALOGUE/SET_LOGGING_ID",J.SET_GREETING_MESSAGE="DIALOGUE/SET_GREETING_MESSAGE",J.SET_FATAL_ERROR_MESSAGE="DIALOGUE/SET_FATAL_ERROR_MESSAGE",J.DISABLE_CHAT="DIALOGUE/DISABLE_CHAT",J.ADD_MESSAGE="DIALOGUE/ADD_MESSAGE",J.UPDATE_CURRENT_MESSAGE="DIALOGUE/UPDATE_CURRENT_MESSAGE",J.UPDATE_SURVEY_RESPONSE="DIALOGUE/UPDATE_SURVEY_RESPONSE",J.CLICK_LINK="DIALOGUE/CLICK_LINK",J.RESTART_CHAT="DIALOGUE/RESTART_CHAT";const K={cx_support:u.CX_SUPPORT,cx_specialized:u.CX_SPECIALIZED,business:u.BUSINESS,scaled_onboarding:u.SCALED_ONBOARDING},Z=t=>{switch(t[".tag"]){case"lex":return _.LEX;case"rasa":return _.RASA;default:return _.UNKNOWN}},X=t=>{const e=Object.keys(K).find((e=>K[e]===t));if(!e)throw new Error("invalid bot type");return{".tag":e}},j=t=>{switch(t){case _.LEX:return{".tag":"lex"};case _.RASA:return{".tag":"rasa"};default:return{".tag":"unknown"}}},Y=S.default.lazy((async()=>{const{Dialogue:e}=await new Promise((function(e,a){t(["./c_chat_dialogue"],e,a)}));return{default:e}})),Q=()=>S.default.createElement(S.default.Fragment,null),$=t=>S.default.createElement(S.default.Suspense,{fallback:S.default.createElement(Q,null)},S.default.createElement(Y,{...t}));class tt extends b{constructor(a){var i,s;super(a),this.DEFAULT_ID="chatbot",this.isReady=!1,this.setup=async()=>{const e=new Promise((function(e,a){t(["./c_dialogue_reducers_index"],e,a)})).then((({createAppRootStore:t})=>{this.initialiseReduxStore(t),this.loadChat()})),a=new Promise((function(e,a){t(["./c_dialogue_actions_chat_actions"],e,a)})).then((function(t){return t.chat_actions_esnext}));await Promise.all([e,a]),a.then((t=>{this.chatActions=t;const e={text:this.campaign.greetingMessage,sender:"bot"};this.callWhenReady((()=>{this.action(this.chatActions.getChat(this.stoneSettings,e,Number(this.campaign.campaignId)))})),this.isReady=!0,this.onReadyCallbacks.forEach((t=>{t()}))})),this.onChatLoadStatusListener(this.campaign,!0)},this.initialiseReduxStore=t=>{this.store=t(this);const a=(t=>{const e={};return t.forEach((t=>{const a=t.name;e[a]=t.active})),e})(this.settings.experiments);this.store.dispatch({type:e.DialogueActionType.INIT_PROVIDER,settings:this.stoneSettings,userProperties:this.userProperties,experiments:a,campaignId:Number(this.campaign.campaignId)})},this.action=t=>{t(this.store.dispatch,this.store.getState)},this.transferToNewCampaign=t=>{t.chatProviderType===e.ChatProviderType.SNAPENGAGE&&this.onSwitchProviderWithNewCampaign(t,this.campaign)},this.handleTransferEvent=t=>{var e,a;if(t===H.START_TRANSFER);else if(t===H.END_TRANSFER){const{providerState:t}=this.store.getState(),i=null===(e=t.savedTransferProps)||void 0===e?void 0:e.campaignResult;let s;if(i){const{campaignName:t,versionName:e,campaignId:a}=i;s=`chatbot_transfer_${a}`,this.logAsync("transfer",{campaignName:t,versionName:e,campaignId:Number(a)})}this.action(this.chatActions.endChat({},this.stoneSettings,!1,s)),null===(a=this.getRootElement())||void 0===a||a.remove()}else t===H.ERROR_ON_TRANSFER&&this.addMessage({text:"Sorry, I wasn't able to transfer you.",sender:"bot"})},this.onReactiveButtonShown=()=>{this.onProviderReactiveButtonShownListener(this.campaign)},this.addMessage=(t,a=!1)=>{this.callWhenReady((()=>{this.store.dispatch({type:e.DialogueActionType.ADD_MESSAGE,message:t,awaitingResponse:a})}))},this.addBottomMargin=()=>{const t=this.getRootElement();t&&t.style.setProperty("transform","translateY(calc(-1 * var(--privacy-consent-banner-height, 0px)))")},this.removeBottomMargin=()=>{const t=this.getRootElement();t&&t.style.removeProperty("transform")},this.callWhenReady=t=>{this.isReady?t():this.onReadyCallbacks.push(t)},this.getRootElement=()=>document.getElementById("dialogue-chat-root"),this.getLogger=async()=>{if(this.logger)return this.logger;const{DialogueEventsLogger:e}=await new Promise((function(e,a){t(["./c_chat_dialogue_logging"],e,a)}));return this.logger=new e,this.logger},this.logAsync=async(t,e={})=>{(await this.getLogger()).logEvent(t,e)},this.settings=(null===(i=a.chatCampaign)||void 0===i?void 0:i.systemSettings).value,this.stoneSettings=(s=this.settings,{bot_provider:j(s.botProvider),bot_type:X(s.botType),environment:s.environment,settings_hmac:s.settingsHmac,proactive_intent:s.proactiveIntent,portaled:s.portaled}),this.campaign=a.chatCampaign,this.userProperties=a.userProperties,this.onReadyCallbacks=[],this.onAgentStatusUpdateListener=a.onAgentStatusUpdate,this.onChatLoadStatusListener=a.onChatLoadStatusUpdate,this.onChatShownListener=a.onChatShown,this.onChatStartedListener=a.onChatStarted,this.onChatClosedListener=a.onChatClosed,this.onChatMinimizedListener=a.onChatMinimized,this.onChatMaximizedListener=a.onChatMaximized,this.onProviderDrivenOpenProactive=a.onProviderDrivenOpenProactive,this.onProviderReactiveButtonShownListener=a.onProviderReactiveButtonShown,this.onSwitchProviderWithNewCampaign=a.onSwitchProviderWithNewCampaign,this.hasLoaded=!1,this.setup().catch((async t=>{var e;(await this.getLogger()).logError("provider_init",{userId:null===(e=a.userProperties)||void 0===e?void 0:e.userId,error:t.toString()})}))}getDefaultChatIdentifier(){return this.DEFAULT_ID}loadChatIfNecessary(t){}requestAgentStatusUpdate(t){this.onAgentStatusUpdateListener(t,V.ONLINE)}showProviderReactiveChatButton(){this.callWhenReady((()=>{this.action(this.chatActions.toggleReactiveButton(!0))}))}handleProviderDrivenOpen(){}startChat(t,e){this.callWhenReady((()=>{this.action(this.chatActions.openChat(e))}))}updateHmac(){}onChatStarted(){this.onChatStartedListener(this.campaign)}onChatClosed(){this.onChatClosedListener(this.campaign,{})}onChatMinimized(){this.onChatMinimizedListener(this.campaign)}onChatMaximized(){this.onChatMaximizedListener(this.campaign)}onChatShown(t){this.onChatShownListener(t||this.campaign)}async loadChat(){if(!this.getRootElement()){const t=document.createElement("div");t.setAttribute("id","dialogue-chat-root"),document.body.appendChild(t)}this.hasLoaded||(C.render(S.default.createElement($,{store:this.store,portaled:this.settings.portaled}),this.getRootElement()),this.hasLoaded=!0)}}const et=new class{constructor(){this.getChatProvider=(t,a)=>{if(t===e.ChatProviderType.SNAPENGAGE)return new q(a);if(t===e.ChatProviderType.DIALOGUE_CHAT)return new tt(a);throw new Error(`Unknown chat provider type ${t}`)}}};function at(t){return"1508d082-aa3d-468f-9ac3-cfeb7d5a8435"===t||"c0b3fc4d-5e75-4c65-b5c0-db72be2085f7"===t}var it,st,nt,rt,ot,ht;!function(t){t.INITIALIZED="initialized",t.IMPRESSION_FAILED="impression_failed",t.CLICK="click",t.IMPRESSION="impression",t.INTERACT="interact",t.DISMISSED="dismissed",t.CLOSE="close",t.ERROR="error",t.TRANSFER="transfer"}(it||(it={})),function(t){t.CONTROL_VERSION="control_version",t.NO_ONLINE_AGENTS="no_online_agents",t.NOT_ENOUGH_TIME_ON_PAGE="not_enough_time_on_page",t.CHAT_IS_NOT_ALLOWED="chat_is_not_allowed",t.CHAT_IS_NOT_INITIALIZED="chat_is_not_initialized",t.ANOTHER_CHAT_STARTED="another_chat_started",t.COOLOFF_PERIOD="COOLOFF_PERIOD"}(st||(st={})),function(t){t.CHAT_ICON="chat_icon",t.PROACTIVE_CHAT="proactive_chat",t.RESUMED_CHAT="resumed_chat",t.REACTIVE_CHAT="reactive_chat"}(nt||(nt={})),function(t){t.UNKNOWN="unknown",t.RESUMED_CHAT="resumed_chat",t.PROACTIVE_CHAT="proactive_chat",t.REACTIVE_CHAT="reactive_chat",t.TRANSFERRED_CHAT="transferred_chat"}(rt||(rt={})),function(t){t.ATTEMPT_TO_START_UNINITIALIZED_CHAT="attempt_to_start_uninitialized_chat",t.CHAT_STARTED_FROM_UNKNOWN_SOURCE="chat_started_from_unknown_source",t.ATTEMPT_START_PROACTIVE_CHAT_WITHOUT_MESSAGE="attempt_start_proactive_chat_without_message"}(ot||(ot={})),function(t){t.DEFAULT="default",t.HIVE_VORTEX_COMBO="hive_vortex_combo"}(ht||(ht={}));class ct{constructor(t,e){this.category="megaphone-events_v0_5",this.user_id=-1,this.team_id=-1,this.entity_id=-1,this.version_id=-1,this.node_id="-1",this.parent_correlation_id="none",this.parent_event_id="none",this.external_tag="none",this.location="none",this.platform="WEB",this.surface_screen_height=-1,this.surface_screen_width=-1,this.event_details={},e&&(this.category=e),["user_id","team_id","entity_type","entity_id","version_id","node_id","event_id","event_name","correlation_id","parent_correlation_id","parent_event_id","external_tag","location","platform","surface_screen_height","surface_screen_width","event_details"].map((e=>{t.hasOwnProperty(e)&&void 0!==t[e]&&(this[e]=t[e])})),this.event_id||(this.event_id=d.InsecureUUID.v4()),Object.seal(this)}}class dt{constructor(t){this.logger=t}logEvent(t,e,a){const i={entity_type:"chat",event_name:t,correlation_id:e.correlationId,event_id:a,user_id:this.toNumber(e.userId),entity_id:this.toNumber(e.campaignId),version_id:this.toNumber(e.versionId),platform:e.platform,event_details:this.getEventDetails(t,e)};this.logger.log(new ct(i))}toNumber(t,e=-1){return null==t||""===t?e:"string"==typeof t?parseInt(t,10):"number"==typeof t?t:t.toNumber()}getEventDetails(t,e){const a={...e.eventDetails};let i=e.widgetId;return e.eventDetails.widgetOverride&&(i=e.eventDetails.widgetOverride),a.widget_id=i,a}}const pt=new n.HiveLogger,mt=new n.VortexComboLogger;const gt=new class{getChatLogger(t=ht.DEFAULT){const e=t===ht.HIVE_VORTEX_COMBO?mt:pt;return new dt(e)}};function lt(t){var e,a,i;const s=null!==(e=null==t?void 0:t.path)&&void 0!==e?e:"/team/admin/engaged_chat",r=null!==(a=null==t?void 0:t.routeParams)&&void 0!==a?a:{},o=null!==(i=null==t?void 0:t.base)&&void 0!==i?i:window.location.origin;return new n.AjaxURL(n.replacePattern(s,r),o)}const _t="MegaphoneChatCooloff";var ut,Ct;!function(t){t[t.NOT_SHOWN=0]="NOT_SHOWN",t[t.TO_SHOW_PROVIDER_REACTIVE_BUTTON_ON_LOAD=1]="TO_SHOW_PROVIDER_REACTIVE_BUTTON_ON_LOAD",t[t.TO_SHOW_PROVIDER_REACTIVE_BUTTON_ON_AGENT_STATUS_UPDATE=2]="TO_SHOW_PROVIDER_REACTIVE_BUTTON_ON_AGENT_STATUS_UPDATE",t[t.REQUESTED_PROVIDER_TO_SHOW_REACTIVE_BUTTON=3]="REQUESTED_PROVIDER_TO_SHOW_REACTIVE_BUTTON",t[t.SHOWING_PROVIDER_REACTIVE_BUTTON=4]="SHOWING_PROVIDER_REACTIVE_BUTTON",t[t.SHOWING_CHAT=5]="SHOWING_CHAT",t[t.TO_START_ON_LOAD=6]="TO_START_ON_LOAD",t[t.TO_START_ON_AGENT_STATUS_UPDATE=7]="TO_START_ON_AGENT_STATUS_UPDATE",t[t.REQUESTED_PROVIDER_TO_START_CHAT=8]="REQUESTED_PROVIDER_TO_START_CHAT",t[t.CHAT_ONGOING=9]="CHAT_ONGOING"}(ut||(ut={})),function(t){t[t.REACTIVE=0]="REACTIVE",t[t.PROACTIVE=1]="PROACTIVE",t[t.RESUME=2]="RESUME",t[t.TRANSFER=3]="TRANSFER",t[t.PROVIDER_DRIVEN_PROACTIVE=4]="PROVIDER_DRIVEN_PROACTIVE"}(Ct||(Ct={}));class St extends B{constructor(t,a,s){super(t,a),this.setupChatEnvironment=t=>{if(this._isSetup)return;if(t.featureGates.enable_vortex_logger&&(this.logger=this.loggerFactory.getChatLogger(ht.HIVE_VORTEX_COMBO)),!this.shouldAllowChat())return;if(this.initProperties=t,this.setupTime=new Date,this.hasFirstLoadOccured=!1,this.state={lifecycleState:ut.NOT_SHOWN,hasShownAChat:!1,interactedWithChat:!1,cookieBannerState:{isVisible:!1}},!t.chatMetadata)throw new Error("Did not provide chat metadata.");if(this.metadata=t.chatMetadata,!t.userProperties)throw new Error("Did not provide user properties.");const a=this.getChatProviderMetadata(t),i=t.campaignResult;if(this.setupProvider(i,a,t.userProperties,t.chatProviderType),i&&i.isControl)this.setupControlLogging(i);else{const a=i&&i.chatInitialState===e.ChatInitialState.SHOW_PROVIDER_REACTIVE_BUTTON;if(t.resume){const t=this.chatCampaignWrapper||this.defaultChatWrapper;this.deprecatedLogChatAction("chat_persistence",M(t.chatCampaign)),this.intializeStartingChat(t,Ct.RESUME)}else this.setupProactivePropertiesIfNeeded(),a&&(this.attemptToShowProviderReactiveChatButton(),this.deprecatedMaybeLogExperiment(i))}window.addEventListener("beforeunload",(()=>{this.maybeLogImpressionFailedOnUnload()}))},this.startReactiveChat=()=>{if(!this.hasFirstLoadOccured)return void this.deferStartChat();if(this.logEvent(it.CLICK,{source:"startReactiveChat"}),!this.shouldAllowChat())return void this.logEvent(it.IMPRESSION_FAILED,{failed_reason:st.CHAT_IS_NOT_ALLOWED});if(this.logAndRaiseIfNotSetup(),!this.canStartChat())return;let t=this.chatCampaignWrapper;const e=t&&D(t.chatCampaign)&&t.chatCampaign.isControl;if(!this.chatCampaignWrapper||e)return t=this.defaultChatWrapper,this.deprecatedLogChatAction("chat_initiated",M(t.chatCampaign)),void this.intializeStartingChat(t,Ct.REACTIVE);this.deprecatedLogChatAction("chat_initiated",M(t.chatCampaign)),this.intializeStartingChat(this.chatCampaignWrapper,Ct.REACTIVE)},this.startSupportChat=t=>{this.hasFirstLoadOccured?(this.logEvent(it.CLICK,{source:"startSupportChat",widgetOverride:t}),this.shouldAllowChat()?(this.logAndRaiseIfNotSetup(),this.canStartChat()&&(this.supportChatWrapper={chatCampaign:t,chatCampaignState:this.getInitialChatCampaignState()},at(t)&&n.WebRequest$2({url:lt(),data:{chatId:t}}),this.deprecatedLogChatAction("support_chat_initiated",t),this.intializeStartingChat(this.supportChatWrapper,Ct.REACTIVE))):this.logEvent(it.IMPRESSION_FAILED,{failed_reason:st.CHAT_IS_NOT_ALLOWED,widgetOverride:t})):this.deferStartChat(t)},this.isSetup=()=>this._isSetup,this.setCookieBannerInfo=t=>{this.state.cookieBannerState={isVisible:t},this.adjustProviderMarginOnStateChange()},this.regsiterVisibilityChangeCallback=t=>{this.onVisibilityChangeCallbacks.push(t)},this.deferStartChat=t=>{this.deferredStartChatCallback=()=>{t?this.startSupportChat(t):this.startReactiveChat()}},this.updateChatVisibility=t=>{this.onVisibilityChangeCallbacks.forEach((e=>e(t)))},this.adjustProviderMarginOnStateChange=()=>{this.state.cookieBannerState.isVisible?this.state.lifecycleState===ut.CHAT_ONGOING||this.state.lifecycleState===ut.SHOWING_CHAT?this.provider.removeBottomMargin():this.provider.addBottomMargin():this.provider.removeBottomMargin()},this.modifyLifecycleState=t=>{this.state.lifecycleState=t,this.adjustProviderMarginOnStateChange()},this.logAndRaiseIfNotSetup=()=>{if(!this._isSetup)throw this.logEvent(it.IMPRESSION_FAILED,{failed_reason:st.CHAT_IS_NOT_INITIALIZED}),this.logError(ot.ATTEMPT_TO_START_UNINITIALIZED_CHAT),new Error("Started chat without being initialized")},this.setupProvider=(t,e,a,i)=>{const s={chatCampaign:t,metadata:e,userProperties:a,onAgentStatusUpdate:this.onAgentStatusUpdate,onChatLoadStatusUpdate:this.onChatLoadStatusUpdate,onChatShown:this.onChatShown,onChatStarted:this.onChatStarted,onChatClosed:this.onChatClosed,onChatMinimized:this.onChatMinimized,onChatMaximized:this.onChatMaximized,onProviderDrivenOpenProactive:this.onProviderDrivenOpenProactive,onProviderReactiveButtonShown:this.onProviderReactiveButtonShown,onSwitchProviderWithNewCampaign:this.onSwitchProviderWithNewCampaign};t&&(this.chatCampaignWrapper={chatCampaign:t,chatCampaignState:this.getInitialChatCampaignState()}),this.provider=this.getChatProvider(i,s),this.defaultChatWrapper={chatCampaign:this.provider.getDefaultChatIdentifier(),chatCampaignState:this.getInitialChatCampaignState()},this._isSetup=!0},this.attemptToShowProviderReactiveChatButton=()=>{const t=this.chatCampaignWrapper;t&&D(t.chatCampaign)&&(this.state.campaign=t.chatCampaign,this.state.source_type=Ct.REACTIVE,t.chatCampaignState.isLoaded?D(t.chatCampaign)&&t.chatCampaign.mustHaveAvailableAgents?this.attemptToShowReactiveButtonChatThatMustHaveAgents(t):this.requestProviderToShowProviderReactiveButton():this.requestProviderToLoadChatToShowProviderReactiveButton(t))},this.requestProviderToShowProviderReactiveButton=()=>{this.modifyLifecycleState(ut.REQUESTED_PROVIDER_TO_SHOW_REACTIVE_BUTTON),this.provider.showProviderReactiveChatButton();const t=this.chatCampaignWrapper||this.defaultChatWrapper;this.deprecatedLogChatAction("minimized_chat_initiated",M(t.chatCampaign))},this.requestProviderToGetAgentStatusUpdateToShowProviderReactiveButton=t=>{this.modifyLifecycleState(ut.TO_SHOW_PROVIDER_REACTIVE_BUTTON_ON_AGENT_STATUS_UPDATE),this.provider.requestAgentStatusUpdate(t.chatCampaign)},this.requestProviderToLoadChatToShowProviderReactiveButton=t=>{this.modifyLifecycleState(ut.TO_SHOW_PROVIDER_REACTIVE_BUTTON_ON_LOAD),this.provider.loadChatIfNecessary(t.chatCampaign)},this.canStartChat=()=>{const t=this.state.lifecycleState;return t===ut.NOT_SHOWN||t===ut.TO_SHOW_PROVIDER_REACTIVE_BUTTON_ON_LOAD||t===ut.TO_SHOW_PROVIDER_REACTIVE_BUTTON_ON_AGENT_STATUS_UPDATE||t===ut.REQUESTED_PROVIDER_TO_SHOW_REACTIVE_BUTTON||t===ut.SHOWING_PROVIDER_REACTIVE_BUTTON},this.intializeStartingChat=(t,e)=>{this.state.source_type=e,this.state.campaign=t.chatCampaign,this.attemptToStartChat(t)},this.attemptToStartChat=t=>{const e=this.state.source_type,a=e===Ct.PROACTIVE||e===Ct.PROVIDER_DRIVEN_PROACTIVE;t.chatCampaignState.isLoaded?a&&D(t.chatCampaign)&&t.chatCampaign.mustHaveAvailableAgents?this.attemptToStartChatThatMustHaveAgents(t,e===Ct.PROVIDER_DRIVEN_PROACTIVE):e===Ct.PROVIDER_DRIVEN_PROACTIVE?this.requestProviderToHandleProviderDrivenOpen():this.requestProviderToStartChat(t):this.requestProviderToLoadChatToStartChat(t)},this.requestProviderToHandleProviderDrivenOpen=()=>{this.provider.handleProviderDrivenOpen(),this.modifyLifecycleState(ut.SHOWING_CHAT)},this.requestProviderToStartChat=t=>{this.modifyLifecycleState(ut.REQUESTED_PROVIDER_TO_START_CHAT),this.provider.startChat(t.chatCampaign,this.state.source_type===Ct.PROACTIVE)},this.requestProviderToGetAgentStatusUpdateToStartChat=t=>{this.modifyLifecycleState(ut.TO_START_ON_AGENT_STATUS_UPDATE),this.provider.requestAgentStatusUpdate(t.chatCampaign)},this.setupProactivePropertiesIfNeeded=()=>{const t=this.chatCampaignWrapper;if(!t||!D(t.chatCampaign))return;const e=t.chatCampaign,a=e.proactiveSettings;if(!a||a.whenToShowControlledByProvider||e.isControl)return;if(!e.greetingMessage)return void this.logError(ot.ATTEMPT_START_PROACTIVE_CHAT_WITHOUT_MESSAGE);const i=this.readProactiveChatCooloffCookie();if(i)return void this.logEvent(it.IMPRESSION_FAILED,{failed_reason:st.COOLOFF_PERIOD,debug_info:i},e);const s=1e3*Number(a.secondsUntilShown);setTimeout((()=>{this.state.hasShownAChat||this.state.campaign&&this.state.campaign!==e?this.logEvent(it.IMPRESSION_FAILED,{failed_reason:st.ANOTHER_CHAT_STARTED},e):this.intializeStartingChat(t,Ct.PROACTIVE)}),s)},this.setupControlLogging=t=>{const e=t.proactiveSettings,a=()=>{let e=st.CONTROL_VERSION;this.readProactiveChatCooloffCookie()?e=st.COOLOFF_PERIOD:this.state.campaign&&this.state.campaign!==t?e=st.ANOTHER_CHAT_STARTED:this.chatCampaignWrapper&&this.chatCampaignWrapper.chatCampaignState.agentStatus!==V.ONLINE&&D(this.chatCampaignWrapper.chatCampaign)&&this.chatCampaignWrapper.chatCampaign.mustHaveAvailableAgents&&(e=st.NO_ONLINE_AGENTS),this.logEvent(it.IMPRESSION_FAILED,{failed_reason:e},t)};if(!e)return void a();const i=1e3*Number(e.secondsUntilShown);setTimeout(a,i),setTimeout((()=>this.deprecatedMaybeLogExperiment(t)),i)},this.getPersistenceCookie=t=>D(t)?t.persistenceCookie:`SNAPENGAGE:${t}`,this.setChatVisibleCookie=t=>{if(!this.metadata)return;const e=this.getPersistenceCookie(t),a=this.getLegacyCampaignIdentifierToCookieStr(t);a&&i.Cookies.create(this.metadata.legacyCookieCampaignName,a,.084,this.metadata.cookieDomain),i.Cookies.create(this.metadata.cookieCampaignName,e,1,this.metadata.cookieDomain)},this.maybeSetProactiveChatCooloffCookie=(t,e)=>{if(this.metadata&&t===Ct.PROACTIVE&&e&&D(e.chatCampaign)&&e.chatCampaign.proactiveSettings&&e.chatCampaign.proactiveSettings.coolOffPeriodMinutes){const t=e.chatCampaign,a=(new Date).getTime(),s=`${t.campaignId}:${t.versionId}:${a}`,n=Number(t.proactiveSettings.coolOffPeriodMinutes)/1440;i.Cookies.create(_t,s,n,this.metadata.cookieDomain)}},this.readProactiveChatCooloffCookie=()=>i.Cookies.read(_t),this.getInitialChatCampaignState=()=>({isLoaded:!1,agentStatus:V.UNKNOWN}),this.getWrapperFromIdentifier=t=>this.chatCampaignWrapper&&U(this.chatCampaignWrapper.chatCampaign,t)?this.chatCampaignWrapper:U(this.defaultChatWrapper.chatCampaign,t)?this.defaultChatWrapper:this.supportChatWrapper&&U(this.supportChatWrapper.chatCampaign,t)?this.supportChatWrapper:void 0,this.getLegacyCampaignIdentifierToCookieStr=t=>D(t)?"snapengageChatSystemSettings"===t.systemSettings.case?t.systemSettings.value.widgetId:null:t,this.legacyToggleOutsideChatVisibilityOnAgentStatusUpdate=t=>{this.modifyVisibility("[data-snap-engage-visibility]",!1),t===V.ONLINE?this.modifyVisibility('[data-snap-engage-visibility="online"]',!0):this.modifyVisibility('[data-snap-engage-visibility="offline"]',!0)},this.modifyVisibility=(t,e)=>{const a=e?"inline":"none",i=document.querySelectorAll(t);for(let t=0;t{const a=U(this.state.campaign,t),i=this.state.lifecycleState,s=i===ut.TO_SHOW_PROVIDER_REACTIVE_BUTTON_ON_AGENT_STATUS_UPDATE&&a,n=i===ut.TO_START_ON_AGENT_STATUS_UPDATE&&a,r=this.getWrapperFromIdentifier(t);void 0!==r&&(r.chatCampaignState.agentStatus=e,this.legacyToggleOutsideChatVisibilityOnAgentStatusUpdate(e),s?this.attemptToShowProviderReactiveChatButton():n&&this.attemptToStartChat(r))},this.onChatLoadStatusUpdate=(t,e)=>{if(!this.hasFirstLoadOccured&&e){this.hasFirstLoadOccured=!0;const e=((new Date).valueOf()-this.setupTime.valueOf()).toString();this.logEvent(it.INITIALIZED,{init_latency_ms:e}),this.deprecatedLogChatAction("snapengage_loaded",M(t),{total_time:e}),this.deferredStartChatCallback&&this.deferredStartChatCallback()}const a=U(this.state.campaign,t),i=this.state.lifecycleState,s=i===ut.TO_SHOW_PROVIDER_REACTIVE_BUTTON_ON_LOAD&&a,n=i===ut.TO_START_ON_LOAD&&a,r=this.getWrapperFromIdentifier(t);void 0!==r&&(r.chatCampaignState.isLoaded=e,e&&this.provider.requestAgentStatusUpdate(t),s?this.attemptToShowProviderReactiveChatButton():n&&this.attemptToStartChat(r))},this.onProviderReactiveButtonShown=()=>{this.state.lifecycleState===ut.REQUESTED_PROVIDER_TO_SHOW_REACTIVE_BUTTON&&(this.modifyLifecycleState(ut.SHOWING_PROVIDER_REACTIVE_BUTTON),this.logEvent(it.IMPRESSION,{impression_type:nt.CHAT_ICON}))},this.onProviderDrivenOpenProactive=t=>{this.chatCampaignWrapper&&U(this.chatCampaignWrapper.chatCampaign,t)&&(this.state.hasShownAChat||(this.logEvent(it.IMPRESSION,{impression_type:nt.PROACTIVE_CHAT}),this.deprecatedMaybeLogExperiment(t),this.deprecatedLogChatAction("proactive_chat_opened",M(t)),this.canStartChat()&&this.intializeStartingChat(this.chatCampaignWrapper,Ct.PROVIDER_DRIVEN_PROACTIVE))),this.updateChatVisibility(!0)},this.onChatShown=t=>{this.state.lifecycleState!==ut.SHOWING_PROVIDER_REACTIVE_BUTTON&&this.state.lifecycleState!==ut.REQUESTED_PROVIDER_TO_START_CHAT||U(this.state.campaign,t),this.modifyLifecycleState(ut.SHOWING_CHAT),this.state.campaign=t,this.state.hasShownAChat=!0,this.state.source_type===Ct.RESUME?(this.provider.updateHmac(),this.state.interactedWithChat=!0,this.logEvent(it.IMPRESSION,{impression_type:nt.RESUMED_CHAT})):this.state.source_type!==Ct.REACTIVE||this.impressionLogged||this.logEvent(it.IMPRESSION,{impression_type:nt.REACTIVE_CHAT}),this.updateChatVisibility(!0)},this.onChatStarted=t=>{const e=this.state.source_type;if(void 0!==e){let a;this.state.interactedWithChat=!0;let i=rt.UNKNOWN;e===Ct.RESUME?(a="chat_persistence_init",i=rt.RESUMED_CHAT):e===Ct.PROACTIVE||e===Ct.PROVIDER_DRIVEN_PROACTIVE?(a="proactive_chat_initiated",i=rt.PROACTIVE_CHAT,at(M(t))&&n.WebRequest$2({url:lt(),data:{chatId:M(t)}})):e===Ct.REACTIVE?(a="reactive_chat_initiated",i=rt.REACTIVE_CHAT):e===Ct.TRANSFER&&(i=rt.TRANSFERRED_CHAT),this.logEvent(it.INTERACT,{interaction_type:i}),void 0!==a&&this.deprecatedLogChatAction(a,M(t))}else this.logError(ot.CHAT_STARTED_FROM_UNKNOWN_SOURCE);this.setChatVisibleCookie(t),this.modifyLifecycleState(ut.CHAT_ONGOING)},this.onChatClosed=(t,e)=>{let a;this.handleCookieOnClosed(this.state.source_type,this.chatCampaignWrapper);let i=V.UNKNOWN;void 0!==e.agentStatus&&(a=e.agentStatus===V.ONLINE?"online":"offline",i=e.agentStatus===V.ONLINE?V.ONLINE:V.OFFLINE),this.deprecatedLogChatAction("snapengage_chat_close",M(t),{type:e.chatType,agent_status:a});const s=this.state.interactedWithChat?it.CLOSE:it.DISMISSED;this.logEvent(s,{agents_status:i,chat_form_type:e.chatType}),this.updateChatVisibility(!1),this.resetChatState()},this.onChatMinimized=t=>{this.updateChatVisibility(!1),this.modifyLifecycleState(ut.SHOWING_PROVIDER_REACTIVE_BUTTON)},this.onChatMaximized=t=>{this.updateChatVisibility(!0),this.modifyLifecycleState(ut.SHOWING_CHAT)},this.onSwitchProviderWithNewCampaign=(t,e)=>{const a=this.provider;let i;a.handleTransferEvent(H.START_TRANSFER);try{const e=this.getChatProviderMetadata(t);if(!t.userProperties)throw new Error("User properties cannot be empty");this.setupProvider(t.campaignResult,e,t.userProperties,t.chatProviderType),i=t.campaignResult}catch{return void a.handleTransferEvent(H.ERROR_ON_TRANSFER)}this.logEvent(it.TRANSFER,{},i),this.onChatLoadStatusUpdate(e,!1),this.onAgentStatusUpdate(e,V.UNKNOWN),this.resetChatState(),this.provider.requestAgentStatusUpdate(i),a.handleTransferEvent(H.END_TRANSFER),this.setChatVisibleCookie(i),this.intializeStartingChat(this.chatCampaignWrapper,Ct.TRANSFER)},this.getChatProviderMetadata=t=>{let a;if("snapengageChatMetadata"===t.chatProviderMetadata.case)a=t.chatProviderMetadata.value;else if(t.chatProviderType!==e.ChatProviderType.DIALOGUE_CHAT)throw new Error("No provider metadata provided");return a},this.maybeLogImpressionFailedOnUnload=()=>{if(!this.impressionLogged){const t=(new Date).valueOf()-this.setupTime.valueOf();this.logEvent(it.IMPRESSION_FAILED,{failed_reason:st.NOT_ENOUGH_TIME_ON_PAGE,time_on_page_ms:t.toString()})}},this.logEvent=(t,e,a)=>{t!==it.IMPRESSION&&t!==it.IMPRESSION_FAILED||(this.impressionLogged=!0),this.logger.logEvent(t,this.createEventData(e,a))},this.logError=t=>{this.logEvent(it.ERROR,{error_type:t})},this.createEventData=(t,e)=>{let a="-1",s=-1,n=-1,r="";if(this.initProperties.userProperties&&(a=this.initProperties.userProperties.userId),e)s=Number(e.campaignId),n=Number(e.versionId),r="snapengageChatSystemSettings"===e.systemSettings.case&&e.systemSettings.value.widgetId||"";else{const t=this.chatCampaignWrapper||this.defaultChatWrapper;t&&(r=M(t.chatCampaign)||"",D(t.chatCampaign)&&(s=Number(t.chatCampaign.campaignId),n=Number(t.chatCampaign.versionId)))}return t.chat_session_id||(t.chat_session_id=i.Cookies.read("SnapABugChatSession")||""),{userId:a,campaignId:s,versionId:n,widgetId:r,correlationId:this.initProperties.loggingCorrelationId,platform:"WEB",eventDetails:t}},this.loggerFactory=s,this.logger=s.getChatLogger(),this.getChatProvider=t,this.shouldAllowChat=a,this._isSetup=!1,this.onVisibilityChangeCallbacks=[]}attemptToShowReactiveButtonChatThatMustHaveAgents(t){const e=t.chatCampaignState.agentStatus;e===V.UNKNOWN?this.requestProviderToGetAgentStatusUpdateToShowProviderReactiveButton(t):e===V.OFFLINE?(this.deprecatedLogChatAction("chat_agent_must_be_online_but_was_offline",M(t.chatCampaign)),this.logEvent(it.IMPRESSION_FAILED,{failed_reason:st.NO_ONLINE_AGENTS}),this.resetChatState()):this.requestProviderToShowProviderReactiveButton()}attemptToStartChatThatMustHaveAgents(t,e){const a=t.chatCampaignState.agentStatus;a===V.UNKNOWN?this.requestProviderToGetAgentStatusUpdateToStartChat(t):a===V.OFFLINE?(this.logEvent(it.IMPRESSION_FAILED,{failed_reason:st.NO_ONLINE_AGENTS}),this.resetChatState()):e?this.requestProviderToHandleProviderDrivenOpen():this.requestProviderToStartChat(t)}requestProviderToLoadChatToStartChat(t){this.modifyLifecycleState(ut.TO_START_ON_LOAD),this.provider.loadChatIfNecessary(t.chatCampaign)}handleCookieOnClosed(t,e){this.metadata&&(i.Cookies.delete(this.metadata.cookieCampaignName),i.Cookies.delete(this.metadata.legacyCookieCampaignName),this.maybeSetProactiveChatCooloffCookie(t,e))}deprecatedLogChatAction(t,e,a){if(!e)return;const i={...{chat_widget_id:e,url:n.get_href()},...a};n.TeamsWebActionsLogger.log(t,i),n.getAMPWebLogger().logEventCount("chat_events",t,{chat_widget_id:e})}deprecatedMaybeLogExperiment(t){D(t)}resetChatState(){this.modifyLifecycleState(ut.NOT_SHOWN),this.state.campaign=void 0,this.state.source_type=void 0,this.state.interactedWithChat=!1}}const Tt=new St(et.getChatProvider,(()=>top===window),gt);var Et=Object.freeze({__proto__:null,ChatClientSingleton:Tt,get ChatStartSourceType(){return Ct},_ChatClientSingleton:St,moduleInit:function(t){const e=a.unmarshalProto(t,L);Tt.setupChatEnvironment(e)}});e.CampaignResult=P,e.ChatInitializerProperties=L,e.ChatMetadata=T,e.ProactiveSettings=R,e.SnapengageChatMetadata=E,e.SnapengageChatSystemSettings=O,e.UserProperties=A,e.chat_client_esnext=Et,e.convertStoneSettingsToProto=t=>{const e=(t.experiments||[]).map((t=>new I(t)));return new f({botProvider:Z(t.bot_provider),botType:(a=t.bot_type,K[a[".tag"]]),environment:t.environment,settingsHmac:t.settings_hmac,experiments:e,proactiveIntent:t.proactive_intent});var a}})); //# sourceMappingURL=c_chat_chat_client.js-vflA1Pypz.map //# debugId=3104311c-ca76-3430-90af-049dc5c96020