(()=>{t.$inject=["$q","$uibModal","c8yBase","c8yInventory","c8yNavigator","dashboardSvc","gettext"],angular.module("c8y.cockpit.reports").factory("c8yReports",t);var g="c8y_Report",y={fragmentType:g,pageSize:1e3},R="reports/";function t(e,n,r,a,o,i,u){function t(){return a.list(y)}function c(){var t=o.findNode(d);t&&t.update({sortAlphabetically:!0})}function d(t){return"Reports"===t.name}function p(t){o.addNavigation(_.map(t,f))}function f(t){return{report_id:t.id,path:R+t.id,name:t.name,icon:t.icon,parent:{name:u("Reports")}}}function s(e){return function(t){return t.report_id===e.id}}function l(t){return i.named(v(t)).then(i.remove)}function m(t){return a.remove(t)}function h(t){return n.open({templateUrl:":::PLUGIN_PATH:::/views/edit.html",controller:"ReportDetailCtrl",resolve:{report:function(){return t?a.detail(t).then(r.getResData):{}}}}).result}function v(t){if(t)return"report_".concat(t.id||t);throw new Error("Must define a report")}return{initialize:function(){return t().then(p).then(c)},save:function(t){(e=t)[g]||(e[g]={});var e=a[t.id?"save":"createConfirm"](t);return t.id?o.findNode(s(t)).update(t):e.then(r.getResData).then(function(t){o.addNavigation(f(t))}),e},list:t,remove:function(t){return(t=>(t=o.findNode(s(t)),e.when(o.removeNavigation(t))))(t).then(_.partial(l,t)).then(_.partial(m,t))},detail:a.detail,createUI:h,editUI:h,isReport:function(t){return!!t[g]},dashboardName:v,getReportFromDashboard:function(t){return t=_(t).keys().map(function(t){return _.get(t.match(/^c8y_Dashboard!name!report_(\d+)/),1)}).compact().first(),a.detail(t).then(r.getResData)}}}})();