/*! Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one or more contributor license agreements.
 * Licensed under the Elastic License 2.0; you may not use this file except in compliance with the Elastic License 2.0. */
(window.cloudChat_bundle_jsonpfunction=window.cloudChat_bundle_jsonpfunction||[]).push([[1],{23:function(e,t,n){"use strict";n.d(t,"a",(function(){return s}));var o=n(1),a=n(11),r=n.n(a),i=n(10);const s=({onReady:e=(()=>{}),onResize:t=(()=>{}),onPlaybookFired:n=(()=>{}),controlled:a=!0})=>{const s=Object(o.useRef)(null),d=Object(i.b)(),[c,l]=Object(o.useState)({height:0,width:0}),[u,h]=Object(o.useState)(!1),[f,b]=Object(o.useState)(!1),w=Object(o.useRef)(!1),[p,g]=r()("cloudChatPlaybookFiredOnce",!1);return Object(o.useEffect)((()=>{const o=o=>{const{current:r}=s;if(!d||null==r||!r.contentWindow||o.source!==(null==r?void 0:r.contentWindow))return;const i=(()=>{const{location:e,navigator:t,innerHeight:n,innerWidth:o}=window,{hash:a,host:r,hostname:i,href:s,origin:d,pathname:c,port:l,protocol:u,search:h}=e,{language:f,userAgent:b}=t,{title:w,referrer:p}=document;return{window:{location:{hash:a,host:r,hostname:i,href:s,origin:d,pathname:c,port:l,protocol:u,search:h},navigator:{language:f,userAgent:b},innerHeight:n,innerWidth:o},document:{title:w,referrer:p}}})(),{data:u}=o,{user:m,chatVariant:y}=d,{id:j,email:v,jwt:k,trialEndDate:O,kbnVersion:R,kbnBuildNum:C}=m,_={show:()=>{var e,t,n,o;null===(e=s.current)||void 0===e||null===(t=e.contentWindow)||void 0===t||t.postMessage({type:"driftShow"},"*"),null===(n=s.current)||void 0===n||null===(o=n.contentWindow)||void 0===o||o.postMessage({type:"driftOpenChat"},"*"),w.current=!0},hide:()=>{var e,t;null===(e=s.current)||void 0===e||null===(t=e.contentWindow)||void 0===t||t.postMessage({type:"driftHide"},"*"),w.current=!1},toggle:()=>{w.current?_.hide():_.show()}};switch(u.type){case"driftIframeReady":{const e={id:j,attributes:{email:v,trial_end_date:O,kbn_version:R,kbn_build_num:C,kbn_chat_variant:y},jwt:k};r.contentWindow.postMessage({type:"driftSetContext",data:{context:i,user:e}},"*");break}case"driftIframeResize":{const e=u.data.styles||{},n=e=>e.replace(/-./g,(e=>e[1].toUpperCase())),o=Object.keys(e).reduce(((t,o)=>(t[n(o)]=e[o],t)),{});l({...c,...o}),f||b(!0),t();break}case"driftWidgetReady":a&&_.hide(),h(!0),e(_),p&&n();break;case"driftChatClosed":a&&_.hide();break;case"driftPlaybookFired":n(),g(!0)}};return window.addEventListener("message",o),()=>window.removeEventListener("message",o)}),[d,c,e,t,u,f,a,p,n,g]),d?{enabled:!0,src:d.chatURL,ref:s,style:c,isReady:u,isResized:f}:{enabled:!1}}},25:function(e,t,n){"use strict";n.r(t),n.d(t,"Chat",(function(){return c}));var o=n(1),a=n.n(o),r=n(6),i=n(0);const s=({children:e})=>{const[t,n]=a.a.useState(!1);return a.a.useEffect((()=>{!function(e){const t=window.requestIdleCallback||window.setTimeout;"complete"===document.readyState?t((()=>e())):window.addEventListener("load",(()=>{t((()=>e()))}))}((()=>{n(!0)}))}),[]),t?Object(i.jsx)(a.a.Fragment,null,e):null};var d=n(23);const c=({onReady:e,onResize:t,onPlaybookFired:n,topOffset:o=0})=>{const a=Object(d.a)({onReady:e,onResize:t,onPlaybookFired:n});return a.enabled?Object(i.jsx)(s,null,Object(i.jsx)("iframe",{"data-test-subj":"cloud-chat-frame",title:r.i18n.translate("xpack.cloudChat.chatFrameTitle",{defaultMessage:"Chat"}),src:a.src,ref:a.ref,style:a.isReady?{position:"fixed",...a.style,bottom:"auto",inset:"initial",top:o,right:0,colorScheme:"light"}:{display:"none"}})):null}}}]);