/*! 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.maps_bundle_jsonpfunction=window.maps_bundle_jsonpfunction||[]).push([[2],{101:function(e,t,s){"use strict";s.d(t,"a",(function(){return m}));var i=s(4),a=s.n(i),o=s(152),r=s.n(o),n=s(14),l=s(1),c=s(40),d=s(24),p=s(5),u=s(74),h=s(0),g=s(3);function m(e){var t;const[s,o]=Object(i.useState)(!1),m=Object(i.useMemo)((()=>!!e.dataView&&e.dataView.fields.some((t=>!d.indexPatterns.isNestedField(t)&&null!=e&&e.isGeoPointsOnly?h.A.GEO_POINT===t.type:h.B.includes(t.type)))),[e.dataView,null==e?void 0:e.isGeoPointsOnly]),x=r()(),b=Object(i.useRef)(),j=Object(p.t)(),_=!!e.dataView&&!m,S=_?l.i18n.translate("xpack.maps.noGeoFieldInIndexPattern.message",{defaultMessage:"Data view does not contain any geospatial fields"}):"";return Object(g.jsx)(a.a.Fragment,null,s?Object(g.jsx)(a.a.Fragment,null,Object(g.jsx)(n.EuiCallOut,{title:l.i18n.translate("xpack.maps.noIndexPattern.messageTitle",{defaultMessage:"Couldn't find any data views"}),color:"warning"},Object(g.jsx)("p",null,Object(g.jsx)(c.FormattedMessage,{id:"xpack.maps.noIndexPattern.doThisPrefixDescription",defaultMessage:"You'll need to "}),Object(g.jsx)(n.EuiLink,{href:Object(p.r)().basePath.prepend("/app/management/kibana/dataViews")},Object(g.jsx)(c.FormattedMessage,{id:"xpack.maps.noIndexPattern.doThisLinkTextDescription",defaultMessage:"Create a data view."}))),Object(g.jsx)("p",null,Object(g.jsx)(c.FormattedMessage,{id:"xpack.maps.noIndexPattern.hintDescription",defaultMessage:"Don't have any data? "}),Object(g.jsx)(n.EuiLink,{href:Object(p.r)().basePath.prepend("/app/home#/tutorial_directory/sampleData")},Object(g.jsx)(c.FormattedMessage,{id:"xpack.maps.noIndexPattern.getStartedLinkText",defaultMessage:"Get started with some sample data sets."})))),Object(g.jsx)(n.EuiSpacer,{size:"s"})):null,Object(g.jsx)(n.EuiFormRow,{label:Object(u.b)(),isInvalid:_,error:S},Object(g.jsx)(j,{isInvalid:_,isDisabled:s,indexPatternId:null!==(t=e.dataView)&&void 0!==t&&t.id?e.dataView.id:"",onChange:async function(t){if(!t||0===t.length)return;let s;b.current=t;try{s=await Object(p.u)().get(t)}catch(e){return}x()&&s.id===b.current&&e.onChange(s)},placeholder:Object(u.d)(),onNoIndexPatterns:()=>{o(!0)},isClearable:!1,"data-test-subj":"mapGeoIndexPatternSelect"})))}},112:function(e,t,s){"use strict";s.r(t),s.d(t,"createLayerDescriptor",(function(){return V})),s.d(t,"ESSearchSource",(function(){return es_search_source_ESSearchSource})),s.d(t,"createDefaultLayerDescriptor",(function(){return q})),s.d(t,"esDocumentsLayerWizardConfig",(function(){return $})),s.d(t,"esTopHitsLayerWizardConfig",(function(){return D}));var i=s(0),a=s(2),o=s.n(a),r=s(39),n=s.n(r),l=s(4),c=s.n(l),d=s(1),p=s(44),u=s(47),h=s(31),g=s(306),m=s(271),x=s(5),b=s(76),j=s(14),_=s(24),S=s(40),f=s(74),y=s(95),F=s(138),O=s(81),T=s(131);let v=!1;const M=new Map;async function w(e){if(M.has(e))return M.get(e);const t=async function(e){const t=Object(x.r)(),s=Object(x.Q)();try{return await t.fetch(i.P,{method:"GET",credentials:"same-origin",version:"1",query:{indexPatternTitle:e}})}catch(t){const a=d.i18n.translate("xpack.maps.indexSettings.fetchErrorMsg",{defaultMessage:"Unable to fetch index settings for data view '{indexPatternTitle}'.\n Ensure you have '{viewIndexMetaRole}' role.",values:{indexPatternTitle:e,viewIndexMetaRole:"view_index_metadata"}});return v||(v=!0,s.addWarning(a)),console.warn(a),{maxResultWindow:i.u,maxInnerResultWindow:i.t}}}(e);return M.set(e,t),t}var C=s(3);function E(e){const[t,s]=Object(l.useState)(!1);return Object(C.jsx)(j.EuiPopover,{id:"scalingHelpPopover",anchorPosition:"leftCenter",button:Object(C.jsx)(j.EuiButtonIcon,{onClick:()=>{s(!t)},iconType:"documentation","aria-label":"Scaling documentation"}),isOpen:t,closePopover:()=>{s(!1)},repositionOnScroll:!0,ownFocus:!0},Object(C.jsx)(j.EuiPopoverTitle,null,Object(C.jsx)(S.FormattedMessage,{id:"xpack.maps.scalingDocs.title",defaultMessage:"Scaling"})),Object(C.jsx)("div",null,Object(C.jsx)(j.EuiText,{size:"s",style:{maxWidth:"36em"}},Object(C.jsx)("dl",null,Object(C.jsx)("dt",null,e.mvtOptionLabel," (Default)"),Object(C.jsx)("dd",null,Object(C.jsx)("p",null,Object(C.jsx)(S.FormattedMessage,{id:"xpack.maps.scalingDocs.mvtDetails",defaultMessage:"Vector tiles partition your map into tiles, with each tile displaying features from the first {maxResultWindow} documents. Results exceeding {maxResultWindow} are not displayed in a tile. A bounding box indicates the area where data is incomplete.",values:{maxResultWindow:e.maxResultWindow}})),Object(C.jsx)("p",null,Object(C.jsx)(S.FormattedMessage,{id:"xpack.maps.scalingDocs.mvtUseCase",defaultMessage:"Use this option to display large data sets with the fastest loading times."}))),Object(C.jsx)("dt",null,e.clustersOptionLabel),Object(C.jsx)("dd",null,Object(C.jsx)("p",null,Object(C.jsx)(S.FormattedMessage,{id:"xpack.maps.scalingDocs.clustersDetails",defaultMessage:"Display clusters when results exceed {maxResultWindow} documents. Display documents when results are less then {maxResultWindow}.",values:{maxResultWindow:e.maxResultWindow}})),Object(C.jsx)("p",null,Object(C.jsx)(S.FormattedMessage,{id:"xpack.maps.scalingDocs.clustersUseCase",defaultMessage:"Use this option to display large data sets. "}),Object(C.jsx)("i",null,Object(C.jsx)(S.FormattedMessage,{id:"xpack.maps.scalingDocs.doesNotSupportJoins",defaultMessage:"Does not support joins."})))),Object(C.jsx)("dt",null,e.limitOptionLabel),Object(C.jsx)("dd",null,Object(C.jsx)("p",null,Object(C.jsx)(S.FormattedMessage,{id:"xpack.maps.scalingDocs.limitDetails",defaultMessage:"Display features from the first {maxResultWindow} documents.",values:{maxResultWindow:e.maxResultWindow}})),Object(C.jsx)(S.FormattedMessage,{id:"xpack.maps.scalingDocs.limitUseCases",defaultMessage:"Use this option when you can not use vector tiles for the following reasons:"}),Object(C.jsx)("ul",null,Object(C.jsx)("li",null,Object(C.jsx)(S.FormattedMessage,{id:"xpack.maps.scalingDocs.limitUseCase.formatLabels",defaultMessage:"Formatted labels"})),Object(C.jsx)("li",null,Object(C.jsx)(S.FormattedMessage,{id:"xpack.maps.scalingDocs.limitUseCase.multipleJoins",defaultMessage:"Spatial joins"})),Object(C.jsx)("li",null,Object(C.jsx)(S.FormattedMessage,{id:"xpack.maps.scalingDocs.limitUseCase.spatialJoins",defaultMessage:"Multiple term joins"})),Object(C.jsx)("li",null,Object(C.jsx)(S.FormattedMessage,{id:"xpack.maps.scalingDocs.limitUseCase.joinFieldsWithLayoutStyles",defaultMessage:"Data driven styling from join metrics with 'Label', 'Label size', icon 'Symbol size', and 'Symbol orientation' style properties"})),Object(C.jsx)("li",null,Object(C.jsx)(S.FormattedMessage,{id:"xpack.maps.scalingDocs.limitUseCase.scriptedFields",defaultMessage:"Data driven styling from scripted fields"}))))),Object(C.jsx)("p",{style:{fontStyle:"italic"}},Object(C.jsx)(S.FormattedMessage,{id:"xpack.maps.scalingDocs.maxResultWindow",defaultMessage:"{maxResultWindow} constraint provided by {link} index setting.",values:{maxResultWindow:e.maxResultWindow,link:Object(C.jsx)(j.EuiLink,{href:Object(x.k)().links.elasticsearch.dynamicIndexSettings,target:"_blank",external:!0},"max_result_window")}})))))}class scaling_form_ScalingForm extends l.Component{constructor(...e){super(...e),o()(this,"state",{maxResultWindow:i.u.toLocaleString(),modalContent:null,showModal:!1}),o()(this,"_isMounted",!1),o()(this,"_onScalingTypeSelect",(e=>{if(this.props.numberOfJoins>0&&e===i.vb.CLUSTERS)this._openModal(e,[d.i18n.translate("xpack.maps.source.esSearch.clusterScalingJoinMsg",{defaultMessage:"Scaling with clusters does not support joins. Switching to clusters will remove all joins from your layer configuration."})]);else{if(e===i.vb.MVT){const t=[];if(this.props.hasSpatialJoins&&t.push(d.i18n.translate("xpack.maps.source.esSearch.mvtNoSpatialJoinMsg",{defaultMessage:"Vector tiles do not support spatial joins. Switching to vector tiles will remove all spatial joins from your layer configuration."})),this.props.numberOfJoins>1&&t.push(d.i18n.translate("xpack.maps.source.esSearch.mvtScalingJoinMsg",{defaultMessage:"Vector tiles support one term join. Your layer has {numberOfJoins} joins. Switching to vector tiles will keep the first term join and remove all other joins from your layer configuration.",values:{numberOfJoins:this.props.numberOfJoins}})),t.length)return void this._openModal(e,t)}this._onScalingTypeChange(e)}})),o()(this,"_onScalingTypeChange",(e=>{let t;t=e===i.vb.CLUSTERS?i.Z.BLENDED_VECTOR:e===i.vb.MVT?i.Z.MVT_VECTOR:i.Z.GEOJSON_VECTOR,this.props.onChange({propName:"scalingType",value:e,newLayerType:t})})),o()(this,"_onFilterByMapBoundsChange",(e=>{this.props.onChange({propName:"filterByMapBounds",value:e.target.checked})})),o()(this,"_openModal",((e,t)=>{this.setState({modalContent:t.length?t.map(((e,t)=>Object(C.jsx)("p",{key:t},e))):null,nextScalingType:e,showModal:!0})})),o()(this,"_closeModal",(()=>{this.setState({modalContent:null,nextScalingType:void 0,showModal:!1})})),o()(this,"_acceptModal",(()=>{this.state.nextScalingType&&this._onScalingTypeChange(this.state.nextScalingType),this._closeModal()}))}componentDidMount(){this._isMounted=!0,this.loadIndexSettings()}componentWillUnmount(){this._isMounted=!1}async loadIndexSettings(){try{const e=await Object(x.u)().get(this.props.indexPatternId),{maxResultWindow:t}=await w(e.getIndexPattern());this._isMounted&&this.setState({maxResultWindow:t.toLocaleString()})}catch(e){return}}_getLimitOptionLabel(){return d.i18n.translate("xpack.maps.source.esSearch.limitScalingLabel",{defaultMessage:"Limit results to {maxResultWindow}",values:{maxResultWindow:this.state.maxResultWindow}})}_getClustersOptionLabel(){return d.i18n.translate("xpack.maps.source.esSearch.clusterScalingLabel",{defaultMessage:"Show clusters when results exceed {maxResultWindow}",values:{maxResultWindow:this.state.maxResultWindow}})}_getMvtOptionLabel(){return d.i18n.translate("xpack.maps.source.esSearch.useMVTVectorTiles",{defaultMessage:"Use vector tiles"})}_renderModal(){return this.state.showModal&&this.state.modalContent&&void 0!==this.state.nextScalingType?Object(C.jsx)(j.EuiConfirmModal,{title:d.i18n.translate("xpack.maps.source.esSearch.scalingModal.title",{defaultMessage:"Remove unsupported configurations?"}),onCancel:this._closeModal,onConfirm:this._acceptModal,cancelButtonText:d.i18n.translate("xpack.maps.source.esSearch.scalingModal.cancelBtnLabel",{defaultMessage:"Cancel"}),confirmButtonText:d.i18n.translate("xpack.maps.source.esSearch.scalingModal.confirmBtnLabel",{defaultMessage:"Accept"}),buttonColor:"danger",defaultFocusedButton:"cancel"},this.state.modalContent):null}_renderClusteringRadio(){const e=Object(C.jsx)(j.EuiRadio,{id:i.vb.CLUSTERS,label:this._getClustersOptionLabel(),checked:this.props.scalingType===i.vb.CLUSTERS,onChange:()=>this._onScalingTypeSelect(i.vb.CLUSTERS),disabled:!this.props.supportsClustering});return this.props.clusteringDisabledReason?Object(C.jsx)(j.EuiToolTip,{position:"left",content:this.props.clusteringDisabledReason},e):e}render(){let e;return this.props.scalingType===i.vb.LIMIT&&(e=Object(C.jsx)(j.EuiFormRow,null,Object(C.jsx)(j.EuiSwitch,{label:d.i18n.translate("xpack.maps.source.esSearch.extentFilterLabel",{defaultMessage:"Dynamically filter for data in the visible map area"}),checked:this.props.filterByMapBounds,onChange:this._onFilterByMapBoundsChange,compressed:!0}))),Object(C.jsx)(l.Fragment,null,this._renderModal(),Object(C.jsx)(j.EuiTitle,{size:"xs"},Object(C.jsx)("h5",null,Object(C.jsx)(S.FormattedMessage,{id:"xpack.maps.esSearch.scaleTitle",defaultMessage:"Scaling"})," ",Object(C.jsx)(E,{limitOptionLabel:this._getLimitOptionLabel(),clustersOptionLabel:this._getClustersOptionLabel(),maxResultWindow:this.state.maxResultWindow,mvtOptionLabel:this._getMvtOptionLabel()}))),Object(C.jsx)(j.EuiSpacer,{size:"m"}),Object(C.jsx)(j.EuiFormRow,null,Object(C.jsx)("div",null,Object(C.jsx)(j.EuiRadio,{id:i.vb.MVT,label:this._getMvtOptionLabel(),checked:this.props.scalingType===i.vb.MVT,onChange:()=>this._onScalingTypeSelect(i.vb.MVT)}),this._renderClusteringRadio(),Object(C.jsx)(j.EuiRadio,{id:i.vb.LIMIT,label:this._getLimitOptionLabel(),checked:this.props.scalingType===i.vb.LIMIT,onChange:()=>this._onScalingTypeSelect(i.vb.LIMIT)}))),e)}}class update_source_editor_UpdateSourceEditor extends l.Component{constructor(...e){super(...e),o()(this,"_isMounted",!1),o()(this,"state",{sourceFields:null,sortFields:void 0,supportsClustering:!1,clusteringDisabledReason:null}),o()(this,"_onTooltipPropertiesChange",(e=>{this.props.onChange({propName:"tooltipProperties",value:e})})),o()(this,"_onSortFieldChange",(e=>{this.props.onChange({propName:"sortField",value:e})})),o()(this,"_onSortOrderChange",(e=>{this.props.onChange({propName:"sortOrder",value:e.target.value})}))}componentDidMount(){this._isMounted=!0,this.loadFields()}componentWillUnmount(){this._isMounted=!1}async loadFields(){let e,t;try{e=await Object(x.u)().get(this.props.indexPatternId)}catch(e){return void(this._isMounted&&this.setState({loadError:Object(f.c)(this.props.indexPatternId)}))}try{t=await this.props.getGeoField()}catch(e){return void(this._isMounted&&this.setState({loadError:e.message}))}if(!this._isMounted)return;const s=Object(O.h)(e.fields).map((e=>new T.a({fieldName:e.name,source:this.props.source,origin:i.D.SOURCE})));this.setState({supportsClustering:Object(O.j)(t),clusteringDisabledReason:Object(O.d)(t),sourceFields:s,sortFields:e.fields.filter((e=>e.sortable&&!_.indexPatterns.isNestedField(e)))})}_renderTooltipsPanel(){return Object(C.jsx)(j.EuiPanel,null,Object(C.jsx)(j.EuiTitle,{size:"xs"},Object(C.jsx)("h5",null,Object(C.jsx)(S.FormattedMessage,{id:"xpack.maps.esSearch.tooltipsTitle",defaultMessage:"Tooltip fields"}))),Object(C.jsx)(j.EuiSpacer,{size:"m"}),Object(C.jsx)(F.a,{tooltipFields:this.props.tooltipFields,onChange:this._onTooltipPropertiesChange,fields:this.state.sourceFields}))}_renderSortPanel(){return Object(C.jsx)(j.EuiPanel,null,Object(C.jsx)(j.EuiTitle,{size:"xs"},Object(C.jsx)("h5",null,Object(C.jsx)(S.FormattedMessage,{id:"xpack.maps.esSearch.sortTitle",defaultMessage:"Sorting"}))),Object(C.jsx)(j.EuiSpacer,{size:"m"}),Object(C.jsx)(j.EuiFormRow,{label:d.i18n.translate("xpack.maps.source.esSearch.sortFieldLabel",{defaultMessage:"Field"}),display:"columnCompressed"},Object(C.jsx)(y.a,{placeholder:d.i18n.translate("xpack.maps.source.esSearch.sortFieldSelectPlaceholder",{defaultMessage:"Select sort field"}),value:this.props.sortField,onChange:this._onSortFieldChange,fields:this.state.sortFields,compressed:!0})),Object(C.jsx)(j.EuiFormRow,{label:d.i18n.translate("xpack.maps.source.esSearch.sortOrderLabel",{defaultMessage:"Order"}),display:"columnCompressed"},Object(C.jsx)(j.EuiSelect,{disabled:!this.props.sortField,options:[{text:d.i18n.translate("xpack.maps.source.esSearch.ascendingLabel",{defaultMessage:"ascending"}),value:_.SortDirection.asc},{text:d.i18n.translate("xpack.maps.source.esSearch.descendingLabel",{defaultMessage:"descending"}),value:_.SortDirection.desc}],value:this.props.sortOrder,onChange:this._onSortOrderChange,compressed:!0})))}_renderScalingPanel(){return Object(C.jsx)(j.EuiPanel,null,Object(C.jsx)(scaling_form_ScalingForm,{filterByMapBounds:this.props.filterByMapBounds,indexPatternId:this.props.indexPatternId,onChange:this.props.onChange,scalingType:this.props.scalingType,supportsClustering:this.state.supportsClustering,clusteringDisabledReason:this.state.clusteringDisabledReason,hasSpatialJoins:this.props.hasSpatialJoins,numberOfJoins:this.props.numberOfJoins}))}render(){return Object(C.jsx)(l.Fragment,null,this._renderTooltipsPanel(),Object(C.jsx)(j.EuiSpacer,{size:"s"}),this._renderSortPanel(),Object(C.jsx)(j.EuiSpacer,{size:"s"}),this._renderScalingPanel(),Object(C.jsx)(j.EuiSpacer,{size:"s"}))}}var P=s(116),L=s(127),I=s(280);class top_hits_form_TopHitsForm extends l.Component{constructor(...e){super(...e),o()(this,"state",{maxInnerResultWindow:i.t}),o()(this,"_isMounted",!1),o()(this,"_onGroupByTimeseriesChange",(e=>{this.props.onChange({propName:"topHitsGroupByTimeseries",value:e})})),o()(this,"_onTopHitsSplitFieldChange",(e=>{e&&this.props.onChange({propName:"topHitsSplitField",value:e})})),o()(this,"_onTopHitsSizeChange",(e=>{this.props.onChange({propName:"topHitsSize",value:e})})),o()(this,"_onSortFieldChange",(e=>{this.props.onChange({propName:"sortField",value:e})})),o()(this,"_onSortOrderChange",(e=>{this.props.onChange({propName:"sortOrder",value:e.target.value})}))}componentDidMount(){this._isMounted=!0,this.loadIndexSettings()}componentWillUnmount(){this._isMounted=!1}async loadIndexSettings(){try{const e=await Object(x.u)().get(this.props.indexPatternId),{maxInnerResultWindow:t}=await w(e.getIndexPattern());this._isMounted&&this.setState({maxInnerResultWindow:t})}catch(e){return}}render(){return Object(C.jsx)(l.Fragment,null,this.props.isTimeseries&&Object(C.jsx)(j.EuiFormRow,{label:d.i18n.translate("xpack.maps.source.esSearch.topHitsGroupByLabel",{defaultMessage:"Group by"}),display:this.props.isColumnCompressed?"columnCompressed":"row"},Object(C.jsx)(I.a,{groupByTimeseries:this.props.topHitsGroupByTimeseries,onGroupByTimeseriesChange:this._onGroupByTimeseriesChange})),!this.props.topHitsGroupByTimeseries&&Object(C.jsx)(j.EuiFormRow,{label:d.i18n.translate("xpack.maps.source.esSearch.topHitsSplitFieldLabel",{defaultMessage:"Entity"}),display:this.props.isColumnCompressed?"columnCompressed":"row"},Object(C.jsx)(y.a,{placeholder:d.i18n.translate("xpack.maps.source.esSearch.topHitsSplitFieldSelectPlaceholder",{defaultMessage:"Select entity field"}),value:this.props.topHitsSplitField,onChange:this._onTopHitsSplitFieldChange,fields:this.props.termFields,isClearable:!1,compressed:!0})),(this.props.topHitsSplitField||this.props.topHitsGroupByTimeseries)&&Object(C.jsx)(c.a.Fragment,null,Object(C.jsx)(j.EuiFormRow,{label:this.props.topHitsGroupByTimeseries?d.i18n.translate("xpack.maps.source.esSearch.topHitsTimeseriesSizeLabel",{defaultMessage:"Documents per time series"}):d.i18n.translate("xpack.maps.source.esSearch.topHitsSizeLabel",{defaultMessage:"Documents per entity"}),display:this.props.isColumnCompressed?"columnCompressed":"row"},Object(C.jsx)(L.a,{min:1,max:this.state.maxInnerResultWindow,step:1,value:this.props.topHitsSize,onChange:this._onTopHitsSizeChange,showLabels:!0,showInput:!0,showRange:!0,"data-test-subj":"layerPanelTopHitsSize",compressed:!0})),Object(C.jsx)(j.EuiFormRow,{label:d.i18n.translate("xpack.maps.source.esTopHitsSearch.sortFieldLabel",{defaultMessage:"Sort field"}),display:this.props.isColumnCompressed?"columnCompressed":"row"},Object(C.jsx)(y.a,{placeholder:d.i18n.translate("xpack.maps.source.esSearch.sortFieldSelectPlaceholder",{defaultMessage:"Select sort field"}),value:this.props.sortField,onChange:this._onSortFieldChange,fields:this.props.sortFields,compressed:!0})),Object(C.jsx)(j.EuiFormRow,{label:d.i18n.translate("xpack.maps.source.esTopHitsSearch.sortOrderLabel",{defaultMessage:"Sort order"}),display:this.props.isColumnCompressed?"columnCompressed":"row"},Object(C.jsx)(j.EuiSelect,{disabled:!this.props.sortField,options:[{text:d.i18n.translate("xpack.maps.source.esSearch.ascendingLabel",{defaultMessage:"ascending"}),value:_.SortDirection.asc},{text:d.i18n.translate("xpack.maps.source.esSearch.descendingLabel",{defaultMessage:"descending"}),value:_.SortDirection.desc}],value:this.props.sortOrder,onChange:this._onSortOrderChange,compressed:!0}))))}}class update_source_editor_TopHitsUpdateSourceEditor extends l.Component{constructor(...e){super(...e),o()(this,"_isMounted",!1),o()(this,"state",{isLoading:!1,isTimeseries:!1,sourceFields:[],termFields:[],sortFields:[]}),o()(this,"_onTooltipPropertiesChange",(e=>{this.props.onChange({propName:"tooltipProperties",value:e})})),o()(this,"_onFilterByMapBoundsChange",(e=>{this.props.onChange({propName:"filterByMapBounds",value:e.target.checked})}))}componentDidMount(){this._isMounted=!0,this.loadFields()}componentWillUnmount(){this._isMounted=!1}async loadFields(){let e;this.setState({isLoading:!0});try{e=await Object(x.u)().get(this.props.indexPatternId)}catch(e){return void(this._isMounted&&this.setState({isLoading:!1,loadError:Object(f.c)(this.props.indexPatternId)}))}if(!this._isMounted)return;const t=Object(O.h)(e.fields).map((e=>new T.a({fieldName:e.name,source:this.props.source,origin:i.D.SOURCE})));this.setState({isLoading:!1,isTimeseries:Object(O.f)(e),sourceFields:t,termFields:Object(O.i)(e.fields),sortFields:Object(O.g)(e.fields)})}render(){return Object(C.jsx)(l.Fragment,null,Object(C.jsx)(j.EuiPanel,null,Object(C.jsx)(j.EuiTitle,{size:"xs"},Object(C.jsx)("h5",null,Object(C.jsx)(S.FormattedMessage,{id:"xpack.maps.esSearch.tooltipsTitle",defaultMessage:"Tooltip fields"}))),Object(C.jsx)(j.EuiSpacer,{size:"m"}),Object(C.jsx)(j.EuiSkeletonText,{lines:3,size:"s",isLoading:this.state.isLoading},Object(C.jsx)(F.a,{tooltipFields:this.props.tooltipFields,onChange:this._onTooltipPropertiesChange,fields:this.state.sourceFields}))),Object(C.jsx)(j.EuiSpacer,{size:"s"}),Object(C.jsx)(j.EuiPanel,null,Object(C.jsx)(j.EuiTitle,{size:"xs"},Object(C.jsx)("h5",null,Object(C.jsx)(S.FormattedMessage,{id:"xpack.maps.source.topHitsPanelLabel",defaultMessage:"Top hits"}))),Object(C.jsx)(j.EuiSpacer,{size:"m"}),Object(C.jsx)(j.EuiSkeletonText,{lines:3,size:"s",isLoading:this.state.isLoading},Object(C.jsx)(top_hits_form_TopHitsForm,{indexPatternId:this.props.indexPatternId,isColumnCompressed:!0,isTimeseries:this.state.isTimeseries,onChange:this.props.onChange,sortField:this.props.sortField,sortFields:this.state.sortFields,sortOrder:this.props.sortOrder,termFields:this.state.termFields,topHitsGroupByTimeseries:this.props.topHitsGroupByTimeseries,topHitsSplitField:this.props.topHitsSplitField,topHitsSize:this.props.topHitsSize})),Object(C.jsx)(j.EuiFormRow,null,Object(C.jsx)(j.EuiSwitch,{label:d.i18n.translate("xpack.maps.source.esSearch.extentFilterLabel",{defaultMessage:"Dynamically filter for data in the visible map area"}),checked:this.props.filterByMapBounds,onChange:this._onFilterByMapBoundsChange,compressed:!0}))),Object(C.jsx)(j.EuiSpacer,{size:"s"}))}}var k=s(148),N=s(101);class create_source_editor_CreateSourceEditor extends l.Component{constructor(...e){super(...e),o()(this,"state",{indexPattern:null,isTimeseries:!1,geoFields:[],geoFieldName:null,sortField:null,sortFields:[],sortOrder:_.SortDirection.desc,termFields:[],topHitsGroupByTimeseries:!1,topHitsSplitField:null,topHitsSize:1}),o()(this,"_onIndexPatternSelect",(e=>{const t=Object(O.b)(e.fields),s=Object(O.f)(e);this.setState({indexPattern:e,isTimeseries:s,geoFields:t,geoFieldName:t.length?t[0].name:null,sortField:e.timeFieldName?e.timeFieldName:null,sortFields:Object(O.g)(e.fields),termFields:Object(O.i)(e.fields),topHitsGroupByTimeseries:s,topHitsSplitField:null},this._previewLayer)})),o()(this,"_onGeoFieldSelect",(e=>{this.setState({geoFieldName:e||null},this._previewLayer)})),o()(this,"_onTopHitsPropChange",(({propName:e,value:t})=>{this.setState({[e]:t},this._previewLayer)})),o()(this,"_previewLayer",(()=>{const{indexPattern:e,geoFieldName:t,sortField:s,sortOrder:a,topHitsGroupByTimeseries:o,topHitsSplitField:r,topHitsSize:n}=this.state,l=[];if(o){var c;const t=(null!==(c=null==e?void 0:e.fields)&&void 0!==c?c:[]).filter((e=>e.timeSeriesDimension)).map((e=>e.name));l.push(...t)}else r&&l.push(r);e&&e.timeFieldName&&l.push(e.timeFieldName);const d=t&&(null==e?void 0:e.getFieldByName(t)),p=e&&t&&s&&(o||r)?{indexPatternId:e.id,geoField:t,scalingType:i.vb.TOP_HITS,sortField:s,sortOrder:a,tooltipProperties:l,topHitsGroupByTimeseries:o,topHitsSplitField:r||void 0,topHitsSize:n}:null,u=!!d&&"geo_point"===d.type;this.props.onSourceConfigChange(p,u)}))}_renderGeoSelect(){return this.state.indexPattern?Object(C.jsx)(k.a,{value:this.state.geoFieldName?this.state.geoFieldName:"",onChange:this._onGeoFieldSelect,geoFields:this.state.geoFields}):null}_renderTopHitsPanel(){return this.state.indexPattern&&this.state.indexPattern.id&&this.state.geoFieldName?Object(C.jsx)(top_hits_form_TopHitsForm,{indexPatternId:this.state.indexPattern.id,isColumnCompressed:!1,isTimeseries:this.state.isTimeseries,onChange:this._onTopHitsPropChange,sortField:this.state.sortField?this.state.sortField:"",sortFields:this.state.sortFields,sortOrder:this.state.sortOrder,termFields:this.state.termFields,topHitsGroupByTimeseries:this.state.topHitsGroupByTimeseries,topHitsSplitField:this.state.topHitsSplitField,topHitsSize:this.state.topHitsSize}):null}render(){return Object(C.jsx)(j.EuiPanel,null,Object(C.jsx)(N.a,{dataView:this.state.indexPattern,onChange:this._onIndexPatternSelect}),this._renderGeoSelect(),this._renderTopHitsPanel())}}var H=s(72);const D={id:i.Hb.ES_TOP_HITS,order:10,categories:[i.ab.ELASTICSEARCH],description:d.i18n.translate("xpack.maps.source.topHitsDescription",{defaultMessage:"Display the most relevant documents per entity, e.g. the most recent GPS hits per vehicle."}),icon:()=>Object(C.jsx)("svg",{xmlns:"http://www.w3.org/2000/svg",width:"49",height:"25",fill:"none",viewBox:"0 0 49 25"},Object(C.jsx)("circle",{cx:"24.939",cy:"12.409",r:"2.182",className:"mapLayersWizardIcon__highlight"}),Object(C.jsx)("circle",{cx:"35.849",cy:"12.409",r:"2.182",className:"mapLayersWizardIcon__highlight"}),Object(C.jsx)("circle",{cx:"45.561",cy:"12.409",r:"3.273",className:"mapLayersWizardIcon__highlight"}),Object(C.jsx)("circle",{cx:"5.197",cy:"18.954",r:"2.182",className:"mapLayersWizardIcon__highlight"}),Object(C.jsx)("circle",{cx:"13.485",cy:"12.409",r:"2.182",className:"mapLayersWizardIcon__highlight"})),renderWizard:({previewLayers:e,mapColors:t})=>Object(C.jsx)(create_source_editor_CreateSourceEditor,{onSourceConfigChange:(s,a)=>{if(!s)return void e([]);const o=es_search_source_ESSearchSource.createDescriptor(s),r=H.b.createDescriptor({sourceDescriptor:o},t);a&&(r.style.properties[i.Gb.LINE_WIDTH]={type:i.Cb.STATIC,options:{size:0}}),e([r])}}),title:d.i18n.translate("xpack.maps.source.topHitsTitle",{defaultMessage:"Top hits per entity"})};function R(e,t,s){const i=[],a=[],o={};return t.forEach((t=>{const r=Object(b.l)(e,t);if(r.scripted)o[r.name]={script:{source:r.script||"",lang:r.lang||""}};else if(r.readFromDocValues||r.runtimeField){const e="date"===r.type?{field:t,format:s}:t;i.push(e)}else a.push(t)})),{docValueFields:i,sourceOnlyFields:a,scriptFields:o}}var B=s(58),z=s(117),G=s(232);function W(e){const t=Object(x.P)().calculateBounds(e);return void 0!==t.min&&void 0!==t.max?{from:t.min.valueOf(),to:t.max.valueOf()}:void 0}const A=d.i18n.translate("xpack.maps.source.esSearchTitle",{defaultMessage:"Documents"});class es_search_source_ESSearchSource extends m.a{static createDescriptor(e){const t=m.a.createDescriptor(e);if(!Object(P.a)(t.geoField))throw new Error("Cannot create an ESSearchSourceDescriptor without a geoField");return{...t,type:i.Ab.ES_SEARCH,geoField:t.geoField,filterByMapBounds:"boolean"!=typeof e.filterByMapBounds||e.filterByMapBounds,tooltipProperties:Array.isArray(e.tooltipProperties)?e.tooltipProperties:[],sortField:Object(P.a)(e.sortField)?e.sortField:"",sortOrder:Object(P.a)(e.sortOrder)?e.sortOrder:h.SortDirection.desc,scalingType:Object(P.a)(e.scalingType)?e.scalingType:i.vb.MVT,topHitsGroupByTimeseries:"boolean"==typeof t.topHitsGroupByTimeseries&&t.topHitsGroupByTimeseries,topHitsSplitField:Object(P.a)(e.topHitsSplitField)?e.topHitsSplitField:"",topHitsSize:"number"==typeof e.topHitsSize&&e.topHitsSize>0?e.topHitsSize:1}}constructor(e){const t=es_search_source_ESSearchSource.createDescriptor(e);super(t),o()(this,"_descriptor",void 0),o()(this,"_tooltipFields",void 0),this._descriptor=t,this._tooltipFields=this._descriptor.tooltipProperties?this._descriptor.tooltipProperties.map((e=>this.createField({fieldName:e}))):[]}createField({fieldName:e}){return new T.a({fieldName:e,source:this,origin:i.D.SOURCE})}renderSourceSettingsEditor(e){return this._isTopHits()?Object(C.jsx)(update_source_editor_TopHitsUpdateSourceEditor,{source:this,indexPatternId:this.getIndexPatternId(),onChange:e.onChange,tooltipFields:this._tooltipFields,sortField:this._descriptor.sortField,sortOrder:this._descriptor.sortOrder,filterByMapBounds:this.isFilterByMapBounds(),topHitsGroupByTimeseries:this._descriptor.topHitsGroupByTimeseries,topHitsSplitField:this._descriptor.topHitsSplitField,topHitsSize:this._descriptor.topHitsSize}):Object(C.jsx)(update_source_editor_UpdateSourceEditor,{source:this,indexPatternId:this.getIndexPatternId(),getGeoField:()=>this._getGeoField(),onChange:e.onChange,tooltipFields:this._tooltipFields,sortField:this._descriptor.sortField,sortOrder:this._descriptor.sortOrder,scalingType:this._descriptor.scalingType,filterByMapBounds:this.isFilterByMapBounds(),numberOfJoins:e.numberOfJoins,hasSpatialJoins:e.hasSpatialJoins})}async getFields(){try{return(await this.getIndexPattern()).fields.filter((e=>e.aggregatable)).map((e=>this.createField({fieldName:e.name})))}catch(e){return[]}}isMvt(){return this._descriptor.scalingType===i.vb.MVT}async getImmutableProperties(){let e="";try{e=(await this._getGeoField()).type}catch(e){}return[{label:Object(f.a)(),value:A},{label:Object(f.b)(),value:await this.getDisplayName()},{label:d.i18n.translate("xpack.maps.source.esSearch.geoFieldLabel",{defaultMessage:"Geospatial field"}),value:this._descriptor.geoField},{label:d.i18n.translate("xpack.maps.source.esSearch.geoFieldTypeLabel",{defaultMessage:"Geospatial field type"}),value:e}]}_buildEsSort(){const{sortField:e,sortOrder:t}=this._descriptor;if(!e)throw new Error("Cannot build sort");return[{[e]:{order:t}}]}async _getTopHits(e,t,s,a){const{topHitsGroupByTimeseries:o,topHitsSplitField:r,topHitsSize:l}=this._descriptor;if(!o&&!r)throw new Error("Cannot _getTopHits without topHitsSplitField");const c=await this.getIndexPattern(),{docValueFields:u,sourceOnlyFields:h,scriptFields:g}=R(c,t.fieldNames,"epoch_millis"),m={size:l,script_fields:g,docvalue_fields:u,fields:[this._descriptor.geoField]};this._hasSort()&&(m.sort=this._buildEsSort()),0===h.length?m._source=!1:m._source={includes:h};const x={precision_threshold:1},j={size:i.s,shard_size:i.s},_=await this.makeSearchSource(t,0);if(_.setField("trackTotalHits",!1),o)_.setField("aggs",{totalEntities:{cardinality:{...x,field:"_tsid"}},entitySplit:{terms:{...j,field:"_tsid"},aggs:{entityHits:{top_hits:m}}}});else{const e=Object(b.l)(c,r);if(_.setField("aggs",{totalEntities:{cardinality:Object(b.a)(x,e)},entitySplit:{terms:Object(b.a)(j,e),aggs:{entityHits:{top_hits:m}}}}),"string"===e.type){const t=Object(p.buildPhraseFilter)(e,"",c);t.meta.negate=!0,_.setField("filter",[..._.getField("filter"),t])}}const S=await this._runEsQuery({requestId:this.getId(),requestName:d.i18n.translate("xpack.maps.esSearchSource.topHits.requestName",{defaultMessage:"{layerName} top hits request",values:{layerName:e}}),searchSource:_,registerCancelCallback:s,requestDescription:d.i18n.translate("xpack.maps.esSearchSource.topHits.requestDescription",{defaultMessage:"Get top hits from data view: {dataViewName}, entities: {entitiesFieldName}, geospatial field: {geoFieldName}",values:{dataViewName:c.getName(),entitiesFieldName:o?"_tsid":r,geoFieldName:this._descriptor.geoField}}),searchSessionId:t.searchSessionId,executionContext:Object(z.b)({description:"es_search_source:top_hits"},t.executionContext),requestsAdapter:a.requests}),f=[],y=n.a.get(S,"aggregations.entitySplit.buckets",[]),F=n.a.get(S,"aggregations.totalEntities.value",0),O=y.length>=i.s;let T=!1;return y.forEach((e=>{const t=n.a.get(e,"entityHits.hits.hits",[]);f.push(...t.reverse()),Object(b.n)(e.entityHits.hits.total,t.length)&&(T=!0)})),{hits:f,meta:{areResultsTrimmed:O||T,areEntitiesTrimmed:O,entityCount:y.length,totalEntities:F}}}async _getSearchHits(e,t,s,i){const a=await this.getIndexPattern(),{docValueFields:o,sourceOnlyFields:r}=R(a,t.fieldNames,"epoch_millis"),n={docvalue_fields:o},l={...t};delete l.timeslice;const c=void 0!==t.timeslice&&await this.canLoadAllDocuments(l,s),p=await this.getMaxResultWindow(),u=await this.makeSearchSource(c?l:t,p,n);u.setField("trackTotalHits",p+1),u.setField("fieldsFromSource",t.fieldNames),0===r.length?u.setField("source",!1):u.setField("source",r),u.setField("fields",[this._descriptor.geoField]),this._hasSort()&&u.setField("sort",this._buildEsSort());const h=await this._runEsQuery({requestId:this.getId(),requestName:d.i18n.translate("xpack.maps.esSearchSource.requestName",{defaultMessage:"{layerName} documents request",values:{layerName:e}}),searchSource:u,registerCancelCallback:s,requestDescription:d.i18n.translate("xpack.maps.esSearchSource.requestDescription",{defaultMessage:"Get documents from data view: {dataViewName}, geospatial field: {geoFieldName}",values:{dataViewName:a.getName(),geoFieldName:this._descriptor.geoField}}),searchSessionId:t.searchSessionId,executionContext:Object(z.b)({description:"es_search_source:doc_search"},t.executionContext),requestsAdapter:i.requests}),g=void 0!==t.timeslice&&!c;return{hits:h.hits.hits.reverse(),meta:{resultsCount:h.hits.hits.length,areResultsTrimmed:Object(b.n)(h.hits.total,h.hits.hits.length),timeExtent:g?t.timeslice:W(t.timeFilters),isTimeExtentForTimeslice:g}}}_isTopHits(){return this._descriptor.scalingType===i.vb.TOP_HITS}async _getSourceIndexList(){const e=await this.getIndexPattern();try{const{success:t,matchingIndexes:s}=await(async e=>await Object(x.r)().fetch({path:i.K,method:"GET",version:"1",query:{indexPattern:e}}))(e.getIndexPattern());return t?s:[]}catch(e){return[]}}async supportsFeatureEditing(){return 1===(await this._getSourceIndexList()).length}async _getNewFeatureFields(){var e;if(!await this._isDrawingIndex())return{};const t=await(null===(e=Object(x.J)())||void 0===e?void 0:e.authc.getCurrentUser()),s=(new Date).toISOString();return{created:{...t?{user:t.username}:{},"@timestamp":s}}}async _isDrawingIndex(){const e=await this.getIndexPattern(),{success:t,isDrawingIndex:s}=await(async e=>await Object(x.r)().fetch({path:i.i,method:"GET",version:"1",query:{index:e}}))(e.getIndexPattern());return t&&s}_hasSort(){const{sortField:e,sortOrder:t}=this._descriptor;return!!e&&!!t}async getMaxResultWindow(){const e=await this.getIndexPattern();return(await w(e.getIndexPattern())).maxResultWindow}isFieldAware(){return!0}async getGeoJsonWithMeta(e,t,s,i,a){const o=await this.getIndexPattern(),{hits:r,meta:n}=this._isTopHits()?await this._getTopHits(e,t,s,a):await this._getSearchHits(e,t,s,a),l=o.metaFields.filter((e=>!["_id","_index"].includes(e))),c=e=>{const t=o.flattenHit(e);return l.forEach((e=>{delete t[e]})),t},p=t.fieldNames.filter((e=>{const t=Object(b.l)(o,e);return t.readFromDocValues&&"date"===t.type}));let u;try{const e=await this._getGeoField();u=Object(b.m)(r,c,e.name,e.type,p)}catch(e){throw new Error(d.i18n.translate("xpack.maps.source.esSearch.convertToGeoJsonErrorMsg",{defaultMessage:"Unable to convert search response to geoJson feature collection, error: {errorMsg}",values:{errorMsg:e.message}}))}return{data:u,meta:n}}hasTooltipProperties(){return this._tooltipFields.length>0}async _loadTooltipProperties(e,t,s,i){if(0===this._tooltipFields.length)return{};const a=Object(x.I)(),o=await a.searchSource.create();o.setField("trackTotalHits",!1),o.setField("index",s),o.setField("size",1);const r={language:"kuery",query:`_id:"${e}" and _index:"${t}"`};o.setField("query",r),o.setField("fieldsFromSource",["_id"]),o.setField("source",!1),o.setField("fields",this._getTooltipPropertyNames().map((e=>{const t=s.fields.getByName(e);return t&&"date"===t.type?{field:e,format:"strict_date_optional_time"}:e})));const{rawResponse:l}=await Object(u.lastValueFrom)(o.fetch$({legacyHitsTotal:!1,executionContext:Object(z.b)({description:"es_search_source:load_tooltip_properties"},i)})),c=n.a.get(l,"hits.hits[0]");if(!c)throw new Error(d.i18n.translate("xpack.maps.source.esSearch.loadTooltipPropertiesErrorMsg",{defaultMessage:"Unable to find document, _id: {docId}",values:{docId:e}}));const p=s.flattenHit(c);return s.metaFields.forEach((e=>{this._getTooltipPropertyNames().includes(e)||delete p[e]})),p}_getTooltipPropertyNames(){return this._tooltipFields.map((e=>e.getName()))}async getTooltipProperties(e,t){if(null===e)throw new Error("properties cannot be null");const s=await this.getIndexPattern(),i=await this._loadTooltipProperties(e._id,e._index,s,t),a=this._tooltipFields.map((e=>{const t=i[e.getName()];return e.createTooltipProperty(t)}));return Promise.all(a)}isFilterByMapBounds(){return this._descriptor.scalingType===i.vb.CLUSTERS||this._descriptor.scalingType!==i.vb.MVT&&!!this._descriptor.filterByMapBounds}async getLeftJoinFields(){const e=await this.getIndexPattern();return Object(O.h)(e.fields).map((e=>this.createField({fieldName:e.name})))}async getSupportedShapeTypes(){let e;try{e=(await this._getGeoField()).type}catch(e){}return e===i.A.GEO_POINT?[i.Fb.POINT]:[i.Fb.POINT,i.Fb.LINE,i.Fb.POLYGON]}getSourceStatus(e){var t;const s=e?e.getMeta():null;return s?this._isTopHits()?{tooltipContent:`${s.areEntitiesTrimmed?d.i18n.translate("xpack.maps.esSearch.topHitsResultsTrimmedMsg",{defaultMessage:"Results limited to first {entityCount} entities of ~{totalEntities}.",values:{entityCount:null===(i=s.entityCount)||void 0===i?void 0:i.toLocaleString(),totalEntities:null===(a=s.totalEntities)||void 0===a?void 0:a.toLocaleString()}}):d.i18n.translate("xpack.maps.esSearch.topHitsEntitiesCountMsg",{defaultMessage:"Found {entityCount} entities.",values:{entityCount:null===(o=s.entityCount)||void 0===o?void 0:o.toLocaleString()}})} ${d.i18n.translate("xpack.maps.esSearch.topHitsSizeMsg",{defaultMessage:"Showing top {topHitsSize} documents per entity.",values:{topHitsSize:null===(r=this._descriptor.topHitsSize)||void 0===r?void 0:r.toLocaleString()}})}`,areResultsTrimmed:!!s.areEntitiesTrimmed}:s.areResultsTrimmed?{tooltipContent:d.i18n.translate("xpack.maps.esSearch.resultsTrimmedMsg",{defaultMessage:"Results limited to first {count} documents.",values:{count:null===(n=s.resultsCount)||void 0===n?void 0:n.toLocaleString()}}),areResultsTrimmed:!0}:{tooltipContent:d.i18n.translate("xpack.maps.esSearch.featureCountMsg",{defaultMessage:"Found {count} documents.",values:{count:null===(t=s.resultsCount)||void 0===t?void 0:t.toLocaleString()}}),areResultsTrimmed:!1}:{tooltipContent:null,areResultsTrimmed:!1};var i,a,o,r,n}getSyncMeta(){return{geoField:this._descriptor.geoField,filterByMapBounds:this._descriptor.filterByMapBounds,sortField:this._descriptor.sortField,sortOrder:this._descriptor.sortOrder,scalingType:this._descriptor.scalingType,topHitsGroupByTimeseries:this._descriptor.topHitsGroupByTimeseries,topHitsSplitField:this._descriptor.topHitsSplitField,topHitsSize:this._descriptor.topHitsSize}}async _getPreIndexedShape(e){if(null===e)return null;const t=await this._getGeoField();return{index:e._index,id:e._id,path:t.name}}supportsJoins(){return this._descriptor.scalingType!==i.vb.CLUSTERS}async _getEditableIndex(){const e=await this._getSourceIndexList();if(0===e.length)throw new Error(d.i18n.translate("xpack.maps.source.esSearch.indexZeroLengthEditError",{defaultMessage:"Your data view doesn't point to any indices."}));if(e.length>1)throw new Error(d.i18n.translate("xpack.maps.source.esSearch.indexOverOneLengthEditError",{defaultMessage:"Your data view points to multiple indices. Only one index is allowed per data view."}));return e[0]}async addFeature(e){const t=await this._getEditableIndex();await(async(e,t,s,a)=>{const o=Object(B.set)({...a},s,t);return await Object(x.r)().fetch({path:`${i.O}`,method:"POST",version:"1",body:JSON.stringify({index:e,data:o})})})(t,e,this.getGeoFieldName(),await this._getNewFeatureFields())}async deleteFeature(e){const t=await this._getEditableIndex();await(async(e,t)=>await Object(x.r)().fetch({path:`${i.O}/${t}`,method:"DELETE",version:"1",body:JSON.stringify({index:e})}))(t,e)}getTileSourceLayer(){return"hits"}async getTileUrl(e,t,s,a){const o=await this.getIndexPattern(),r=await w(o.getIndexPattern()),l=await this.makeSearchSource(e,r.maxResultWindow);return l.setField("fieldsFromSource",["_id"]),l.setField("source",!1),this._hasSort()&&l.setField("sort",this._buildEsSort()),l.setField("fields",e.fieldNames.map((e=>{const t=o.fields.getByName(e);return t&&"date"===t.type?{field:e,format:"epoch_millis"}:e}))),`${Object(x.r)().basePath.prepend(`${i.ob}/{z}/{x}/{y}.pbf`)}?${Object(g.a)({geometryFieldName:this._descriptor.geoField,index:o.getIndexPattern(),hasLabels:s,buffer:a,requestBody:n.a.pick(l.getSearchRequestBody(),["fields","query","runtime_mappings","size","sort"]),token:t,executionContextId:Object(z.a)(e.executionContext)})}`}async getTimesliceMaskFieldName(){if(this._isTopHits()||this._descriptor.scalingType===i.vb.MVT)return null;try{const e=await this.getIndexPattern();return e.timeFieldName?e.timeFieldName:null}catch(e){return null}}getUpdateDueToTimeslice(e,t){if(this._isTopHits()||this._descriptor.scalingType===i.vb.MVT)return!0;if(void 0===e.timeExtent||void 0===e.areResultsTrimmed||e.areResultsTrimmed)return!0;const s=void 0!==e.isTimeExtentForTimeslice&&e.isTimeExtentForTimeslice;return t?!(!s||t.from>=e.timeExtent.from&&t.to<=e.timeExtent.to):!!s}async canLoadAllDocuments(e,t){const s=new AbortController;t((()=>s.abort()));const i=await this.getMaxResultWindow(),a=await this.makeSearchSource(e,0);a.setField("trackTotalHits",i+1);const{rawResponse:o}=await Object(u.lastValueFrom)(a.fetch$({abortSignal:s.signal,sessionId:e.searchSessionId,legacyHitsTotal:!1,executionContext:Object(z.b)({description:"es_search_source:all_doc_counts"},e.executionContext)}));return!Object(b.n)(o.hits.total,i)}getFeatureActions({addFilters:e,geoFieldNames:t,getActionContext:s,getFilterActions:a,mbFeature:o,onClose:r}){return 0===t.length||null===e?[]:o.geometry.type===i.J.POLYGON||o.geometry.type===i.J.MULTI_POLYGON?[{label:d.i18n.translate("xpack.maps.tooltip.action.filterByGeometryLabel",{defaultMessage:"Filter by geometry"}),id:"FILTER_BY_PRE_INDEXED_SHAPE_ACTION",form:Object(C.jsx)(G.a,{onClose:r,geoFieldNames:t,addFilters:e,getFilterActions:a,getActionContext:s,loadPreIndexedShape:async()=>this._getPreIndexedShape(o.properties)})}]:[]}}var U=s(19);function V({indexPatternId:e,geoFieldName:t,geoFieldType:s,query:a}){const o=s===i.A.GEO_POINT||s===i.A.GEO_SHAPE&&Object(U.b)()?i.vb.CLUSTERS:i.vb.LIMIT,r=es_search_source_ESSearchSource.createDescriptor({indexPatternId:e,geoField:t,scalingType:o});return H.b.createDescriptor({sourceDescriptor:r,query:a})}const J={indexPattern:void 0,geoFields:void 0,geoFieldName:void 0};class es_search_source_create_source_editor_CreateSourceEditor extends l.Component{constructor(...e){super(...e),o()(this,"state",{...J}),o()(this,"_onIndexPatternSelect",(e=>{const t=Object(O.b)(e.fields);this.setState({...J,indexPattern:e,geoFields:t},(()=>{if(t.length){const e=t.find((e=>e.aggregatable))||t[0];this._onGeoFieldSelect(e.name)}}))})),o()(this,"_onGeoFieldSelect",(e=>{this.setState({geoFieldName:e},this._previewLayer)})),o()(this,"_previewLayer",(()=>{const{indexPattern:e,geoFieldName:t}=this.state,s=t&&(null==e?void 0:e.getFieldByName(t)),a=e&&t?{indexPatternId:e.id,geoField:t,scalingType:i.vb.MVT}:null,o=!!s&&"geo_point"===s.type;this.props.onSourceConfigChange(a,o)}))}_renderGeoSelect(){if(this.state.indexPattern)return Object(C.jsx)(j.EuiFormRow,{label:d.i18n.translate("xpack.maps.source.esSearch.geofieldLabel",{defaultMessage:"Geospatial field"})},Object(C.jsx)(y.a,{placeholder:d.i18n.translate("xpack.maps.source.esSearch.selectLabel",{defaultMessage:"Select geo field"}),value:this.state.geoFieldName?this.state.geoFieldName:null,onChange:this._onGeoFieldSelect,fields:this.state.geoFields}))}render(){return Object(C.jsx)(j.EuiPanel,null,Object(C.jsx)(N.a,{dataView:this.state.indexPattern,onChange:this._onIndexPatternSelect}),this._renderGeoSelect())}}function q(e,t){const s=es_search_source_ESSearchSource.createDescriptor(e);return s.scalingType===i.vb.CLUSTERS?H.a.createDescriptor({sourceDescriptor:s},t):s.scalingType===i.vb.MVT?H.c.createDescriptor({sourceDescriptor:s},t):H.b.createDescriptor({sourceDescriptor:s},t)}const $={id:i.Hb.ES_DOCUMENT,order:10,categories:[i.ab.ELASTICSEARCH],description:d.i18n.translate("xpack.maps.source.esSearchDescription",{defaultMessage:"Points, lines, and polygons from Elasticsearch"}),icon:()=>Object(C.jsx)("svg",{xmlns:"http://www.w3.org/2000/svg",width:"49",height:"25",fill:"none",viewBox:"0 0 49 25",className:"mapLayersWizardIcon"},Object(C.jsx)("path",{className:"mapLayersWizardIcon__background",d:"M30.501 14.511l1.602-12.954-1.388.236c-.744.254-1.768.38-2.703.45-.463.034-.899.055-1.258.07l-.093.005c-.311.014-.57.025-.72.042a1.895 1.895 0 00-.558.167 7.55 7.55 0 00-.47.238l-.057.031c-.356.19-.686.357-1.025.4l-1.307.338v5.864c0 .697.141 2.168 0 3.443l-.205 1.67h8.182zM20.607 3.249c-.657.038-1.248.281-2.06.398l-.703.103c-.583.087-1.16.172-1.692.238-.751.093-1.39.145-1.82.113-.593-.044-1.125.341-1.611.843-.453.467-.925 1.101-1.429 1.777l-.144.193c-1.132 1.517-2.452 3.218-4.22 4.102-.213.107-.346.312-.431.528a3.07 3.07 0 00-.173.78c-.064.586-.046 1.324.007 2.083.072 1.01.211 2.102.32 2.955.055.42.101.784.128 1.05.08.78-.128 1.77-.37 2.653-.088.319-.178.616-.258.882l-.086.285a9.67 9.67 0 00-.12.434 1.518 1.518 0 00-.053.334c0 .28.11.577.283.842a2.3 2.3 0 00.735.708l.067.04h.078c4.133-.069 10.221-.555 10.973-.639a.581.581 0 00.333-.17c.083-.08.158-.181.225-.293.134-.223.263-.524.387-.867.25-.69.495-1.6.721-2.519.161-.654.544-1.41.682-2.011l.784-2.796c.067-.379.199-1.13.272-1.704.147-1.149-.01-2.54.097-4 .107-1.458.172-2.917.147-4.052a10.13 10.13 0 00-.113-1.438 2.469 2.469 0 00-.131-.495c-.052-.128-.276-.357-.276-.357h-.55zM31.538 15.87s-1.17-.652-1.548-.643c-.758.02-1.298-.026-2.353 0H22.15l-2.864 8.915c.2.067 1.938.445 2.242.447.62.005 1.478-.08 2.393-.197.88-.112 1.824-.257 2.679-.389l.112-.017c.888-.136 1.664-.254 2.166-.304.348-.035.996-.025 1.858-.007l.128.002c.827.017 1.818.037 2.868.023 2.199-.028 4.695-.203 6.5-.887 1.42-.538 2.1-.87 2.513-1.339.414-.469.575-1.576.575-1.576s-2.906.867-4.807.784c-.927-.041-1.507.044-2.352-.341-1.428-.652-1.205-2.22-2.429-3.205-.771-.62-2.194-1.267-2.194-1.267z"}),Object(C.jsx)("path",{className:"mapLayersWizardIcon__background",d:"M33.058 1.625S31.012 14.8 31.455 15.023c.787.393 2.012.664 3.137 1.67 1.23 1.1 1.172 2.5 2.318 3.239.835.538 6.525-.704 6.525-.704l.228-7.956s-.173-4.5-.89-5.215c-.715-.716-2.488-1.125-3-2.08-1.114-2.081-3.068-2.352-3.068-2.352h-3.647z"}),Object(C.jsx)("circle",{cx:"14.761",cy:"9.754",r:"1.091",className:"mapLayersWizardIcon__highlight"}),Object(C.jsx)("circle",{cx:"36.63",cy:"10.706",r:"1.091",className:"mapLayersWizardIcon__highlight"}),Object(C.jsx)("circle",{cx:"24.842",cy:"19.181",r:"1.091",className:"mapLayersWizardIcon__highlight"}),Object(C.jsx)("circle",{cx:"39.024",cy:"15.363",r:"1.091",className:"mapLayersWizardIcon__highlight"}),Object(C.jsx)("circle",{cx:"27.569",cy:"6.091",r:"1.091",className:"mapLayersWizardIcon__highlight"}),Object(C.jsx)("circle",{cx:"28.66",cy:"11",r:"1.091",className:"mapLayersWizardIcon__highlight"}),Object(C.jsx)("circle",{cx:"35.206",cy:"4.454",r:"1.091",className:"mapLayersWizardIcon__highlight"}),Object(C.jsx)("circle",{cx:"18.842",cy:"6.091",r:"1.091",className:"mapLayersWizardIcon__highlight"}),Object(C.jsx)("circle",{cx:"10.115",cy:"13.727",r:"1.091",className:"mapLayersWizardIcon__highlight"}),Object(C.jsx)("circle",{cx:"16.66",cy:"14.818",r:"1.091",className:"mapLayersWizardIcon__highlight"}),Object(C.jsx)("circle",{cx:"11.206",cy:"20.272",r:"1.091",className:"mapLayersWizardIcon__highlight"}),Object(C.jsx)("circle",{cx:"17.751",cy:"20.818",r:"1.091",className:"mapLayersWizardIcon__highlight"}),Object(C.jsx)("circle",{cx:"30.842",cy:"20.818",r:"1.091",className:"mapLayersWizardIcon__highlight"})),renderWizard:({previewLayers:e,mapColors:t})=>Object(C.jsx)(es_search_source_create_source_editor_CreateSourceEditor,{onSourceConfigChange:(s,a)=>{if(!s)return void e([]);const o=q(s,t);a&&(o.style.properties[i.Gb.LINE_WIDTH]={type:i.Cb.STATIC,options:{size:0}}),e([o])}}),title:A}},135:function(e,t,s){"use strict";s.d(t,"d",(function(){return a})),s.d(t,"c",(function(){return o})),s.d(t,"a",(function(){return r})),s.d(t,"b",(function(){return n}));var i=s(1);const a=i.i18n.translate("xpack.maps.source.esGeoLine.groupBy.timeseriesLabel",{defaultMessage:"Time series"}),o=i.i18n.translate("xpack.maps.source.esGeoLine.groupBy.termsLabel",{defaultMessage:"Top terms"}),r=i.i18n.translate("xpack.maps.source.esGeoLine.splitFieldLabel",{defaultMessage:"Entity"}),n=i.i18n.translate("xpack.maps.source.esGeoLine.sortFieldLabel",{defaultMessage:"Sort"})},138:function(e,t,s){"use strict";s.d(t,"a",(function(){return tooltip_selector_TooltipSelector}));var i=s(23),a=s.n(i),o=s(2),r=s.n(o),n=s(4),l=s(42),c=s.n(l),d=s(14),p=s(40),u=s(1),h=s(149),g=s(3);function m(e,t){return e.label.localeCompare(t.label)}class add_tooltip_field_popover_AddTooltipFieldPopover extends n.Component{constructor(...e){super(...e),r()(this,"state",{isPopoverOpen:!1,checkedFields:[]}),r()(this,"_togglePopover",(()=>{this.setState((e=>({isPopoverOpen:!e.isPopoverOpen})))})),r()(this,"_closePopover",(()=>{this.setState({isPopoverOpen:!1})})),r()(this,"_onSelect",(e=>{const t=e.filter((e=>"on"===e.checked)).map((e=>e.value));this.setState({checkedFields:t,options:e})})),r()(this,"_onAdd",(()=>{this.props.onAdd(this.state.checkedFields),this.setState({checkedFields:[]}),this._closePopover()}))}static getDerivedStateFromProps(e,t){return e.fields!==t.prevFields||e.selectedFields!==t.prevSelectedFields?{options:(s=e.fields,i=e.selectedFields,s?s.filter((e=>!i.find((t=>e.name===t.name)))).map((e=>({value:e.name,prepend:"type"in e?Object(g.jsx)(h.a,{className:"eui-alignMiddle",type:e.type,fill:"none"}):null,label:e.label}))).sort(m):[]),checkedFields:[],prevFields:e.fields,prevSelectedFields:e.selectedFields}:null;var s,i}_renderAddButton(){return Object(g.jsx)(d.EuiButtonEmpty,{onClick:this._togglePopover,size:"xs",iconType:"plusInCircleFilled",isDisabled:!this.props.fields},Object(g.jsx)(p.FormattedMessage,{id:"xpack.maps.tooltipSelector.togglePopoverLabel",defaultMessage:"Add"}))}_renderContent(){const e=0===this.state.checkedFields.length?u.i18n.translate("xpack.maps.tooltipSelector.addLabelWithoutCount",{defaultMessage:"Add"}):u.i18n.translate("xpack.maps.tooltipSelector.addLabelWithCount",{defaultMessage:"Add {count}",values:{count:this.state.checkedFields.length}});return Object(g.jsx)(n.Fragment,null,Object(g.jsx)(d.EuiSelectable,{searchable:!0,searchProps:{compressed:!0},options:this.state.options,onChange:this._onSelect},((e,t)=>Object(g.jsx)("div",{style:{width:"300px"}},Object(g.jsx)(d.EuiPopoverTitle,{paddingSize:"s"},t),e))),Object(g.jsx)(d.EuiSpacer,{size:"xs"}),Object(g.jsx)(d.EuiPopoverFooter,{paddingSize:"s"},Object(g.jsx)(d.EuiTextAlign,{textAlign:"right"},Object(g.jsx)(d.EuiButton,{fill:!0,isDisabled:0===this.state.checkedFields.length,onClick:this._onAdd,size:"s"},e))))}render(){return Object(g.jsx)(d.EuiPopover,{id:"addTooltipFieldPopover",anchorPosition:"leftCenter",button:this._renderAddButton(),isOpen:this.state.isPopoverOpen,closePopover:this._closePopover,panelPaddingSize:"none",ownFocus:!0},this._renderContent())}}async function x(e){return{label:await e.getLabel(),type:await e.getDataType(),name:e.getName()}}class tooltip_selector_TooltipSelector extends n.Component{constructor(e){super(e),r()(this,"_isMounted",void 0),r()(this,"_previousFields",void 0),r()(this,"_previousSelectedTooltips",void 0),r()(this,"state",{fieldProps:[],selectedFieldProps:[]}),r()(this,"_getPropertyLabel",(e=>{if(!this.state.fieldProps.length)return e;const t=this.state.fieldProps.find((t=>t.name===e));return t?t.label:e})),r()(this,"_onAdd",(e=>{if(this.props.tooltipFields){const t=this._getTooltipFieldNames();this.props.onChange([...t,...e])}else this.props.onChange([...e])})),r()(this,"_removeProperty",(e=>{if(this.props.tooltipFields){const t=this._getTooltipFieldNames();t.splice(e,1),this.props.onChange(t)}else this.props.onChange([])})),r()(this,"_onDragEnd",(({source:e,destination:t})=>{t&&this.props.onChange(((e,t,s)=>{const i=Array.from(e),[a]=i.splice(t,1);return i.splice(s,0,a),i})(this._getTooltipFieldNames(),e.index,t.index))})),this._isMounted=!1,this._previousFields=null,this._previousSelectedTooltips=null}componentDidMount(){this._isMounted=!0,this._loadFieldProps(),this._loadTooltipFieldProps()}componentWillUnmount(){this._isMounted=!1}componentDidUpdate(){this._loadTooltipFieldProps(),this._loadFieldProps()}async _loadTooltipFieldProps(){if(!this.props.tooltipFields||this.props.tooltipFields===this._previousSelectedTooltips)return;this._previousSelectedTooltips=this.props.tooltipFields;const e=this.props.tooltipFields.map(x),t=await Promise.all(e);this._isMounted&&this.setState({selectedFieldProps:t})}async _loadFieldProps(){if(!this.props.fields||this.props.fields===this._previousFields)return;this._previousFields=this.props.fields;const e=this.props.fields.map(x),t=await Promise.all(e);this._isMounted&&this.setState({fieldProps:t})}_getTooltipFieldNames(){return this.props.tooltipFields?this.props.tooltipFields.map((e=>e.getName())):[]}_renderProperties(){return this.state.selectedFieldProps.length?Object(g.jsx)(d.EuiDragDropContext,{onDragEnd:this._onDragEnd},Object(g.jsx)(d.EuiDroppable,{droppableId:"mapLayerTOC",spacing:"none"},((e,t)=>Object(g.jsx)(n.Fragment,null,this.state.selectedFieldProps.map(((e,s)=>Object(g.jsx)(d.EuiDraggable,{spacing:"none",key:e.name,index:s,draggableId:e.name,customDragHandle:!0,disableInteractiveElementBlocking:!0},((i,o)=>Object(g.jsx)("div",{className:c()("mapTooltipSelector__propertyRow",{"mapTooltipSelector__propertyRow-isDragging":o.isDragging,"mapTooltipSelector__propertyRow-isDraggingOver":t.isDraggingOver})},Object(g.jsx)(d.EuiText,{className:"mapTooltipSelector__propertyContent",size:"s"},this._getPropertyLabel(e.name)),Object(g.jsx)("div",{className:"mapTooltipSelector__propertyIcons"},Object(g.jsx)(d.EuiButtonIcon,{iconType:"trash",color:"danger",onClick:this._removeProperty.bind(null,s),title:u.i18n.translate("xpack.maps.tooltipSelector.trashButtonTitle",{defaultMessage:"Remove property"}),"aria-label":u.i18n.translate("xpack.maps.tooltipSelector.trashButtonAriaLabel",{defaultMessage:"Remove property"})}),Object(g.jsx)(d.EuiButtonIcon,a()({className:"mapTooltipSelector__grab",iconType:"grab",color:"text",title:u.i18n.translate("xpack.maps.tooltipSelector.grabButtonTitle",{defaultMessage:"Reorder property"}),"aria-label":u.i18n.translate("xpack.maps.tooltipSelector.grabButtonAriaLabel",{defaultMessage:"Reorder property"})},i.dragHandleProps)))))))))))):Object(g.jsx)(d.EuiText,{size:"s",textAlign:"center"},Object(g.jsx)("p",null,Object(g.jsx)(d.EuiTextColor,{color:"subdued"},Object(g.jsx)(p.FormattedMessage,{id:"xpack.maps.tooltipSelector.emptyState.description",defaultMessage:"Add a tooltip field to create filters from field values."}))))}render(){return Object(g.jsx)("div",null,this._renderProperties(),Object(g.jsx)(d.EuiSpacer,{size:"s"}),Object(g.jsx)(d.EuiTextAlign,{textAlign:"center"},Object(g.jsx)(add_tooltip_field_popover_AddTooltipFieldPopover,{onAdd:this._onAdd,fields:this.state.fieldProps,selectedFields:this.state.selectedFieldProps})))}}},148:function(e,t,s){"use strict";s.d(t,"a",(function(){return c}));var i=s(23),a=s.n(i),o=(s(4),s(1)),r=s(14),n=s(95),l=s(3);function c(e){const{geoFields:t,...s}=e;return Object(l.jsx)(r.EuiFormRow,{label:o.i18n.translate("xpack.maps.source.geofieldLabel",{defaultMessage:"Geospatial field"})},Object(l.jsx)(n.a,a()({placeholder:o.i18n.translate("xpack.maps.source.selectLabel",{defaultMessage:"Select geo field"}),fields:e.geoFields},s)))}},152:function(e,t,s){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var i=s(4);t.default=function(){var e=i.useRef(!1),t=i.useCallback((function(){return e.current}),[]);return i.useEffect((function(){return e.current=!0,function(){e.current=!1}})),t}},280:function(e,t,s){"use strict";s.d(t,"a",(function(){return d})),s(4);var i=s(14),a=s(1),o=s(135),r=s(3);const n="timeseries",l="terms",c=[{id:n,label:o.d},{id:l,label:o.c}];function d({groupByTimeseries:e,onGroupByTimeseriesChange:t}){return Object(r.jsx)(i.EuiButtonGroup,{type:"single",legend:a.i18n.translate("xpack.maps.source.esGeoLine.groupByButtonGroupLegend",{defaultMessage:"Choose group by method"}),options:c,idSelected:e?n:l,onChange:e=>{t(e===n)},isFullWidth:!0,buttonSize:"compressed"})}}}]);