/*! 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(i){if(t[i])return t[i].exports;var o=t[i]={i:i,l:!1,exports:{}};return e[i].call(o.exports,o,o.exports,n),o.l=!0,o.exports}n.m=e,n.c=t,n.d=function(e,t,i){n.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:i})},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 i=Object.create(null);if(n.r(i),Object.defineProperty(i,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var o in e)n.d(i,o,function(t){return e[t]}.bind(null,o));return i},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=4)}([function(e,t,n){e.exports=n(6)(1465)},function(e,t,n){n.r(t);var i=__kbnBundles__.get("plugin/embeddable/public");Object.defineProperties(t,Object.getOwnPropertyDescriptors(i))},function(e,t){e.exports=__kbnSharedDeps__.KbnI18n},function(e,t,n){n.r(t);var i=__kbnBundles__.get("plugin/uiActionsEnhanced/public");Object.defineProperties(t,Object.getOwnPropertyDescriptors(i))},function(e,t,n){n(5),__kbnBundles__.define("plugin/embeddableEnhanced/public",n,7)},function(e,t,n){n.p=window.__kbnPublicPath__.embeddableEnhanced},function(e,t){e.exports=__kbnSharedDeps_npm__},function(e,t,n){"use strict";n.r(t),n.d(t,"plugin",(function(){return b})),n.d(t,"isEnhancedEmbeddable",(function(){return l})),n.d(t,"embeddableEnhancedDrilldownGrouping",(function(){return c}));var i=n(0),o=n.n(i),d=n(1),a=n(3);class embeddable_action_storage_EmbeddableActionStorage extends a.UiActionsEnhancedAbstractActionStorage{constructor(e){super(),this.embbeddable=e}put(e,t){var n;this.embbeddable.updateInput({enhancements:{...e.enhancements||{},dynamicActions:{...(null===(n=e.enhancements)||void 0===n?void 0:n.dynamicActions)||{},events:t}}})}async create(e){const t=this.embbeddable.getInput(),n=this.getEventsFromEmbeddable();if(n.find((({eventId:t})=>t===e.eventId)))throw new Error(`[EEXIST]: Event with [eventId = ${e.eventId}] already exists on [embeddable.id = ${t.id}, embeddable.title = ${t.title}].`);this.put(t,[...n,e])}async update(e){const t=this.embbeddable.getInput(),n=this.getEventsFromEmbeddable(),i=n.findIndex((({eventId:t})=>t===e.eventId));if(-1===i)throw new Error(`[ENOENT]: Event with [eventId = ${e.eventId}] could not be updated as it does not exist in [embeddable.id = ${t.id}, embeddable.title = ${t.title}].`);this.put(t,[...n.slice(0,i),e,...n.slice(i+1)])}async remove(e){const t=this.embbeddable.getInput(),n=this.getEventsFromEmbeddable(),i=n.findIndex((t=>e===t.eventId));if(-1===i)throw new Error(`[ENOENT]: Event with [eventId = ${e}] could not be removed as it does not exist in [embeddable.id = ${t.id}, embeddable.title = ${t.title}].`);this.put(t,[...n.slice(0,i),...n.slice(i+1)])}async read(e){const t=this.embbeddable.getInput(),n=this.getEventsFromEmbeddable().find((t=>e===t.eventId));if(!n)throw new Error(`[ENOENT]: Event with [eventId = ${e}] could not be found in [embeddable.id = ${t.id}, embeddable.title = ${t.title}].`);return n}async list(){return this.getEventsFromEmbeddable()}getEventsFromEmbeddable(){var e,t;const n=(null===(e=this.embbeddable.getInput().enhancements)||void 0===e||null===(t=e.dynamicActions)||void 0===t?void 0:t.events)||[];return this.migrate(n)}migrate(e){return e.map((e=>{if("DASHBOARD_TO_DASHBOARD_DRILLDOWN"===e.action.factoryId){const t=e.triggers.filter((e=>e!==d.VALUE_CLICK_TRIGGER&&e!==d.SELECT_RANGE_TRIGGER));return t.length===e.triggers.length||t.includes("FILTER_TRIGGER")||t.push("FILTER_TRIGGER"),{...e,triggers:t}}return e}))}}var r=n(2);const s=r.i18n.translate("xpack.embeddableEnhanced.actions.panelNotifications.oneDrilldown",{defaultMessage:"Panel has 1 drilldown"});class panel_notifications_action_PanelNotificationsAction{constructor(){o()(this,"id","ACTION_PANEL_NOTIFICATIONS"),o()(this,"getDisplayName",(({embeddable:e})=>String(this.getEventCount(e)))),o()(this,"getDisplayNameTooltip",(({embeddable:e})=>{const t=this.getEventCount(e);return t?1===t?s:(e=>r.i18n.translate("xpack.embeddableEnhanced.actions.panelNotifications.manyDrilldowns",{defaultMessage:"Panel has {count} drilldowns",values:{count:String(e)}}))(t):""})),o()(this,"isCompatible",(async({embeddable:e})=>e.getInput().viewMode===d.ViewMode.EDIT&&this.getEventCount(e)>0)),o()(this,"execute",(async()=>{}))}getEventCount(e){return e.enhancements.dynamicActions.state.get().events.length}}const c=[{id:"drilldowns",getDisplayName:()=>r.i18n.translate("xpack.embeddableEnhanced.Drilldowns",{defaultMessage:"Drilldowns"}),getIconType:()=>"symlink",order:25}];class plugin_EmbeddableEnhancedPlugin{constructor(e){o()(this,"uiActions",void 0),o()(this,"isEmbeddableContext",(e=>!(null==e||!e.embeddable)||(console.warn("For drilldowns to work action context should contain .embeddable field."),!1))),this.context=e}setup(e,t){this.setCustomEmbeddableFactoryProvider(t);const n=new panel_notifications_action_PanelNotificationsAction;return t.uiActionsEnhanced.registerAction(n),t.uiActionsEnhanced.attachAction(d.PANEL_NOTIFICATION_TRIGGER,n.id),{}}start(e,t){return this.uiActions=t.uiActionsEnhanced,{}}stop(){}setCustomEmbeddableFactoryProvider(e){e.embeddable.setCustomEmbeddableFactoryProvider((e=>{const t=Object(d.defaultEmbeddableFactoryProvider)(e);return{...t,create:async(...e)=>{const n=await t.create(...e);return n?this.enhanceEmbeddableWithDynamicActions(n):n},createFromSavedObject:async(...e)=>{const n=await t.createFromSavedObject(...e);return n?this.enhanceEmbeddableWithDynamicActions(n):n}}}))}enhanceEmbeddableWithDynamicActions(e){const t=e,n=new embeddable_action_storage_EmbeddableActionStorage(e),i=new a.UiActionsEnhancedDynamicActionManager({isCompatible:async t=>!!this.isEmbeddableContext(t)&&t.embeddable.runtimeId===e.runtimeId,storage:n,uiActions:this.uiActions});i.start().catch((t=>{console.log("Failed to start embeddable dynamic actions",e),console.error(t)}));const o=()=>{i.stop().catch((t=>{console.log("Failed to stop embeddable dynamic actions",e),console.error(t)}))};return e.getInput$().subscribe({next:()=>{n.reload$.next()},error:o,complete:o}),t.enhancements={...t.enhancements,dynamicActions:i},t}}const l=e=>{var t;return"object"==typeof(null==e||null===(t=e.enhancements)||void 0===t?void 0:t.dynamicActions)};function b(e){return new plugin_EmbeddableEnhancedPlugin(e)}}]);