(window.eventAnnotation_bundle_jsonpfunction=window.eventAnnotation_bundle_jsonpfunction||[]).push([[4],{1:function(e,t,n){"use strict";n.d(t,"b",(function(){return a})),n.d(t,"d",(function(){return r})),n.d(t,"f",(function(){return s})),n.d(t,"e",(function(){return c})),n.d(t,"a",(function(){return d})),n.d(t,"c",(function(){return l}));var i=n(23),o=n(0);const a=i.euiLightVars.euiColorAccent,r="#F04E981A",s=e=>Boolean(e&&"range"===(null==e?void 0:e.key.type)),c=e=>Boolean(e&&"query"===e.type),d=(e,t,n)=>n?{...n,id:e}:u(e,t),l=o.i18n.translate("eventAnnotationCommon.manualAnnotation.defaultAnnotationLabel",{defaultMessage:"Event"}),u=(e,t)=>({label:l,type:"manual",key:{type:"point_in_time",timestamp:t},icon:"triangle",id:e})},126:function(e,t,n){"use strict";n.r(t),n.d(t,"hasIcon",(function(){return v})),n.d(t,"getEventAnnotationService",(function(){return h}));var i=n(33),o=n.n(i),a=n(19),r=n(4),s=n(3),c=n(26),d=n(1),l=n(0),u=n(22),p=n(30),f=n(20),b=n(18),y=n(6),m={name:"13udsys",styles:"height:100%"};const g=({contentClient:e,uiSettings:t,fixedPageSize:n=10,checkHasAnnotationGroups:i,onChoose:o,onCreateNew:r})=>{const[s,c]=Object(a.useState)();return Object(a.useEffect)((()=>{i().then(c)}),[i]),void 0===s?Object(b.jsx)(f.EuiFlexGroup,{responsive:!1,justifyContent:"center"},Object(b.jsx)(f.EuiFlexItem,{grow:0},Object(b.jsx)(f.EuiLoadingSpinner,null))):!1===s?Object(b.jsx)(f.EuiFlexGroup,{css:m,direction:"column",justifyContent:"center"},Object(b.jsx)(f.EuiFlexItem,null,Object(b.jsx)(f.EuiEmptyPrompt,{titleSize:"xs",title:Object(b.jsx)("h2",null,Object(b.jsx)(u.FormattedMessage,{id:"eventAnnotation.eventAnnotationGroup.savedObjectFinder.emptyPromptTitle",defaultMessage:"Start by adding an annotation layer"})),body:Object(b.jsx)(f.EuiText,{size:"s"},Object(b.jsx)("p",null,Object(b.jsx)(u.FormattedMessage,{id:"eventAnnotation.eventAnnotationGroup.savedObjectFinder.emptyPromptDescription",defaultMessage:"There are currently no annotations available to select from the library. Create a new layer to add annotations."}))),actions:Object(b.jsx)(f.EuiButton,{onClick:()=>r(),size:"s"},Object(b.jsx)(u.FormattedMessage,{id:"eventAnnotation.eventAnnotationGroup.savedObjectFinder.emptyCTA",defaultMessage:"Create annotation layer"}))}))):Object(b.jsx)(p.SavedObjectFinder,{key:"searchSavedObjectFinder",fixedPageSize:n,onChoose:(e,t,n,i)=>{o({id:e,type:t,fullName:n,savedObject:i})},showFilter:!1,noItemsMessage:Object(b.jsx)(u.FormattedMessage,{id:"eventAnnotation.eventAnnotationGroup.savedObjectFinder.notFoundLabel",defaultMessage:"No matching annotation groups found."}),savedObjectMetaData:x,services:{contentClient:e,uiSettings:t}})},x=[{type:y.b,getIconForSavedObject:()=>"annotation",name:l.i18n.translate("eventAnnotation.eventAnnotationGroup.metadata.name",{defaultMessage:"Annotations Groups"}),includeFields:["*"]}];var j=n(11);function v(e){return null!=e&&"empty"!==e}function h(e,t){const n=t.client,i=e=>{var t;const n=e.attributes.dataViewSpec?c.DataViewPersistableStateService.inject(e.attributes.dataViewSpec,e.references):void 0;return{title:e.attributes.title,description:e.attributes.description,tags:e.references.filter((e=>"tag"===e.type)).map((({id:e})=>e)),ignoreGlobalFilters:e.attributes.ignoreGlobalFilters,indexPatternId:n?n.id:null===(t=e.references.find((e=>"index-pattern"===e.type)))||void 0===t?void 0:t.id,annotations:e.attributes.annotations,dataViewSpec:n}},a=e=>{const t=i(e);return{id:e.id,references:e.references,type:e.type,updatedAt:e.updatedAt?e.updatedAt:"",attributes:{title:t.title,description:t.description,indexPatternId:t.indexPatternId,dataViewSpec:t.dataViewSpec}}},r=e=>{const{references:t,dataViewSpec:n}=(e=>{let t,{dataViewSpec:n=null}=e;if(n){if(!n.id)throw new Error("tried to create annotation group with a data view spec that did not include an ID!");const{state:e,references:i}=c.DataViewPersistableStateService.extract(n);n=e,t=i}else t=[{type:"index-pattern",id:e.indexPatternId,name:`event-annotation-group_dataView-ref-${e.indexPatternId}`}];return{references:t,dataViewSpec:n}})(e),{title:i,description:o,tags:a,ignoreGlobalFilters:r,annotations:s}=e;return t.push(...a.map((e=>({id:e,name:e,type:"tag"})))),{attributes:{title:i,description:o,ignoreGlobalFilters:r,annotations:s,dataViewSpec:n||void 0},references:t}},s=async()=>(await n.search({contentTypeId:j.a,query:{text:"*"}})).pagination.total>0;return{loadAnnotationGroup:async e=>{const t=await n.get({contentTypeId:j.a,id:e});if(t.item.error)throw t.item.error;return i(t.item)},groupExistsWithTitle:async e=>{const{hits:t}=await n.search({contentTypeId:j.a,query:{text:e},options:{searchFields:["title"]}});for(const n of t)if(n.attributes.title.toLowerCase()===e.toLowerCase())return!0;return!1},updateAnnotationGroup:async(e,t)=>{const{attributes:i,references:o}=r(e);await n.update({contentTypeId:j.a,id:t,data:{...i},options:{references:o}})},createAnnotationGroup:async e=>{const{attributes:t,references:i}=r(e);return{id:(await n.create({contentTypeId:j.a,data:{...t},options:{references:i}})).item.id}},deleteAnnotationGroups:async e=>{for(const t of e)await n.delete({contentTypeId:j.a,id:t})},findAnnotationGroupContent:async(e,t,i,o)=>{const{pagination:r,hits:s}=await n.search({contentTypeId:j.a,query:{text:e?`${e}*`:void 0,limit:t,tags:{included:i,excluded:o}}});return{total:r.total,hits:s.map(a)}},renderEventAnnotationGroupSavedObjectFinder:n=>Object(b.jsx)(g,o()({contentClient:t.client,uiSettings:e.uiSettings,checkHasAnnotationGroups:s},n)),toExpression:w,toFetchExpression:({interval:e,groups:t})=>0===t.length?[]:[{type:"expression",chain:[{type:"function",function:"kibana",arguments:{}},{type:"function",function:"fetch_event_annotations",arguments:{interval:[e],groups:[...t.filter((e=>e.annotations.some((e=>!e.isHidden)))).map((({annotations:e,indexPatternId:t,ignoreGlobalFilters:n})=>({type:"expression",chain:[{type:"function",function:"event_annotation_group",arguments:{dataView:[{type:"expression",chain:[{type:"function",function:"indexPatternLoad",arguments:{id:[t]}}]}],annotations:[...w(e)],ignoreGlobalFilters:[Boolean(n)]}}]})))]}}]}]}}const w=e=>{const[t,n]=Object(r.partition)(e,d.e),i=[];for(const e of n)if(Object(d.f)(e)){const{label:t,color:n,key:o,outside:a,id:r}=e,{timestamp:s,endTimestamp:c}=o;i.push({type:"expression",chain:[{type:"function",function:"manual_range_event_annotation",arguments:{id:[r],time:[s],endTime:[c],label:[t||d.c],color:[n||d.d],outside:[Boolean(a)],isHidden:[Boolean(e.isHidden)]}}]})}else{const{label:t,color:n,lineStyle:o,lineWidth:a,icon:r,key:s,textVisibility:c,id:l}=e;i.push({type:"expression",chain:[{type:"function",function:"manual_point_event_annotation",arguments:{id:[l],time:[s.timestamp],label:[t||d.c],color:[n||d.b],lineWidth:[a||1],lineStyle:[o||"solid"],icon:v(r)?[r]:["triangle"],textVisibility:[c||!1],isHidden:[Boolean(e.isHidden)]}}]})}for(const e of t){const{id:t,label:n,color:o,lineStyle:a,lineWidth:r,icon:c,timeField:l,textVisibility:u,textField:p,filter:f,extraFields:b}=e;i.push({type:"expression",chain:[{type:"function",function:"query_point_event_annotation",arguments:{id:[t],timeField:l?[l]:[],label:[n||d.c],color:[o||d.b],lineWidth:[r||1],lineStyle:[a||"solid"],icon:v(c)?[c]:["triangle"],textVisibility:[u||!1],textField:u&&p?[p]:[],filter:f?[Object(s.queryToAst)(f)]:[],extraFields:b||[],isHidden:[Boolean(e.isHidden)]}}]})}return i}},33:function(e,t,n){e.exports=n(14)(1466)}}]);