/*! grafana - v3.1.0 - 2016-07-18
 * Copyright (c) 2016 Torkel Ödegaard; Licensed Apache-2.0 */

System.register(["angular","lodash"],function(a){function b(){return{restrict:"E",controller:f,bindToController:!0,controllerAs:"ctrl",templateUrl:"public/app/features/panel/partials/query_editor_row.html",transclude:!0,scope:{queryCtrl:"=",canCollapse:"=",hasTextEditMode:"="}}}var c,d,e,f;return{setters:[function(a){c=a},function(a){d=a}],execute:function(){e=c["default"].module("grafana.directives"),f=function(){function a(){this.panelCtrl=this.queryCtrl.panelCtrl,this.target=this.queryCtrl.target,this.panel=this.panelCtrl.panel,this.target.refId||(this.target.refId=this.getNextQueryLetter()),this.toggleCollapse(!0),this.target.isNew&&(delete this.target.isNew,this.toggleCollapse(!1))}return a.prototype.toggleHideQuery=function(){this.target.hide=!this.target.hide,this.panelCtrl.refresh()},a.prototype.getNextQueryLetter=function(){var a=this,b="ABCDEFGHIJKLMNOPQRSTUVWXYZ";return d["default"].find(b,function(b){return d["default"].every(a.panel.targets,function(a){return a.refId!==b})})},a.prototype.toggleCollapse=function(a){if(this.canCollapse){this.panelCtrl.__collapsedQueryCache||(this.panelCtrl.__collapsedQueryCache={}),a?this.collapsed=this.panelCtrl.__collapsedQueryCache[this.target.refId]!==!1:(this.collapsed=!this.collapsed,this.panelCtrl.__collapsedQueryCache[this.target.refId]=this.collapsed);try{this.collapsedText=this.queryCtrl.getCollapsedText()}catch(b){var c=b.message||b.toString();this.collapsedText="Error: "+c}}},a.prototype.toggleEditorMode=function(){this.canCollapse&&this.collapsed&&(this.collapsed=!1),this.queryCtrl.toggleEditorMode()},a.prototype.removeQuery=function(){this.panelCtrl.__collapsedQueryCache&&delete this.panelCtrl.__collapsedQueryCache[this.target.refId],this.panel.targets=d["default"].without(this.panel.targets,this.target),this.panelCtrl.refresh()},a.prototype.duplicateQuery=function(){var a=c["default"].copy(this.target);a.refId=this.getNextQueryLetter(),this.panel.targets.push(a)},a.prototype.moveQuery=function(a){var b=d["default"].indexOf(this.panel.targets,this.target);d["default"].move(this.panel.targets,b,b+a)},a}(),a("QueryRowCtrl",f),e.directive("queryEditorRow",b)}}});