!function(e){var t={};function s(n){if(t[n])return t[n].exports;var r=t[n]={i:n,l:!1,exports:{}};return e[n].call(r.exports,r,r.exports,s),r.l=!0,r.exports}s.m=e,s.c=t,s.d=function(e,t,n){s.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:n})},s.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},s.t=function(e,t){if(1&t&&(e=s(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var n=Object.create(null);if(s.r(n),Object.defineProperty(n,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var r in e)s.d(n,r,function(t){return e[t]}.bind(null,r));return n},s.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return s.d(t,"a",t),t},s.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},s.p="",s(s.s=14)}([function(e,t){e.exports=__kbnSharedDeps__.EmotionReact},function(e,t){e.exports=__kbnSharedDeps__.ElasticEui},function(e,t){e.exports=__kbnSharedDeps__.React},function(e,t){e.exports=__kbnSharedDeps__.Moment},function(e,t){e.exports=__kbnSharedDeps__.Rxjs},function(e,t){e.exports=__kbnSharedDeps__.KbnI18nReact},function(e,t,s){e.exports=s(10)(1465)},function(e,t){e.exports=__kbnSharedDeps__.RxjsOperators},function(e,t){e.exports=__kbnSharedDeps__.KbnI18n},function(e,t){e.exports=__kbnSharedDeps__.ReactDom},function(e,t){e.exports=__kbnSharedDeps_npm__},function(e,t,s){s.r(t);var n=__kbnBundles__.get("plugin/kibanaReact/public");Object.defineProperties(t,Object.getOwnPropertyDescriptors(n))},function(e,t,s){e.exports=s(10)(1466)},function(e,t,s){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var n=s(16),r=s(2),a=n.__importDefault(s(17));t.default=function(e,t){var s=r.useState(t),n=s[0],i=s[1];return a.default((function(){var t=e.subscribe(i);return function(){return t.unsubscribe()}}),[e]),n}},function(e,t,s){s(15),__kbnBundles__.define("plugin/newsfeed/public",s,18)},function(e,t,s){s.p=window.__kbnPublicPath__.newsfeed},function(e,t){e.exports=__kbnSharedDeps__.TsLib},function(e,t,s){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var n=s(2),r="undefined"!=typeof window?n.useLayoutEffect:n.useEffect;t.default=r},function(e,t,s){"use strict";s.r(t),s.d(t,"NewsfeedApiEndpoint",(function(){return F})),s.d(t,"plugin",(function(){return A}));var n=s(6),r=s.n(n),a=s(4),i=s(7),o=s(9),u=s.n(o),c=s(2),l=s.n(c),d=s(3),f=s.n(d),h=s(5),b=s(11),p=s(1),j=s(8),m=s(13),g=s.n(m),_=s(12),O=s.n(_),w=s(0);const x=()=>Object(w.jsx)(p.EuiEmptyPrompt,{iconType:"documents",titleSize:"s","data-test-subj":"emptyNewsfeed",title:Object(w.jsx)("h2",null,Object(w.jsx)(h.FormattedMessage,{id:"newsfeed.emptyPrompt.noNewsTitle",defaultMessage:"No news?"})),body:Object(w.jsx)("p",null,Object(w.jsx)(h.FormattedMessage,{id:"newsfeed.emptyPrompt.noNewsText",defaultMessage:"If your Kibana instance doesn’t have internet access, ask your administrator to disable this feature. Otherwise, we’ll keep trying to fetch the news."}))}),S=({showPlainSpinner:e})=>Object(w.jsx)(p.EuiEmptyPrompt,{title:e?Object(w.jsx)(p.EuiLoadingSpinner,{size:"xl"}):Object(w.jsx)(p.EuiLoadingElastic,{size:"xl"}),body:Object(w.jsx)("p",null,Object(w.jsx)(h.FormattedMessage,{id:"newsfeed.loadingPrompt.gettingNewsText",defaultMessage:"Getting the latest news..."}))}),y=e=>{const{newsFetchResult:t,setFlyoutVisible:s}=Object(c.useContext)(v),n=Object(c.useCallback)((()=>s(!1)),[s]),{showPlainSpinner:r,...a}=e;return Object(w.jsx)(p.EuiPortal,null,Object(w.jsx)(p.EuiFlyout,O()({},a,{onClose:n,size:"s","aria-labelledby":"flyoutSmallTitle",className:"kbnNews__flyout","data-test-subj":"NewsfeedFlyout"}),Object(w.jsx)(p.EuiFlyoutHeader,{hasBorder:!0},Object(w.jsx)(p.EuiTitle,{size:"s"},Object(w.jsx)("h2",{id:"flyoutSmallTitle"},Object(w.jsx)(h.FormattedMessage,{id:"newsfeed.flyoutList.whatsNewTitle",defaultMessage:"What's new at Elastic"})))),Object(w.jsx)(p.EuiFlyoutBody,{className:"kbnNews__flyoutAlerts"},t?t.feedItems.length>0?t.feedItems.map((e=>Object(w.jsx)(p.EuiHeaderAlert,{key:e.hash,title:e.title,text:e.description,"data-test-subj":"newsHeadAlert",action:Object(w.jsx)(p.EuiLink,{target:"_blank",href:e.linkUrl,external:!0},e.linkText),date:e.publishOn.format("DD MMMM YYYY"),badge:e.badge?Object(w.jsx)(p.EuiBadge,{color:"hollow"},e.badge):void 0}))):Object(w.jsx)(x,null):Object(w.jsx)(S,{showPlainSpinner:e.showPlainSpinner})),Object(w.jsx)(p.EuiFlyoutFooter,null,Object(w.jsx)(p.EuiFlexGroup,{justifyContent:"spaceBetween",alignItems:"center"},Object(w.jsx)(p.EuiFlexItem,{grow:!1},Object(w.jsx)(p.EuiButtonEmpty,{iconType:"cross",onClick:n,flush:"left"},Object(w.jsx)(h.FormattedMessage,{id:"newsfeed.flyoutList.closeButtonLabel",defaultMessage:"Close"}))),Object(w.jsx)(p.EuiFlexItem,{grow:!1},t?Object(w.jsx)(p.EuiText,{color:"subdued",size:"s"},Object(w.jsx)("p",null,Object(w.jsx)(h.FormattedMessage,{id:"newsfeed.flyoutList.versionTextLabel",defaultMessage:"{version}",values:{version:`Version ${t.kibanaVersion}`}}))):null)))))},v=l.a.createContext({}),k=({newsfeedApi:e,hasCustomBranding$:t})=>{const[s,n]=Object(c.useState)(!1),[r,a]=Object(c.useState)(null),i=g()(t,!1),o=Object(c.useMemo)((()=>!!r&&r.hasNew),[r]),u=Object(c.useRef)(null);Object(c.useEffect)((()=>{const t=e.fetchResults$.subscribe((e=>{a(e)}));return()=>t.unsubscribe()}),[e]);const d=Object(c.useCallback)((()=>{r&&e.markAsRead(r.feedItems.map((e=>e.hash))),n(!s)}),[e,r,s]);return Object(w.jsx)(v.Provider,{value:{setFlyoutVisible:n,newsFetchResult:r}},Object(w.jsx)(l.a.Fragment,null,Object(w.jsx)(p.EuiHeaderSectionItemButton,{ref:e=>u.current=e,"data-test-subj":"newsfeed","aria-controls":"keyPadMenu","aria-expanded":s,"aria-haspopup":"true","aria-label":o?j.i18n.translate("newsfeed.headerButton.unreadAriaLabel",{defaultMessage:"Newsfeed menu - unread items available"}):j.i18n.translate("newsfeed.headerButton.readAriaLabel",{defaultMessage:"Newsfeed menu - all items read"}),notification:!!o||null,onClick:d},Object(w.jsx)(p.EuiIcon,{type:"cheer",size:"m"})),s?Object(w.jsx)(y,{focusTrapProps:{shards:[u]},showPlainSpinner:i}):null))},N=e=>!f()(e.expire_on).isBefore(Date.now())&&!f()(e.publish_on).isAfter(Date.now()),I=e=>![e.title,e.description,e.linkText,e.linkUrl,e.publishOn,e.hash].includes(void 0);class driver_NewsfeedApiDriver{constructor(e,t,s,n){r()(this,"kibanaVersion",void 0),r()(this,"loadedTime",f()().utc()),this.userLanguage=t,this.fetchInterval=s,this.storage=n,this.kibanaVersion=e.replace(/^(\d+\.\d+\.\d+).*/,"$1")}shouldFetch(){const e=this.storage.getLastFetchTime();if(!e)return!0;const t=f()(e);if(this.loadedTime.diff(t)>0)return!0;const s=f.a.utc();return f.a.duration(s.diff(t)).asMilliseconds()>this.fetchInterval}fetchNewsfeedItems(e){const t=e.pathTemplate.replace("{VERSION}",this.kibanaVersion),s=(e.urlRoot||"https://feeds.elastic.co")+t,n=new Request(s,{method:"GET"});return a.from(window.fetch(n).then((async e=>{const{items:t}=await e.json();return this.convertResponse(t)})))}convertResponse(e){const t=((e,t)=>e.filter(N).map((e=>((e,t)=>{const{expire_on:s,publish_on:n,languages:r,title:a,description:i,link_text:o,link_url:u,badge:c,hash:l}=e;let d=t;return r&&r.includes(d)||(d="en"),{title:a[d],description:i[d],linkText:null!=o?o[d]:null,linkUrl:u[d],badge:null!=c?c[d]:null,publishOn:f()(n),expireOn:f()(s),hash:l.slice(0,10)}})(e,t))).filter(I))(e,this.userLanguage),s=this.storage.setFetchedItems(t.map((e=>e.hash)));return{error:null,kibanaVersion:this.kibanaVersion,hasNew:s,feedItems:t}}}class NeverFetchNewsfeedApiDriver{shouldFetch(){return!1}fetchNewsfeedItems(){throw new Error("Not implemented!")}}class storage_NewsfeedStorage{constructor(e){r()(this,"lastFetchStorageKey",void 0),r()(this,"readStatusStorageKey",void 0),r()(this,"unreadStatus$",void 0),this.lastFetchStorageKey=R(e,"lastFetch"),this.readStatusStorageKey=R(e,"readStatus"),this.unreadStatus$=new a.BehaviorSubject(E(this.getReadStatus()))}getLastFetchTime(){const e=localStorage.getItem(this.lastFetchStorageKey);if(e)return f()(e,"x").toDate()}setLastFetchTime(e){localStorage.setItem(this.lastFetchStorageKey,JSON.stringify(e.getTime()))}setFetchedItems(e){const t=this.getReadStatus(),s={};return e.forEach((e=>{var n;s[e]=null!==(n=t[e])&&void 0!==n&&n})),this.setReadStatus(s)}markItemsAsRead(e){const t=this.getReadStatus();return e.forEach((e=>{t[e]=!0})),this.setReadStatus(t)}isAnyUnread(){return this.unreadStatus$.value}isAnyUnread$(){return this.unreadStatus$.asObservable()}getReadStatus(){try{return JSON.parse(localStorage.getItem(this.readStatusStorageKey)||"{}")}catch(e){return{}}}setReadStatus(e){const t=E(e);return this.unreadStatus$.next(E(e)),localStorage.setItem(this.readStatusStorageKey,JSON.stringify(e)),t}}const E=e=>Object.values(e).some((e=>!e)),R=(e,t)=>`newsfeed.${e}.${t}`;let F;!function(e){e.KIBANA="kibana",e.KIBANA_ANALYTICS="kibana-analytics",e.SECURITY_SOLUTION="security-solution",e.OBSERVABILITY="observability"}(F||(F={}));class plugin_NewsfeedPublicPlugin{constructor(e){r()(this,"kibanaVersion",void 0),r()(this,"config",void 0),r()(this,"stop$",new a.ReplaySubject(1)),this.kibanaVersion=e.env.packageInfo.version;const t=e.config.get();this.config=Object.freeze({...t,mainInterval:f.a.duration(t.mainInterval),fetchInterval:f.a.duration(t.fetchInterval)})}setup(e){return{}}start(e,{screenshotMode:t}){const s=t.isScreenshotMode(),n=this.createNewsfeedApi(this.config,F.KIBANA,s);return e.chrome.navControls.registerRight({order:1e3,mount:t=>this.mount(n,t,e.theme.theme$,e.customBranding.hasCustomBranding$)}),{createNewsFeed$:e=>{const t=Object.assign({},this.config,{service:{...this.config.service,pathTemplate:`/${e}/v{VERSION}.json`}}),{fetchResults$:n}=this.createNewsfeedApi(t,e,s);return n}}}stop(){this.stop$.next()}createNewsfeedApi(e,t,s){const n=function(e,t,s,n){const r=new storage_NewsfeedStorage(s),o=e.mainInterval.asMilliseconds(),u=(()=>{if(n)return new NeverFetchNewsfeedApiDriver;const s=j.i18n.getLocale(),a=e.fetchInterval.asMilliseconds();return new driver_NewsfeedApiDriver(t,s,a,r)})(),c=Object(a.timer)(0,o).pipe(Object(i.filter)((()=>u.shouldFetch())),Object(i.mergeMap)((()=>u.fetchNewsfeedItems(e.service).pipe(Object(i.catchError)((e=>(window.console.error(e),Object(a.of)({error:e,kibanaVersion:t,hasNew:!1,feedItems:[]}))))))),Object(i.tap)((()=>r.setLastFetchTime(new Date))));return{fetchResults$:Object(a.combineLatest)([c,r.isAnyUnread$()]).pipe(Object(i.map)((([e,t])=>({...e,hasNew:!e.error&&t})))),markAsRead:e=>{r.markItemsAsRead(e)}}}(e,this.kibanaVersion,t,s);return{markAsRead:n.markAsRead,fetchResults$:n.fetchResults$.pipe(Object(i.takeUntil)(this.stop$),Object(i.catchError)((()=>a.of(null))))}}mount(e,t,s,n){return u.a.render(Object(w.jsx)(b.KibanaThemeProvider,{theme$:s},Object(w.jsx)(h.I18nProvider,null,Object(w.jsx)(k,{newsfeedApi:e,hasCustomBranding$:n}))),t),()=>u.a.unmountComponentAtNode(t)}}function A(e){return new plugin_NewsfeedPublicPlugin(e)}}]);