/*! 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. */!function(t){function e(e){for(var n,o,u=e[0],i=e[1],c=0,s=[];cObject(o.jsx)(u.Provider,{value:e},t);function c(){const{chat:t}=Object(r.useContext)(u);return t}},function(t,e){t.exports=__kbnSharedDeps__.ElasticEui},function(t,e){t.exports=__kbnSharedDeps__.Rxjs},function(t,e,n){"use strict";Object.defineProperty(e,"__esModule",{value:!0});var r=n(10),o=n(1),u=r.__importDefault(n(11));e.default=function(t,e){var n=o.useState(e),r=n[0],i=n[1];return u.default((function(){var e=t.subscribe(i);return function(){return e.unsubscribe()}}),[t]),r}},function(t,e,n){n(8),__kbnBundles__.define("plugin/cloudChat/public",n,12)},function(t,e,n){n.p=window.__kbnPublicPath__.cloudChat},function(t,e){t.exports=__kbnSharedDeps_npm__},function(t,e){t.exports=__kbnSharedDeps__.TsLib},function(t,e,n){"use strict";Object.defineProperty(e,"__esModule",{value:!0});var r=n(1),o="undefined"!=typeof window?r.useLayoutEffect:r.useEffect;e.default=o},function(t,e,n){"use strict";n.r(e),n.d(e,"plugin",(function(){return b})),n.d(e,"Chat",(function(){return p}));var r=n(2),o=n.n(r),u=n(1),i=n.n(u),c=n(6),a=n.n(c),s=n(5),l=n(3),d=n(4),f=n(0);const h=i.a.lazy((()=>n.e(1).then(n.bind(null,15)).then((({Chat:t})=>({default:t}))))),p=()=>Object(f.jsx)(d.EuiErrorBoundary,null,Object(f.jsx)(u.Suspense,{fallback:Object(f.jsx)("div",null)},Object(f.jsx)(h,null)));class plugin_CloudChatPlugin{constructor(t){o()(this,"config",void 0),o()(this,"chatConfig$",new s.ReplaySubject(1)),o()(this,"Chat",void 0),o()(this,"kbnVersion",void 0),o()(this,"kbnBuildNum",void 0),this.kbnVersion=t.env.packageInfo.version,this.kbnBuildNum=t.env.packageInfo.buildNum,this.config=t.config.get()}setup(t,{cloud:e,security:n,cloudChatProvider:r}){this.setupChat({http:t.http,cloud:e,security:n,cloudChatProvider:r}).catch((t=>console.debug(`Error setting up Chat: ${t.toString()}`))),e.registerCloudService((({children:t})=>{const e=a()(this.chatConfig$,void 0);return Object(f.jsx)(l.a,{chat:e},t)})),r.registerChatProvider((()=>this.Chat))}start(t,{cloud:e}){const n=e.CloudContextProvider;return this.Chat=()=>Object(f.jsx)(n,null,Object(f.jsx)(p,null)),{Chat:this.Chat}}stop(){}async setupChat({cloud:t,http:e,security:n}){const{isCloudEnabled:r,trialEndDate:o}=t,{chatURL:u,trialBuffer:i}=this.config;if(n&&r&&u&&o&&((t,e)=>{const n=new Date(t);return n.setDate(n.getDate()+e),n>new Date})(o,i))try{const{email:t,id:n,token:r}=await e.get("/internal/cloud/chat_user");if(!t||!n||!r)return;this.chatConfig$.next({chatURL:u,user:{email:t,id:n,jwt:r,trialEndDate:o,kbnVersion:this.kbnVersion,kbnBuildNum:this.kbnBuildNum}})}catch(t){console.debug(`[cloud.chat] Could not retrieve chat config: ${t.response.status} ${t.message}`,t)}}}function b(t){return new plugin_CloudChatPlugin(t)}},function(t,e){t.exports=__kbnSharedDeps__.KbnI18n},function(t,e){t.exports=__kbnSharedDeps__.KbnUiTheme}]);