/*! grafana - v4.2.0 - 2017-03-24
 * Copyright (c) 2017 Torkel Ödegaard; Licensed Apache-2.0 */

System.register(["angular","lodash"],function(a,b){"use strict";function c(){return{restrict:"E",controller:g,bindToController:!0,controllerAs:"ctrl",templateUrl:"public/app/features/panel/partials/query_editor_row.html",transclude:!0,scope:{queryCtrl:"=",canCollapse:"=",hasTextEditMode:"="}}}var d,e,f,g;b&&b.id;return{setters:[function(a){d=a},function(a){e=a}],execute:function(){f=d.default.module("grafana.directives"),g=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 e.default.find(b,function(b){return e.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(a){var b=a.message||a.toString();this.collapsedText="Error: "+b}}},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=e.default.without(this.panel.targets,this.target),this.panelCtrl.refresh()},a.prototype.duplicateQuery=function(){var a=d.default.copy(this.target);a.refId=this.getNextQueryLetter(),this.panel.targets.push(a)},a.prototype.moveQuery=function(a){var b=e.default.indexOf(this.panel.targets,this.target);e.default.move(this.panel.targets,b,b+a)},a}(),a("QueryRowCtrl",g),f.directive("queryEditorRow",c)}}});