/*! 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([[5],{120:function(t,e,i){"use strict";i.d(e,"a",(function(){return d}));var s=i(39),n=i.n(s);const a={};let o,r,c;const d={getGeoFieldNames(){const t=[];return Object.values(a).forEach((e=>{t.push(...e.getGeoFieldNames())})),n.a.uniq(t)},getLocation:()=>o,getMapPanels:()=>Object.keys(a).map((t=>({...a[t],id:t}))),hasMultipleMaps:()=>Object.keys(a).length>1,register(t,e){a[t]=e},setLocation(t,e,i,s){r&&r!==t||(r=t,c&&clearTimeout(c),c=setTimeout((()=>{r=void 0}),500),o={lat:e,lon:i,zoom:s},Object.keys(a).forEach((n=>{if(n===t)return;const o=a[n];o.getIsMovementSynchronized()&&o.onLocationChange(e,i,s)})))},unregister(t){delete a[t],0===Object.keys(a).length&&(o=void 0)}}},305:function(t,e,i){"use strict";i.r(e),i.d(e,"getControlledBy",(function(){return P})),i.d(e,"MapEmbeddable",(function(){return map_embeddable_MapEmbeddable}));var s=i(2),n=i.n(s),a=i(1),o=i(39),r=i.n(o),c=(i(4),i(71)),d=i(519),l=i.n(d),h=i(8),p=i(25),u=i(14),g=i(43),b=i(20),_=i(24),S=i(48),v=i(76),O=i(73),m=i(77),f=i(114),y=i(70),j=i(0),M=i(5),I=i(297),E=i(170),T=i(81),x=i(285),C=i(215),L=i(295),A=i(120);function F(t){if(0===t.length)return"";if(1===t.length)return t[0];const e=a.i18n.translate("xpack.maps.embeddable.geoFieldsConnector",{defaultMessage:" and "});return 2===t.length?t[0]+e+t[1]:t.slice(0,t.length-1).join(", ")+","+e+t[t.length-1]}var R=i(3);function B(t){if(!t)return!1;const e=Object(M.I)().session.getSearchOptions(t);return!!e&&e.isRestore}function P(t){return`mapEmbeddablePanel${t}`}class map_embeddable_MapEmbeddable extends b.Embeddable{constructor(t,e,i){super(e,{editApp:j.e,editable:t.editable,indexPatterns:[]},i),n()(this,"type",j.fb),n()(this,"deferEmbeddableLoad",!0),n()(this,"_isActive",void 0),n()(this,"_savedMap",void 0),n()(this,"_renderTooltipContent",void 0),n()(this,"_subscriptions",[]),n()(this,"_prevIsRestore",!1),n()(this,"_prevMapExtent",void 0),n()(this,"_prevSyncColors",void 0),n()(this,"_domNode",void 0),n()(this,"_unsubscribeFromStore",void 0),n()(this,"_isInitialized",!1),n()(this,"_controlledBy",void 0),n()(this,"_isSharable",!0),n()(this,"_onRenderComplete$",void 0),n()(this,"setRenderTooltipContent",(t=>{this._renderTooltipContent=t})),n()(this,"setEventHandlers",(t=>{this._savedMap.getStore().dispatch(Object(f.i)(t))})),n()(this,"_getIsMovementSynchronized",(()=>void 0===this.input.isMovementSynchronized||this.input.isMovementSynchronized)),n()(this,"_getIsFilterByMapExtent",(()=>void 0!==this.input.filterByMapExtent&&this.input.filterByMapExtent)),n()(this,"_propogateMapMovement",((t,e,i)=>{this._getIsMovementSynchronized()&&A.a.setLocation(this.input.id,t,e,i)})),n()(this,"onSingleValueTrigger",((t,e,i)=>{const s=Object(M.R)().getAction(t);if(!s)throw new Error("Unable to apply action, could not locate action");const n={...this.getActionContext(),data:{data:Object(C.b)(e,i)}};s.execute(n)})),n()(this,"addFilters",(async(t,e=S.ACTION_GLOBAL_APPLY_FILTER)=>{const i={...this.getActionContext(),filters:t},s=Object(M.R)().getAction(e);if(!s)throw new Error("Unable to apply filter, could not locate action");s.execute(i)})),n()(this,"getFilterActions",(async()=>[...await Object(M.R)().getTriggerCompatibleActions(_.APPLY_FILTER_TRIGGER,{embeddable:this,filters:[]}),...(await Object(M.R)().getTriggerCompatibleActions(b.VALUE_CLICK_TRIGGER,{embeddable:this,data:{data:Object(C.b)("anyfield","anyvalue")}})).filter(C.a)])),n()(this,"getActionContext",(()=>{const t=Object(M.R)().getTrigger(_.APPLY_FILTER_TRIGGER);if(!t)throw new Error("Unable to get context, could not locate trigger");return{embeddable:this,trigger:t}})),n()(this,"_setMapExtentFilter",r.a.debounce((()=>{const t=Object(y.v)(this._savedMap.getStore().getState()),e=A.a.getGeoFieldNames();if(void 0===t||0===e.length)return;this._prevMapExtent=t;const i=Object(v.h)(t,e);i.meta.controlledBy=this._controlledBy,i.meta.alias=a.i18n.translate("xpack.maps.embeddable.boundsFilterLabel",{defaultMessage:"{geoFieldsLabel} within map bounds",values:{geoFieldsLabel:F(e)}});const s={...this.getActionContext(),filters:[i],controlledBy:this._controlledBy},n=Object(M.R)().getAction(S.ACTION_GLOBAL_APPLY_FILTER);if(!n)throw new Error("Unable to apply map extent filter, could not locate action");n.execute(s)}),100)),n()(this,"_mapSyncHandler",((t,e,i)=>{Object(y.y)(this._savedMap.getStore().getState()).autoFitToDataBounds&&this._savedMap.getStore().dispatch(Object(O.lb)({autoFitToDataBounds:!1})),this._savedMap.getStore().dispatch(Object(O.cb)({lat:t,lon:e,zoom:i}))})),this._isActive=!0,this._savedMap=new E.b({mapEmbeddableInput:e}),this._initializeSaveMap(),this._subscriptions.push(this.getUpdated$().subscribe((()=>this.onUpdate()))),this._controlledBy=P(this.id),this._onRenderComplete$=this.getOutput$().pipe(Object(p.startWith)(this.getOutput()),Object(p.distinctUntilChanged)(((t,e)=>t.loading===e.loading)),Object(p.skip)(1),Object(p.debounceTime)(j.ub),Object(p.filter)((t=>!t.loading)),Object(p.map)((()=>{})))}getOnRenderComplete$(){return this._onRenderComplete$}reportsEmbeddableLoad(){return!0}async _initializeSaveMap(){try{await this._savedMap.whenReady()}catch(t){return void this.onFatalError(t)}this._initializeStore();try{await this._initializeOutput()}catch(t){return void this.onFatalError(t)}this._savedMap.getStore().dispatch(Object(O.ab)(this.getExecutionContext())),this.setInitializationFinished(),this._isInitialized=!0,this._domNode&&this.render(this._domNode)}getExecutionContext(){const t=Object(M.o)().get(),e={type:j.e,name:j.e,id:this.id,url:this.output.editPath};return t?{...t,child:e}:e}_initializeStore(){this._dispatchSetChartsPaletteServiceGetColor(this.input.syncColors);const t=this._savedMap.getStore();t.dispatch(Object(O.pb)(!0)),t.dispatch(Object(O.lb)({keydownScrollZoom:!0,showTimesliderToggleButton:!1})),t.dispatch(Object(f.j)(this._propogateMapMovement)),this._dispatchSetQuery({forceRefresh:!1}),this._subscriptions.push(Object(b.shouldFetch$)(this.getUpdated$(),(()=>({...this.getInput(),filters:this._getInputFilters(),searchSessionId:this._getSearchSessionId()}))).subscribe((()=>{this._dispatchSetQuery({forceRefresh:!1})})));const e=this._savedMap.getAttributes().mapStateJSON;if(e)try{const i=JSON.parse(e);t.dispatch(Object(O.Z)({filters:i.filters?i.filters:[],query:i.query}))}catch(t){}this._unsubscribeFromStore=t.subscribe((()=>{this._handleStoreChanges()}))}async _initializeOutput(){var t;const{title:e,description:i}=this._savedMap.getAttributes(),s=this.getInput(),n=s.hidePanelTitles?"":null!==(t=s.title)&&void 0!==t?t:e,a="savedObjectId"in s?s.savedObjectId:void 0;this.updateOutput({defaultTitle:e,defaultDescription:i,title:n,editPath:Object(j.Kb)(a),editUrl:Object(M.r)().basePath.prepend(Object(j.Lb)(a)),indexPatterns:await this._getIndexPatterns()})}inputIsRefType(t){return Object(x.a)().inputIsRefType(t)}async getInputAsRefType(){return Object(x.a)().getInputAsRefType(this.getExplicitInput(),{showSaveModal:!0,saveModalTitle:this.getTitle()})}async getExplicitInputIsEqual(t){const e=this.getExplicitInput();if(!Object(b.genericEmbeddableInputIsEqual)(t,e))return!1;const i=Object(b.omitGenericEmbeddableInput)(r.a.omit(t,"mapBuffer")),s=Object(b.omitGenericEmbeddableInput)(r.a.omit(e,"mapBuffer"));return l()(i,s)}async getInputAsValueType(){return Object(x.a)().getInputAsValueType(this.getExplicitInput())}getLayerList(){return Object(y.p)(this._savedMap.getStore().getState())}async getFilters(){const t=Object(y.g)(this._savedMap.getStore().getState());return t?t.filters:[]}async getQuery(){const t=Object(y.g)(this._savedMap.getStore().getState());return null==t?void 0:t.query}supportedTriggers(){return[_.APPLY_FILTER_TRIGGER,b.VALUE_CLICK_TRIGGER]}setIsSharable(t){this._isSharable=t}getInspectorAdapters(){return Object(f.d)(this._savedMap.getStore().getState())}onUpdate(){this.input.syncColors!==this._prevSyncColors&&this._dispatchSetChartsPaletteServiceGetColor(this.input.syncColors);const t=B(this._getSearchSessionId());t!==this._prevIsRestore&&(this._prevIsRestore=t,this._savedMap.getStore().dispatch(Object(O.lb)({disableInteractive:t,hideToolbarOverlay:t})))}_gotoSynchronizedLocation(){const t=A.a.getLocation();if(t)return void this._mapSyncHandler(t.lat,t.lon,t.zoom);if(!Object(y.x)(this._savedMap.getStore().getState())){const t=Object(y.k)(this._savedMap.getStore().getState());if(t&&t.center)return void A.a.setLocation(this.input.id,t.center.lat,t.center.lon,t.center.zoom)}const e=Object(y.t)(this._savedMap.getStore().getState()),i=Object(y.z)(this._savedMap.getStore().getState());A.a.setLocation(this.input.id,e.lat,e.lon,i)}_getInputFilters(){return this.input.filters?this.input.filters.filter((t=>!t.meta.disabled&&t.meta.controlledBy!==this._controlledBy)):[]}_getSearchSessionId(){return this.input.filterByMapExtent?void 0:this.input.searchSessionId}_dispatchSetQuery({forceRefresh:t}){this._savedMap.getStore().dispatch(Object(O.ob)({filters:this._getInputFilters(),query:this.input.query,timeFilters:this.input.timeRange,timeslice:this.input.timeslice?{from:this.input.timeslice[0],to:this.input.timeslice[1]}:void 0,clearTimeslice:void 0===this.input.timeslice,forceRefresh:t,searchSessionId:this._getSearchSessionId(),searchSessionMapBuffer:B(this._getSearchSessionId())?this.input.mapBuffer:void 0}))}async _dispatchSetChartsPaletteServiceGetColor(t){this._prevSyncColors=t;const e=t?await async function(){const t=Object(M.c)(),e=t?await t.palettes.getPalettes():null;if(!e)return null;const i=e.get("default"),s={syncColors:!0};return t=>{const e=[{name:t,rankAtDepth:0,totalSeriesAtDepth:1}];return i.getCategoricalColor(e,s)||"#3d3d3d"}}():null;t===this._prevSyncColors&&this._savedMap.getStore().dispatch(Object(f.h)(e))}render(t){if(this._domNode=t,!this._isInitialized)return;A.a.register(this.input.id,{getTitle:()=>{const t=this.getOutput();return t.title?t.title:t.defaultTitle?t.defaultTitle:this.input.id},onLocationChange:this._mapSyncHandler,getIsMovementSynchronized:this._getIsMovementSynchronized,setIsMovementSynchronized:t=>{this.updateInput({isMovementSynchronized:t}),t?this._gotoSynchronizedLocation():!t&&this._savedMap.getAutoFitToBounds()&&this._savedMap.getStore().dispatch(Object(O.lb)({autoFitToDataBounds:!0}))},getIsFilterByMapExtent:this._getIsFilterByMapExtent,setIsFilterByMapExtent:t=>{this.updateInput({filterByMapExtent:t}),t?this._setMapExtentFilter():this._clearMapExtentFilter()},getGeoFieldNames:()=>Object(y.j)(this._savedMap.getStore().getState())}),this._getIsMovementSynchronized()&&this._gotoSynchronizedLocation();const e=this._savedMap.getSharingSavedObjectProps(),i=Object(M.N)(),s=e&&i&&"conflict"===(null==e?void 0:e.outcome)?Object(R.jsx)("div",{className:"mapEmbeddedError"},Object(R.jsx)(u.EuiEmptyPrompt,{iconType:"warning",iconColor:"danger","data-test-subj":"embeddable-maps-failure",body:i.ui.components.getEmbeddableLegacyUrlConflict({targetType:j.fb,sourceId:e.sourceId})})):Object(R.jsx)(I.a,{onSingleValueTrigger:this.onSingleValueTrigger,addFilters:this.input.hideFilterActions||this.input.disableTriggers?null:this.addFilters,getFilterActions:this.getFilterActions,getActionContext:this.getActionContext,renderTooltipContent:this._renderTooltipContent,title:this.getTitle(),description:this.getDescription(),waitUntilTimeLayersLoad$:Object(L.a)(this._savedMap.getStore()),isSharable:this._isSharable}),n=Object(M.g)().Context;Object(h.render)(Object(R.jsx)(c.Provider,{store:this._savedMap.getStore()},Object(R.jsx)(n,null,Object(R.jsx)(g.KibanaThemeProvider,{theme$:Object(M.O)().theme$},s))),this._domNode)}setLayerList(t){this._savedMap.getStore().dispatch(Object(O.T)(t)),this._getIndexPatterns().then((t=>{this.updateOutput({indexPatterns:t})}))}updateLayerById(t){this._savedMap.getStore().dispatch(Object(O.Fb)(t))}async _getIndexPatterns(){const t=Object(y.D)(this._savedMap.getStore().getState());return await Object(T.e)(t)}_clearMapExtentFilter(){this._prevMapExtent=void 0;const t={...this.getActionContext(),filters:[],controlledBy:this._controlledBy},e=Object(M.R)().getAction(S.ACTION_GLOBAL_APPLY_FILTER);if(!e)throw new Error("Unable to apply map extent filter, could not locate action");e.execute(t)}destroy(){super.destroy(),A.a.unregister(this.input.id),this._isActive=!1,this._unsubscribeFromStore&&this._unsubscribeFromStore(),this._domNode&&Object(h.unmountComponentAtNode)(this._domNode),this._subscriptions.forEach((t=>{t.unsubscribe()}))}reload(){this._dispatchSetQuery({forceRefresh:!0})}_handleStoreChanges(){if(!this._isActive||!Object(y.x)(this._savedMap.getStore().getState()))return;const t=Object(y.v)(this._savedMap.getStore().getState());this._getIsFilterByMapExtent()&&!r.a.isEqual(this._prevMapExtent,t)&&this._setMapExtentFilter();const e=Object(y.t)(this._savedMap.getStore().getState()),i=Object(y.z)(this._savedMap.getStore().getState()),s=this.input.mapCenter||void 0;s&&s.lat===e.lat&&s.lon===e.lon&&s.zoom===i||this.updateInput({mapCenter:{lat:e.lat,lon:e.lon,zoom:i},mapBuffer:Object(y.s)(this._savedMap.getStore().getState())});const n=Object(m.f)(this._savedMap.getStore().getState());this.input.isLayerTOCOpen!==n&&this.updateInput({isLayerTOCOpen:n});const a=Object(m.i)(this._savedMap.getStore().getState());r.a.isEqual(this.input.openTOCDetails,a)||this.updateInput({openTOCDetails:a});const o=Object(y.m)(this._savedMap.getStore().getState());r.a.isEqual(this.input.hiddenLayers,o)||this.updateInput({hiddenLayers:o});const c=Object(y.Q)(this._savedMap.getStore().getState());this.getOutput().loading!==c&&this.updateOutput({loading:c,rendered:!c})}}},519:function(t,e,i){"use strict";t.exports=function t(e,i){if(e===i)return!0;if(e&&i&&"object"==typeof e&&"object"==typeof i){if(e.constructor!==i.constructor)return!1;var s,n,a;if(Array.isArray(e)){if((s=e.length)!=i.length)return!1;for(n=s;0!=n--;)if(!t(e[n],i[n]))return!1;return!0}if(e.constructor===RegExp)return e.source===i.source&&e.flags===i.flags;if(e.valueOf!==Object.prototype.valueOf)return e.valueOf()===i.valueOf();if(e.toString!==Object.prototype.toString)return e.toString()===i.toString();if((s=(a=Object.keys(e)).length)!==Object.keys(i).length)return!1;for(n=s;0!=n--;)if(!Object.prototype.hasOwnProperty.call(i,a[n]))return!1;for(n=s;0!=n--;){var o=a[n];if(!t(e[o],i[o]))return!1}return!0}return e!=e&&i!=i}}}]);