!function(e){function t(t){for(var n,i,o=t[0],r=t[1],s=0,u=[];s({type:"event_annotation_group",annotations:t.annotations.filter((e=>!e.isHidden)),dataView:t.dataView,ignoreGlobalFilters:t.ignoreGlobalFilters})}}var u=n(7)},function(e,t,n){"use strict";n.d(t,"a",(function(){return a})),n.d(t,"b",(function(){return i}));const a={ASTERISK:"asterisk",ALERT:"alert",BELL:"bell",BOLT:"bolt",BUG:"bug",CIRCLE:"circle",EDITOR_COMMENT:"editorComment",FLAG:"flag",HEART:"heart",MAP_MARKER:"mapMarker",PIN_FILLED:"pinFilled",STAR_EMPTY:"starEmpty",STAR_FILLED:"starFilled",TAG:"tag",TRIANGLE:"triangle"},i="event-annotation-group"},function(e,t,n){"use strict";n.d(t,"a",(function(){return a}));const a="annotations"},function(e,t,n){e.exports=n(14)(1465)},function(e,t){e.exports=__kbnSharedDeps__.KbnDatemath},function(e,t){e.exports=__kbnSharedDeps__.Rxjs},function(e,t,n){"use strict";n.d(t,"b",(function(){return a})),n.d(t,"a",(function(){return i}));const a=1,i="event-annotation-group"},function(e,t,n){n.r(t);var a=__kbnBundles__.get("plugin/kibanaUtils/public");Object.defineProperties(t,Object.getOwnPropertyDescriptors(a))},function(e,t){e.exports=__kbnSharedDeps__.ElasticCharts},function(e,t){e.exports=__kbnSharedDeps_npm__},function(e,t,n){n(16),__kbnBundles__.define("plugin/eventAnnotation/public",n,17),__kbnBundles__.define("plugin/eventAnnotation/common",n,5)},function(e,t,n){n.p=window.__kbnPublicPath__.eventAnnotation},function(e,t,n){"use strict";n.r(t),n.d(t,"plugin",(function(){return P})),n.d(t,"EventAnnotationService",(function(){return event_annotation_service_EventAnnotationService}));var a=n(12),i=n(0),o=n(8),r=n.n(o);class event_annotation_service_EventAnnotationService{constructor(e,t){r()(this,"eventAnnotationService",void 0),r()(this,"core",void 0),r()(this,"contentManagement",void 0),this.core=e,this.contentManagement=t}async getService(){if(!this.eventAnnotationService){const{getEventAnnotationService:e}=await n.e(4).then(n.bind(null,126));this.eventAnnotationService=e(this.core,this.contentManagement)}return this.eventAnnotationService}}var s=n(5);const l=()=>({name:"fetch_event_annotations",aliases:[],type:"datatable",inputTypes:["kibana_context","null"],help:i.i18n.translate("eventAnnotation.fetchEventAnnotations.description",{defaultMessage:"Fetch event annotations"}),args:{groups:{types:["event_annotation_group"],help:i.i18n.translate("eventAnnotation.fetchEventAnnotations.args.annotationConfigs",{defaultMessage:"Annotation configs"}),multi:!0},interval:{required:!0,types:["string"],help:i.i18n.translate("eventAnnotation.fetchEventAnnotations.args.interval.help",{defaultMessage:"Interval to use for this aggregation"})}}});var u=n(10),d=n(4),c=n(3),p=n(2),g=n.n(p),f=n(13),m=n(9),v=n.n(m);const _=[{id:"id",name:"id",meta:{type:"string"}},{id:"time",name:"time",meta:{type:"string"}},{id:"endTime",name:"endTime",meta:{type:"string"}},{id:"timebucket",name:"timebucket",meta:{type:"string"}},{id:"type",name:"type",meta:{type:"string"}},{id:"label",name:"label",meta:{type:"string"}},{id:"color",name:"color",meta:{type:"string"}},{id:"lineStyle",name:"lineStyle",meta:{type:"string"}},{id:"lineWidth",name:"lineWidth",meta:{type:"number"}},{id:"icon",name:"icon",meta:{type:"string"}},{id:"textVisibility",name:"textVisibility",meta:{type:"boolean"}},{id:"textField",name:"textField",meta:{type:"string"}},{id:"outside",name:"outside",meta:{type:"number"}},{id:"type",name:"type",meta:{type:"string"}},{id:"skippedCount",name:"skippedCount",meta:{type:"number"}}],h=e=>"endTime"in e,b=e=>"time"in e&&!("endTime"in e);function y(e){const t=v.a.parse(e);return t?t.toDate():void 0}function A(e){const t=v.a.parse(e.from),n=v.a.parse(e.to,{roundUp:!0});if(t&&n)return{from:t.toDate(),to:n.toDate()}}const S=(e,t)=>"time"in e&&"time"in t?e.time.localeCompare(t.time):0,w=(e,t=_)=>({type:"datatable",columns:t,rows:e});function F(e){return{...Object(d.pick)(e,["label","color","icon","lineWidth","lineStyle","textVisibility"])}}const x={rows:[],columns:[],type:"datatable"},M=(e,t,{inspectorAdapters:n,abortSignal:a,getSearchSessionId:o,getExecutionContext:r},s)=>Object(u.defer)((async()=>{if(null==e||!e.timeRange||!t.groups)return x;const{aggs:l,dataViews:p,searchSource:f,getNow:m,uiSettings:v}=await s(),M=((e,t,n)=>{const a=n&&A(n);if(!a)return;const i=new c.TimeBuckets({"histogram:maxBars":e.get(c.UI_SETTINGS.HISTOGRAM_MAX_BARS),"histogram:barTarget":e.get(c.UI_SETTINGS.HISTOGRAM_BAR_TARGET),dateFormat:e.get("dateFormat"),"dateFormat:scaled":e.get("dateFormat:scaled")});return i.setInterval(t),i.setBounds({min:g()(a.from),max:g()(a.to)}),i.getInterval().expression})(v,t.interval,null==e?void 0:e.timeRange);if(!M)return x;const E=t.groups.map((e=>e.dataView.value)).reduce(((e,t)=>e.find((e=>e.id===t.id))?e:[...e,t]),[]),j=await Promise.all(E.map((e=>p.create(e,!0)))),[P,C]=Object(d.partition)(function({groups:e},t,n){const a=e.map((e=>e.annotations.reduce(((a,i)=>{if(h(o=i)||b(o))return((e,t)=>{if(!t)return!1;const{from:n,to:a}=A(t)||{};if(!n||!a)return!1;if(h(e)){const t=y(e.time),i=y(e.endTime);if(t&&i)return!(t>=a||i=n&&t<=a}return!0})(i,null==t?void 0:t.timeRange)?(a.manual||(a.manual={type:"manual",annotations:[]}),a.manual.annotations.push(i),a):a;var o;{var r,s;const t=n.find((t=>t.id===e.dataView.value.id)),o=null!==(r=i.timeField)&&void 0!==r?r:t.timeFieldName||(null===(s=t.fields.find((e=>"date"===e.type&&e.displayName)))||void 0===s?void 0:s.name),l=`${e.dataView.value.id}-${o}-${Boolean(e.ignoreGlobalFilters)}`,u=a[l];if(u){let e=[...u.allFields||[],...i.extraFields||[]];return i.textField&&(e=[...e,i.textField]),{...a,[l]:{...u,allFields:[...new Set(e)],annotations:[...u.annotations,i]}}}let d=i.extraFields||[];return i.textField&&(d=[...d,i.textField]),{...a,[l]:{type:"query",dataView:t,timeField:o,allFields:d,annotations:[i],ignoreGlobalFilters:Boolean(e.ignoreGlobalFilters)}}}}),{}))).reduce(((e,t)=>(Object.keys(t).forEach((n=>{if(e[n]){const a=t[n],i=e[n];T(a)||T(i)?e[n]={...i,annotations:[...i.annotations,...a.annotations]}:e[n]={...i,annotations:[...i.annotations,...a.annotations],allFields:[...new Set([...i.allFields||[],...a.allFields||[]])]}}else e[n]=t[n]})),e)),{});return Object.values(a)}(t,e,j),T),I=P.length?k(P[0],M,function(e){const t=e.get("dateFormat:tz");return"Browser"===t?g.a.tz.guess():t}(v)):[];if(!C.length)return I.length?w(I):x;const q=async({dataView:t,aggConfigs:s,timeFields:l,ignoreGlobalFilters:d})=>Object(u.lastValueFrom)((e=>Object(c.handleEsaggsRequest)(e))({aggs:s,indexPattern:t,timeFields:l,filters:d||null==e?void 0:e.filters,query:d||null==e?void 0:e.query,timeRange:null==e?void 0:e.timeRange,abortSignal:a,inspectorAdapters:n,searchSessionId:o(),searchSourceService:f,getNow:m,executionContext:r(),title:i.i18n.translate("eventAnnotation.fetchEventAnnotations.inspector.dataRequest.title",{defaultMessage:"Annotations"}),description:i.i18n.translate("eventAnnotation.fetchEventAnnotations.inspector.dataRequest.description",{defaultMessage:"This request queries Elasticsearch to fetch the data for the annotations."})})),D=await O(C,M,l),V=C.flatMap((e=>e.annotations));return((e,t,n)=>{const a=e.flatMap((({response:e,fieldsColIdMap:t})=>{const n=Object.fromEntries(Object.entries(t).map((([e,t])=>[t,e])));return e.columns.filter((e=>n[e.id])).map((e=>({...e,name:n[e.id],id:`field:${n[e.id]}`})))})).reduce(((e,t)=>(e.find((e=>e.id===t.id))||e.push(t),e)),[]).concat(_),i=e.flatMap((({response:e,fieldsColIdMap:n})=>e.rows.map((e=>{var a;const i=t.find((({id:t})=>t===e["col-0-1"]));if(!i)throw new Error(`Could not find annotation config for id: ${e["col-0-1"]}`);let o={};null!=i&&null!==(a=i.extraFields)&&void 0!==a&&a.length&&(o=i.extraFields.reduce(((t,a)=>(t[`field:${a}`]=e[n[a]],t)),{})),null!=i&&i.textField&&(o[`field:${i.textField}`]=e[n[i.textField]]);let r={...F(i),id:e["col-0-1"],timebucket:g()(e["col-1-2"]).toISOString(),time:e["col-3-4"],type:"point",label:i.label,extraFields:o};const s=e["col-2-3"];return s>10&&(r={skippedCount:s-10,...r}),r})))).concat(...n).sort(((e,t)=>e.timebucket.localeCompare(t.timebucket))),o=i.reduce(((e,t)=>(t.skippedCount&&(e[t.timebucket]=(e[t.timebucket]||0)+t.skippedCount),e)),{}),r=i.reduce(((e,t)=>(Array.isArray(t.time)?t.time.forEach(((n,a)=>{const i={};t.extraFields&&Object.entries(null==t?void 0:t.extraFields).forEach((([e,t])=>{i[e]=Array.isArray(t)?t[a]:t})),e.push({...Object(d.omit)(t,["extraFields","skippedCount"]),...i,label:Array.isArray(t.label)?t.label[a]:t.label,time:n})})):e.push({...Object(d.omit)(t,["extraFields","skippedCount"]),...t.extraFields}),e)),[]).sort(S).reduce(((e,t,n,a)=>n===a.length-1||t.timebucket!==a[n+1].timebucket?(e.push({...t,skippedCount:o[t.timebucket]}),e):(e.push(t),e)),[]);return w(r,a)})(await Promise.all(D.map((async({esaggsParams:e,fieldsColIdMap:t})=>({response:await q(e),fieldsColIdMap:t})))),V,I)})),T=e=>"manual"===e.type,k=(e,t,n)=>e.annotations.map((e=>{const a=g()(e.time).valueOf(),i=Object(f.roundDateToESInterval)(a,Object(c.parseEsInterval)(t),"start",n);return{timebucket:g()(i).toISOString(),...e,type:b(e)?"point":"range"}})).sort(S),O=(e,t,n)=>e.map((e=>{var a,i;const o=[{type:"agg_type",value:{enabled:!0,schema:"bucket",type:"filters",params:{filters:e.annotations.map((e=>({label:e.id,input:{...e.filter}})))}}},{type:"agg_type",value:{enabled:!0,schema:"bucket",type:"date_histogram",params:{useNormalizedEsInterval:!0,field:e.timeField,interval:t}}},{type:"agg_type",value:{enabled:!0,schema:"metric",type:"count"}},{type:"agg_type",value:{enabled:!0,type:"top_metrics",params:{field:e.timeField,size:10,sortOrder:"asc",sortField:e.timeField}}},...(e.allFields||[]).map((t=>({type:"agg_type",value:{enabled:!0,type:"top_metrics",params:{field:t,size:10,sortOrder:"asc",sortField:e.timeField}}})))],r=n.createAggConfigs(e.dataView,null!==(a=null==o?void 0:o.map((e=>e.value)))&&void 0!==a?a:[]);return{esaggsParams:{dataView:e.dataView,aggConfigs:r,timeFields:[e.timeField],ignoreGlobalFilters:Boolean(e.ignoreGlobalFilters)},fieldsColIdMap:(null===(i=e.allFields)||void 0===i?void 0:i.reduce(((e,t,n)=>({...e,[t]:`col-${n+4}-${n+5}`})),{}))||{}}}));var E=n(7),j=n(11);class plugin_EventAnnotationPlugin{setup(e,t){t.expressions.registerFunction(s.manualPointEventAnnotation),t.expressions.registerFunction(s.manualRangeEventAnnotation),t.expressions.registerFunction(s.queryPointEventAnnotation),t.expressions.registerFunction(s.eventAnnotationGroup),t.expressions.registerFunction(function({getStartServices:e}){return function({getStartDependencies:e}){return{...l(),fn:(t,n,a)=>M(t,n,a,e)}}({getStartDependencies:async()=>{const[{uiSettings:t},{data:{search:n,dataViews:a,nowProvider:i}}]=await e();return{aggs:n.aggs,searchSource:n.searchSource,dataViews:a,getNow:()=>i.get(),uiSettings:t}}})}({getStartServices:e.getStartServices})),t.contentManagement.registry.register({id:j.a,version:{latest:j.b},name:i.i18n.translate("eventAnnotation.content.name",{defaultMessage:"Annotation group"})}),t.visualizations.listingViewRegistry.add({title:i.i18n.translate("eventAnnotation.listingViewTitle",{defaultMessage:"Annotation groups"}),id:E.a,getTableList:async t=>{const[i,o]=await e.getStartServices(),r=await new event_annotation_service_EventAnnotationService(i,o.contentManagement).getService(),s=await o.dataViews.getIds(),l=await Promise.all(s.map((e=>o.dataViews.get(e)))),u={core:i,savedObjectsTagging:o.savedObjectsTagging,eventAnnotationService:r,PresentationUtilContextProvider:o.presentationUtil.ContextProvider,dataViews:l,createDataView:o.dataViews.create.bind(o.dataViews),queryInputServices:{http:i.http,docLinks:i.docLinks,notifications:i.notifications,uiSettings:i.uiSettings,dataViews:o.dataViews,unifiedSearch:o.unifiedSearch,data:o.data,storage:new a.Storage(localStorage)}},{getTableList:d}=await n.e(1).then(n.bind(null,122));return d(t,u)}})}start(e,t){return new event_annotation_service_EventAnnotationService(e,t.contentManagement)}}const P=()=>new plugin_EventAnnotationPlugin},function(e,t){e.exports=__kbnSharedDeps__.EmotionReact},function(e,t){e.exports=__kbnSharedDeps__.React},function(e,t){e.exports=__kbnSharedDeps__.ElasticEui},function(e,t){e.exports=__kbnSharedDeps__.Classnames},function(e,t){e.exports=__kbnSharedDeps__.KbnI18nReact},function(e,t){e.exports=__kbnSharedDeps__.KbnUiTheme},function(e,t){e.exports=__kbnSharedDeps__.TsLib},function(e,t){e.exports=__kbnSharedDeps__.EmotionCache},function(e,t,n){n.r(t);var a=__kbnBundles__.get("plugin/dataViews/common");Object.defineProperties(t,Object.getOwnPropertyDescriptors(a))},function(e,t,n){n.r(t);var a=__kbnBundles__.get("plugin/kibanaReact/public");Object.defineProperties(t,Object.getOwnPropertyDescriptors(a))},function(e,t){e.exports=__kbnSharedDeps__.ReactRouterDom},function(e,t){e.exports=__kbnSharedDeps__.Uuid},function(e,t,n){n.r(t);var a=__kbnBundles__.get("plugin/savedObjectsFinder/public");Object.defineProperties(t,Object.getOwnPropertyDescriptors(a))},function(e,t){e.exports=__kbnSharedDeps__.KbnEsQuery},function(e,t,n){n.r(t);var a=__kbnBundles__.get("plugin/unifiedSearch/public");Object.defineProperties(t,Object.getOwnPropertyDescriptors(a))}]);