(()=>{function t(i,t,e,n,a,o,d,c,r){var l,u=_.partial(p,!1);function f(t){var e=t;return e=o.kpisOnly?_(t).filter("_kpiId").uniqBy("_kpiId").value():e}function s(t){return _.reject(t,function(t){return!!_.find(d,_.pick(t,["fragment","series","__target"]))})}function g(t){i.datapoints=t}function p(t){i.data.loadingDataPoints=t}function v(){return _.union(_.filter(i.datapoints,"__active"),_.filter(i.datapointsSelected,"__active"))}function h(t){var e,n=_.get(i,"data.device.id");return n?(e=_.filter(i.datapointsSelected,function(t){t=t.__target;return n===t.id}),t.filter(function(t){t=t._kpiId;return!t||!_.find(e,{_kpiId:t})})):t}i.config=o,i.shouldDisableSelection=function(t){return!t.__active&&o&&o.maxSelectCount<=v().length},i.cancel=t.dismiss,i.getSelected=v,i.add=function(){t.close(v())},i.data={},i.$watch("data.device",function(t){t&&(i.noContext=!1,p(!0),i.datapointsSelected=v(),delete i.datapoints,n.listPossible(t).then(f).then(s).then(h).then(g).then(u))}),i.getConfigTitle=function(t){return t.title||r("Add data point")},i.getConfigBtnLabel=function(t){return t.addButtonLabel||r("Add")},a=a.getContext(),l=c.SHARED_CONTEXTS.COMPUTED_PROPERTY_LAST_MEASUREMENT.value,(t=>(t=t.context)&&("device"===t||"group"===t))(a)?(i.rootId=a.id,c.isAvailable(l)&&(i.rootId=_.get(c.get(l),"id",i.rootId))):(i.noContext=!0,p(!0),n.listForFirstDevices(2).then(f).then(s).then(g).then(u))}t.$inject=["$scope","$uibModalInstance","$injector","c8yDataPointSvc","c8yUiUtil","config","addedDataPoints","contextDetailsSharedService","gettext"],angular.module("c8y.cockpit.dataPointExplorer").controller("c8yDataPointAddCtrl",t)})();