/*! 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. */!function(t){function e(e){for(var n,o,i=e[0],a=e[1],s=0,l=[];s{if(!t)return[];const e=t.getOutput();return(t=>!(!t||"object"!=typeof t)&&Array.isArray(t.indexPatterns))(e)?e.indexPatterns.map((({id:t})=>t)):[]},l=t=>1===c(t).length;var p=n(4),u=n(5);class abstract_explore_data_action_AbstractExploreDataAction{constructor(t){o()(this,"getIconType",(t=>"discoverApp")),o()(this,"getDisplayName",(t=>p.i18n.translate("xpack.discover.FlyoutCreateDrilldownAction.displayName",{defaultMessage:"Explore underlying data"}))),this.params=t}async isCompatible({embeddable:t}){if(!t)return!1;if(t.type===u.DOC_TYPE)return!1;const{core:e,plugins:n}=this.params.start(),{capabilities:r}=e.application;return!(r.discover&&!r.discover.show||!n.discover.locator||!l(t)||t.getInput().viewMode!==s.ViewMode.VIEW)}async execute(t){if(!l(t.embeddable))return;const{core:e}=this.params.start(),{app:n,path:r}=await this.getLocation(t);await e.application.navigateToApp(n,{path:r})}async getHref(t){const{embeddable:e}=t;if(!l(e))throw new Error(`Embeddable not supported for "${this.getDisplayName(t)}" action.`);const{core:n}=this.params.start(),{app:r,path:o}=await this.getLocation(t);return await n.application.getUrlForApp(r,{path:o,absolute:!1})}}const d="ACTION_EXPLORE_DATA";class explore_data_context_menu_action_ExploreDataContextMenuAction extends abstract_explore_data_action_AbstractExploreDataAction{constructor(...t){super(...t),o()(this,"id",d),o()(this,"type",d),o()(this,"order",200),o()(this,"getLocation",(async t=>{const{plugins:e}=this.params.start(),{locator:n}=e.discover;if(!n)throw new Error("Discover URL locator not available.");const{embeddable:r}=t,o={};if(r){o.indexPatternId=c(r)[0]||void 0;const t=r.getInput();t.timeRange&&!o.timeRange&&(o.timeRange=t.timeRange),t.query&&(o.query=t.query),t.filters&&(o.filters=[...t.filters,...o.filters||[]])}return await n.getLocation(o)}))}}const _="ACTION_EXPLORE_DATA_CHART";class explore_data_chart_action_ExploreDataChartAction extends abstract_explore_data_action_AbstractExploreDataAction{constructor(...t){super(...t),o()(this,"id",_),o()(this,"type",_),o()(this,"order",200),o()(this,"getLocation",(async t=>{const{plugins:e}=this.params.start(),{locator:r}=e.discover;if(!r)throw new Error("Discover URL locator not available.");const{embeddable:o}=t,{extractTimeRange:i}=await Promise.resolve().then(n.t.bind(null,10,7)),{restOfFilters:a,timeRange:s}=i(t.filters,t.timeFieldName),l={filters:a,timeRange:s};if(o){l.indexPatternId=c(o)[0]||void 0;const t=o.getInput();t.timeRange&&!l.timeRange&&(l.timeRange=t.timeRange),t.query&&(l.query=t.query),t.filters&&(l.filters=[...t.filters,...l.filters||[]])}return await r.getLocation(l)}))}async isCompatible(t){var e;return"map"!==(null===(e=t.embeddable)||void 0===e?void 0:e.type)&&super.isCompatible(t)}}class plugin_DiscoverEnhancedPlugin{constructor(t){o()(this,"config",void 0),this.context=t,this.config=t.config.get()}setup(t,{uiActions:e,share:n}){const r=Object(a.createStartServicesGetter)(t.getStartServices);if(n){const t={start:r};if(this.config.actions.exploreDataInContextMenu.enabled){const n=new explore_data_context_menu_action_ExploreDataContextMenuAction(t);e.addTriggerAction(s.CONTEXT_MENU_TRIGGER,n)}if(this.config.actions.exploreDataInChart.enabled){const n=new explore_data_chart_action_ExploreDataChartAction(t);e.addTriggerAction(i.APPLY_FILTER_TRIGGER,n)}}}start(t,e){}stop(){}}const f=t=>new plugin_DiscoverEnhancedPlugin(t)},function(t,e){t.exports=__kbnSharedDeps__.KbnEsQuery}]);