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

System.register(["lodash","app/plugins/sdk"],function(a){var b,c,d,e=this&&this.__extends||function(a,b){function c(){this.constructor=a}for(var d in b)b.hasOwnProperty(d)&&(a[d]=b[d]);a.prototype=null===b?Object.create(b):(c.prototype=b.prototype,new c)};return{setters:[function(a){b=a},function(a){c=a}],execute:function(){d=function(a){function c(c,d,e,f){a.call(this,c,d),this.templateSrv=e,this.$sce=f,this.panelDefaults={mode:"markdown",content:"# title"},b["default"].defaults(this.panel,this.panelDefaults),this.events.on("init-edit-mode",this.onInitEditMode.bind(this)),this.events.on("refresh",this.onRender.bind(this)),this.events.on("render",this.onRender.bind(this))}return e(c,a),c.$inject=["$scope","$injector","templateSrv","$sce"],c.prototype.onInitEditMode=function(){this.addEditorTab("Options","public/app/plugins/panel/text/editor.html"),this.editorTabIndex=1},c.prototype.onRender=function(){"markdown"===this.panel.mode?this.renderMarkdown(this.panel.content):"html"===this.panel.mode?this.updateContent(this.panel.content):"text"===this.panel.mode&&this.renderText(this.panel.content),this.renderingCompleted()},c.prototype.renderText=function(a){a=a.replace(/&/g,"&amp;").replace(/>/g,"&gt;").replace(/</g,"&lt;").replace(/\n/g,"<br/>"),this.updateContent(a)},c.prototype.renderMarkdown=function(a){var b=this;return this.remarkable?void this.updateContent(this.remarkable.render(a)):System["import"]("remarkable").then(function(c){b.remarkable=new c,b.$scope.$apply(function(){b.updateContent(b.remarkable.render(a))})})},c.prototype.updateContent=function(a){try{this.content=this.$sce.trustAsHtml(this.templateSrv.replace(a,this.panel.scopedVars))}catch(b){console.log("Text panel error: ",b),this.content=this.$sce.trustAsHtml(a)}},c.templateUrl="public/app/plugins/panel/text/module.html",c}(c.PanelCtrl),a("TextPanelCtrl",d),a("PanelCtrl",d)}}});