/*! 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(e){var t={};function n(l){if(t[l])return t[l].exports;var a=t[l]={i:l,l:!1,exports:{}};return e[l].call(a.exports,a,a.exports,n),a.l=!0,a.exports}n.m=e,n.c=t,n.d=function(e,t,l){n.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:l})},n.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},n.t=function(e,t){if(1&t&&(e=n(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var l=Object.create(null);if(n.r(l),Object.defineProperty(l,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var a in e)n.d(l,a,function(t){return e[t]}.bind(null,a));return l},n.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return n.d(t,"a",t),t},n.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},n.p="",n(n.s=12)}([function(e,t){e.exports=__kbnSharedDeps__.KbnI18n},function(e,t,n){e.exports=n(14)(1465)},function(e,t,n){n.r(t);var l=__kbnBundles__.get("plugin/embeddable/public");Object.defineProperties(t,Object.getOwnPropertyDescriptors(l))},function(e,t,n){n.r(t);var l=__kbnBundles__.get("plugin/uiActionsEnhanced/public");Object.defineProperties(t,Object.getOwnPropertyDescriptors(l))},function(e,t){e.exports=__kbnSharedDeps__.KbnMonaco},function(e,t,n){n.r(t);var l=__kbnBundles__.get("plugin/uiActions/public");Object.defineProperties(t,Object.getOwnPropertyDescriptors(l))},function(e,t){e.exports=__kbnSharedDeps__.React},function(e,t){e.exports=__kbnSharedDeps__.EmotionReact},function(e,t,n){n.r(t);var l=__kbnBundles__.get("plugin/imageEmbeddable/public");Object.defineProperties(t,Object.getOwnPropertyDescriptors(l))},function(e,t,n){n.r(t);var l=__kbnBundles__.get("plugin/kibanaUtils/public");Object.defineProperties(t,Object.getOwnPropertyDescriptors(l))},function(e,t,n){n.r(t);var l=__kbnBundles__.get("plugin/kibanaReact/public");Object.defineProperties(t,Object.getOwnPropertyDescriptors(l))},function(e,t){e.exports=__kbnSharedDeps__.KbnStd},function(e,t,n){n(13),__kbnBundles__.define("plugin/urlDrilldown/public",n,15)},function(e,t,n){n.p=window.__kbnPublicPath__.urlDrilldown},function(e,t){e.exports=__kbnSharedDeps_npm__},function(e,t,n){"use strict";n.r(t),n.d(t,"plugin",(function(){return C}));var l=n(3),a=n(9),i=n(1),r=n.n(i),o=n(6),s=n.n(o),d=n(2),c=n(8),u=n(5),p=n(10),g=n(0);const f=g.i18n.translate("xpack.urlDrilldown.DisplayName",{defaultMessage:"Go to URL"});var b=n(4);const m=e=>"number"==typeof e||"boolean"==typeof e||"string"==typeof e||null===e?e:"object"==typeof e&&e instanceof Date?e.toISOString():void 0!==e?String(e):void 0,v=e=>(Object.keys(e).forEach((t=>{void 0===e[t]&&delete e[t]})),e),x=e=>{if(Object(d.isRangeSelectTriggerContext)(e))return(e=>{const{table:t,column:n,range:l}=e.data,a=t.columns[n];return v({key:m(null==a?void 0:a.meta.field),from:m(l[0]),to:m(l[l.length-1])})})(e);if(Object(d.isValueClickTriggerContext)(e))return(e=>{var t,n,l;const a=null!==(t=e.data.negate)&&void 0!==t&&t,i=e.data.data.map((({table:e,value:t,column:n})=>{var l;const a=e.columns[n];return{value:m(t),key:null==a||null===(l=a.meta)||void 0===l?void 0:l.field}}));return v({key:null===(n=i[0])||void 0===n?void 0:n.key,value:null===(l=i[0])||void 0===l?void 0:l.value,negate:a,points:i})})(e);if(Object(d.isRowClickTriggerContext)(e))return(e=>{const{data:t}=e,n=e.embeddable,{rowIndex:l}=t,a=t.columns||t.table.columns.map((({id:e})=>e)),i=[],r=[],o=[],s=t.table.rows[l];for(const e of a){const l=t.table.columns.find((({id:t})=>t===e));if(!l)throw console.error(t,n?`Embeddable [${n.getTitle()}]`:null),new Error("Could not find a datatable column.");i.push(s[e]),r.push(l.meta.field||""),o.push(l.name||l.meta.field||"")}return{rowIndex:l,values:i,keys:r,columnNames:o}})(e);if(Object(d.isContextMenuTriggerContext)(e))return{};throw new Error("UrlDrilldown [getEventScope] can't build scope from not supported trigger")},w=b.monaco.languages.CompletionItemKind.Event,k=[{label:"event.value",sortText:"1.event.value",title:g.i18n.translate("xpack.urlDrilldown.click.event.value.title",{defaultMessage:"Click value."}),documentation:g.i18n.translate("xpack.urlDrilldown.click.event.value.documentation",{defaultMessage:"Value behind clicked data point."}),kind:w},{label:"event.key",sortText:"1.event.key",title:g.i18n.translate("xpack.urlDrilldown.click.event.key.title",{defaultMessage:"Name of clicked field."}),documentation:g.i18n.translate("xpack.urlDrilldown.click.event.key.documentation",{defaultMessage:"Field name behind clicked data point."}),kind:w},{label:"event.negate",sortText:"1.event.negate",title:g.i18n.translate("xpack.urlDrilldown.click.event.negate.title",{defaultMessage:"Whether the filter is negated."}),documentation:g.i18n.translate("xpack.urlDrilldown.click.event.negate.documentation",{defaultMessage:"Boolean, indicating whether clicked data point resulted in negative filter."}),kind:w},{label:"event.points",sortText:"1.event.points",title:g.i18n.translate("xpack.urlDrilldown.click.event.points.title",{defaultMessage:"List of all clicked points."}),documentation:g.i18n.translate("xpack.urlDrilldown.click.event.points.documentation",{defaultMessage:"Some visualizations have clickable points that emit more than one data point. Use list of data points in case a single value is insufficient."}),kind:w}],h=[{label:"event.values",sortText:"1.event.values",title:g.i18n.translate("xpack.urlDrilldown.row.event.values.title",{defaultMessage:"List of row cell values."}),documentation:g.i18n.translate("xpack.urlDrilldown.row.event.values.documentation",{defaultMessage:"An array of all cell values for the raw on which the action will execute."}),kind:w},{label:"event.keys",sortText:"1.event.keys",title:g.i18n.translate("xpack.urlDrilldown.row.event.keys.title",{defaultMessage:"List of row cell fields."}),documentation:g.i18n.translate("xpack.urlDrilldown.row.event.keys.documentation",{defaultMessage:"An array of field names for each column."}),kind:w},{label:"event.columnNames",sortText:"1.event.columnNames",title:g.i18n.translate("xpack.urlDrilldown.row.event.columnNames.title",{defaultMessage:"List of table column names."}),documentation:g.i18n.translate("xpack.urlDrilldown.row.event.columnNames.documentation",{defaultMessage:"An array of column names."}),kind:w},{label:"event.rowIndex",sortText:"1.event.rowIndex",title:g.i18n.translate("xpack.urlDrilldown.row.event.rowIndex.title",{defaultMessage:"Clicked row index."}),documentation:g.i18n.translate("xpack.urlDrilldown.row.event.rowIndex.documentation",{defaultMessage:"Number, representing the row that was clicked, starting from 0."}),kind:w}],_=[{label:"event.key",sortText:"1.event.key",title:g.i18n.translate("xpack.urlDrilldown.range.event.key.title",{defaultMessage:"Name of aggregation field."}),documentation:g.i18n.translate("xpack.urlDrilldown.range.event.key.documentation",{defaultMessage:"Aggregation field behind the selected range, if available."}),kind:w},{label:"event.from",sortText:"1.event.from",title:g.i18n.translate("xpack.urlDrilldown.range.event.from.title",{defaultMessage:"Range start value."}),documentation:g.i18n.translate("xpack.urlDrilldown.range.event.from.documentation",{defaultMessage:"`from` value of the selected range. Depending on your data, could be either a date or number."}),kind:w},{label:"event.to",sortText:"1.event.to",title:g.i18n.translate("xpack.urlDrilldown.range.event.to.title",{defaultMessage:"Range end value."}),documentation:g.i18n.translate("xpack.urlDrilldown.range.event.to.documentation",{defaultMessage:"`to` value of the selected range. Depending on your data, could be either a date or number."}),kind:w}];var D=n(11);const y=e=>g.i18n.translate("xpack.urlDrilldown.valuePreview",{defaultMessage:"Value: {value}",values:{value:e}});const I=e=>{if(!(t=e)||"object"!=typeof t||!("embeddable"in t))throw new Error("UrlDrilldown [getContextScope] can't build scope because embeddable object is missing in context");var t;return function(e){var t,n;const l=e.getInput(),a=e.getOutput(),i=function(e){return"object"==typeof(t=e)&&t&&Array.isArray(t.indexPatterns)&&t.indexPatterns.length>0?e.indexPatterns.map((e=>e.id)).filter(Boolean):[];var t}(a);return v({id:l.id,title:null!==(t=a.title)&&void 0!==t?t:l.title,savedObjectId:null!==(n=a.savedObjectId)&&void 0!==n?n:(r=l,"savedObjectId"in r&&"string"==typeof r.savedObjectId?l.savedObjectId:void 0),query:l.query,timeRange:l.timeRange,filters:l.filters,indexPatternIds:i.length>1?i:void 0,indexPatternId:1===i.length?i[0]:void 0});var r}(e.embeddable)},R=e=>({panel:I(e)}),O={id:{title:g.i18n.translate("xpack.urlDrilldown.context.panel.id.title",{defaultMessage:"Panel ID."}),documentation:g.i18n.translate("xpack.urlDrilldown.context.panel.id.documentation",{defaultMessage:"ID of the panel where drilldown is executed."})},title:{title:g.i18n.translate("xpack.urlDrilldown.context.panel.title.title",{defaultMessage:"Panel title."}),documentation:g.i18n.translate("xpack.urlDrilldown.context.panel.title.documentation",{defaultMessage:"Title of the panel where drilldown is executed."})},filters:{title:g.i18n.translate("xpack.urlDrilldown.context.panel.filters.title",{defaultMessage:"Panel filters."}),documentation:g.i18n.translate("xpack.urlDrilldown.context.panel.filters.documentation",{defaultMessage:"List of Kibana filters applied to a panel."})},"query.query":{title:g.i18n.translate("xpack.urlDrilldown.context.panel.query.query.title",{defaultMessage:"Query string."})},"query.language":{title:g.i18n.translate("xpack.urlDrilldown.context.panel.query.language.title",{defaultMessage:"Query language."})},"timeRange.from":{title:g.i18n.translate("xpack.urlDrilldown.context.panel.timeRange.from.title",{defaultMessage:'Time picker "from" value.'})},"timeRange.to":{title:g.i18n.translate("xpack.urlDrilldown.context.panel.timeRange.to.title",{defaultMessage:'Time picker "to" value.'})},indexPatternId:{title:g.i18n.translate("xpack.urlDrilldown.context.panel.timeRange.indexPatternId.title",{defaultMessage:"Index pattern ID."}),documentation:g.i18n.translate("xpack.urlDrilldown.context.panel.timeRange.indexPatternId.documentation",{defaultMessage:"First index pattern ID used by the panel."})},indexPatternIds:{title:g.i18n.translate("xpack.urlDrilldown.context.panel.timeRange.indexPatternIds.title",{defaultMessage:"Index pattern IDs."}),documentation:g.i18n.translate("xpack.urlDrilldown.context.panel.timeRange.indexPatternIds.documentation",{defaultMessage:"List of all index pattern IDs used by the panel."})},savedObjectId:{title:g.i18n.translate("xpack.urlDrilldown.context.panel.savedObjectId.title",{defaultMessage:"Saved object ID."}),documentation:g.i18n.translate("xpack.urlDrilldown.context.panel.savedObjectId.documentation",{defaultMessage:"ID of the saved object behind the panel."})}},M=b.monaco.languages.CompletionItemKind.Variable,j=e=>"object"==typeof e?"\n"+JSON.stringify(e,null,4):String(e),T=e=>(e=>{const t=[],n=Object(D.getFlattenedObject)(e),l=Object.keys(n).sort();for(const e of l){const l=O[e],a="context.panel."+e;l?t.push({label:a,sortText:"2."+a,title:l.title,documentation:(l.documentation||"")+(l.documentation&&n[e]?"\n\n":"")+(n[e]?y(j(n[e])):""),kind:M}):t.push({label:a,sortText:"2."+a,documentation:n[e]?y(j(n[e])):"",kind:M})}return t})(R(e).panel),U=b.monaco.languages.CompletionItemKind.Constant;var E=n(7);class url_drilldown_UrlDrilldown{constructor(e){r()(this,"id","URL_DRILLDOWN"),r()(this,"order",8),r()(this,"minimalLicense","gold"),r()(this,"licenseFeatureName","URL drilldown"),r()(this,"getDisplayName",(()=>f)),r()(this,"actionMenuItem",(({config:e,context:t})=>{const[n,a]=s.a.useState(e.name);return s.a.useEffect((()=>{let e=!1;const i=this.getRuntimeVariables(t);return Object(l.urlDrilldownCompileUrl)(n,i,!1).then((t=>{e||n!==t&&a(t)})).catch((()=>{})),()=>{e=!0}})),Object(E.jsx)(s.a.Fragment,null,n)})),r()(this,"euiIcon","link"),r()(this,"CollectConfig",(({config:e,onConfig:t,context:n})=>{const[a,i]=s.a.useMemo((()=>[this.getVariableList(n),this.getExampleUrl(n)]),[n]);return Object(E.jsx)(p.KibanaContextProvider,{services:{settings:this.deps.settings,theme:this.deps.theme()}},Object(E.jsx)(l.UrlDrilldownCollectConfig,{variables:a,exampleUrl:i,config:e,onConfig:t,syntaxHelpDocsLink:this.deps.getSyntaxHelpDocsLink(),variablesHelpDocsLink:this.deps.getVariablesHelpDocsLink()}))})),r()(this,"createConfig",(()=>({url:{template:""},openInNewTab:!0,encodeUrl:!0}))),r()(this,"isConfigValid",(e=>!!e.url.template)),r()(this,"isCompatible",(async(e,t)=>{const n=this.getRuntimeVariables(t),{isValid:a,error:i}=await Object(l.urlDrilldownValidateUrlTemplate)(e.url,n);if(!a)return console.warn(`UrlDrilldown [${e.url.template}] is not valid. Error [${i}]. Skipping execution.`),!1;const r=await this.buildUrl(e,t);return!!this.deps.externalUrl.validateUrl(r)})),r()(this,"getHref",(async(e,t)=>{const n=await this.buildUrl(e,t);if(!this.deps.externalUrl.validateUrl(n))throw new Error(`External URL [${n}] was denied by ExternalUrl service. You can configure external URL policies using "externalUrl.policy" setting in kibana.yml.`);return n})),r()(this,"execute",(async(e,t)=>{const n=await this.getHref(e,t);e.openInNewTab?window.open(n,"_blank","noopener"):await this.deps.navigateToUrl(n)})),r()(this,"getRuntimeVariables",(e=>({event:x(e),context:R(e),...this.deps.getGlobalScope()}))),r()(this,"getVariableList",(e=>{const t=this.deps.getGlobalScope(),n=(e=>{const[t]=e.triggers;switch(t){case d.VALUE_CLICK_TRIGGER:return[...k];case u.ROW_CLICK_TRIGGER:return[...h];case d.SELECT_RANGE_TRIGGER:return[..._]}return[]})(e);var l;return[...n,...T(e),...(l=t,[{label:"kibanaUrl",sortText:"3.kibanaUrl",title:g.i18n.translate("xpack.urlDrilldown.global.kibanaUrl.documentation.title",{defaultMessage:"Link to Kibana homepage."}),documentation:g.i18n.translate("xpack.urlDrilldown.global.kibanaUrl.documentation",{defaultMessage:"Kibana base URL. Useful for creating URL drilldowns that navigate within Kibana."})+"\n\n"+y(l.kibanaUrl),kind:U}])]})),r()(this,"getExampleUrl",(e=>{switch(e.triggers[0]){case d.SELECT_RANGE_TRIGGER:return"https://www.example.com/?from={{event.from}}&to={{event.to}}";case d.CONTEXT_MENU_TRIGGER:case c.IMAGE_CLICK_TRIGGER:return"https://www.example.com/?panel={{context.panel.title}}";case u.ROW_CLICK_TRIGGER:return"https://www.example.com/keys={{event.keys}}&values={{event.values}}";case d.VALUE_CLICK_TRIGGER:default:return"https://www.example.com/?{{event.key}}={{event.value}}"}})),this.deps=e}supportedTriggers(){return[d.VALUE_CLICK_TRIGGER,d.SELECT_RANGE_TRIGGER,u.ROW_CLICK_TRIGGER,d.CONTEXT_MENU_TRIGGER,c.IMAGE_CLICK_TRIGGER]}async buildUrl(e,t){var n;const a=null===(n=e.encodeUrl)||void 0===n||n;return await Object(l.urlDrilldownCompileUrl)(e.url.template,this.getRuntimeVariables(t),a)}}class plugin_UrlDrilldownPlugin{constructor(e){this.context=e}setup(e,t){const n=Object(a.createStartServicesGetter)(e.getStartServices);return t.uiActionsEnhanced.registerDrilldown(new url_drilldown_UrlDrilldown({externalUrl:e.http.externalUrl,getGlobalScope:Object(l.urlDrilldownGlobalScopeProvider)({core:e}),navigateToUrl:t=>e.getStartServices().then((([{application:e}])=>e.navigateToUrl(t))),getSyntaxHelpDocsLink:()=>n().core.docLinks.links.dashboard.urlDrilldownTemplateSyntax,getVariablesHelpDocsLink:()=>n().core.docLinks.links.dashboard.urlDrilldownVariables,settings:e.settings,theme:()=>n().core.theme})),{}}start(e,t){return{}}stop(){}}function C(e){return new plugin_UrlDrilldownPlugin(e)}}]);