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

System.register(["lodash","app/plugins/sdk"],function(a,b){"use strict";var c,d,e,f=this&&this.__extends||function(){var a=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(a,b){a.__proto__=b}||function(a,b){for(var c in b)b.hasOwnProperty(c)&&(a[c]=b[c])};return function(b,c){function d(){this.constructor=b}a(b,c),b.prototype=null===c?Object.create(c):(d.prototype=c.prototype,new d)}}();b&&b.id;return{setters:[function(a){c=a},function(a){d=a}],execute:function(){e=function(a){function b(b,d,e,f){var g=a.call(this,b,d)||this;return g.templateSrv=e,g.$sce=f,g.panelDefaults={mode:"markdown",content:"# title"},c.default.defaults(g.panel,g.panelDefaults),g.events.on("init-edit-mode",g.onInitEditMode.bind(g)),g.events.on("refresh",g.onRefresh.bind(g)),g.events.on("render",g.onRender.bind(g)),g}return f(b,a),b.$inject=["$scope","$injector","templateSrv","$sce"],b.prototype.onInitEditMode=function(){this.addEditorTab("Options","public/app/plugins/panel/text/editor.html"),this.editorTabIndex=1,"text"===this.panel.mode&&(this.panel.mode="markdown")},b.prototype.onRefresh=function(){this.render()},b.prototype.onRender=function(){"markdown"===this.panel.mode?this.renderMarkdown(this.panel.content):"html"===this.panel.mode&&this.updateContent(this.panel.content),this.renderingCompleted()},b.prototype.renderText=function(a){a=a.replace(/&/g,"&amp;").replace(/>/g,"&gt;").replace(/</g,"&lt;").replace(/\n/g,"<br/>"),this.updateContent(a)},b.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))})})},b.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)}},b.templateUrl="public/app/plugins/panel/text/module.html",b}(d.PanelCtrl),a("TextPanelCtrl",e),a("PanelCtrl",e)}}});