/*! grafana - v4.5.1 - 2017-09-19
 * Copyright (c) 2017 Torkel Ödegaard; Licensed Apache-2.0 */

System.register(["lodash","app/core/config","app/core/core"],function(a,b){"use strict";function c(){return{restrict:"E",templateUrl:"public/app/features/dashboard/row/add_panel.html",controller:g,bindToController:!0,controllerAs:"ctrl",scope:{rowCtrl:"="}}}b&&b.id;a("addPanelDirective",c);var d,e,f,g;return{setters:[function(a){d=a},function(a){e=a},function(a){f=a}],execute:function(){g=function(){function a(a,b,c){this.$scope=a,this.$timeout=b,this.$rootScope=c,this.row=this.rowCtrl.row,this.dashboard=this.rowCtrl.dashboard,this.activeIndex=0,this.allPanels=d.default.chain(e.default.panels).filter({hideFromList:!1}).map(function(a){return a}).orderBy("sort").value(),this.panelHits=this.allPanels}return a.$inject=["$scope","$timeout","$rootScope"],a.prototype.keyDown=function(a){if(27===a.keyCode)return void(this.rowCtrl.dropView=0);if(40!==a.keyCode&&39!==a.keyCode||this.moveSelection(1),38!==a.keyCode&&37!==a.keyCode||this.moveSelection(-1),13===a.keyCode){var b=this.panelHits[this.activeIndex];b&&this.addPanel(b)}},a.prototype.moveSelection=function(a){var b=this.panelHits.length,c=this.activeIndex+a;this.activeIndex=(c%=b)<0?c+b:c},a.prototype.panelSearchChanged=function(){for(var a,b=this.allPanels.slice(),c=[],d=[],e=this.panelSearch.toLowerCase();a=b.shift();){var f=a.name.toLowerCase();0===f.indexOf(e)?c.push(a):f.indexOf(e)!==-1&&d.push(a)}this.panelHits=c.concat(d),this.activeIndex=0},a.prototype.addPanel=function(a){var b=this,c=12,d=12-this.row.span,f={id:null,title:e.default.new_panel_title,span:d<c&&d>0?d:c,type:a.id};this.rowCtrl.closeDropView(),this.dashboard.addPanel(f,this.row),this.$timeout(function(){b.$rootScope.$broadcast("render")})},a}(),a("AddPanelCtrl",g),f.coreModule.directive("dashRowAddPanel",c)}}});