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

System.register(["lodash","moment","app/core/utils/kbn"],function(a){var b,c,d,e;return{setters:[function(a){b=a},function(a){c=a},function(a){d=a}],execute:function(){e=function(){function a(a,b,c,d){this.panel=a,this.table=b,this.isUtc=c,this.sanitize=d,this.formaters=[],this.colorState={}}return a.prototype.getColorForValue=function(a,c){if(!c.thresholds)return null;for(var d=c.thresholds.length;d>0;d--)if(a>=c.thresholds[d-1])return c.colors[d];return b["default"].first(c.colors)},a.prototype.defaultCellFormater=function(a,c){return null===a||void 0===a||void 0===a?"":(b["default"].isArray(a)&&(a=a.join(", ")),c&&c.sanitize?this.sanitize(a):b["default"].escape(a))},a.prototype.createColumnFormater=function(a,e){var f=this;if(!a)return this.defaultCellFormater;if("date"===a.type)return function(d){b["default"].isArray(d)&&(d=d[0]);var e=c["default"](d);return f.isUtc&&(e=e.utc()),e.format(a.dateFormat)};if("number"===a.type){var g=d["default"].valueFormats[e.unit||a.unit];return function(c){return null===c||void 0===c?"-":b["default"].isString(c)?f.defaultCellFormater(c,a):(a.colorMode&&(f.colorState[a.colorMode]=f.getColorForValue(c,a)),g(c,a.decimals,null))}}return function(b){return f.defaultCellFormater(b,a)}},a.prototype.formatColumnValue=function(a,b){if(this.formaters[a])return this.formaters[a](b);for(var c=0;c<this.panel.styles.length;c++){var e=this.panel.styles[c],f=this.table.columns[a],g=d["default"].stringToJsRegex(e.pattern);if(f.text.match(g))return this.formaters[a]=this.createColumnFormater(e,f),this.formaters[a](b)}return this.formaters[a]=this.defaultCellFormater,this.formaters[a](b)},a.prototype.renderCell=function(a,b,c){void 0===c&&(c=!1),b=this.formatColumnValue(a,b);var d="";this.colorState.cell?(d=' style="background-color:'+this.colorState.cell+';color: white"',this.colorState.cell=null):this.colorState.value&&(d=' style="color:'+this.colorState.value+'"',this.colorState.value=null);var e="";return c&&(e='<div class="table-panel-width-hack">'+this.table.columns[a].text+"</div>"),"<td"+d+">"+b+e+"</td>"},a.prototype.render=function(a){for(var b=this.panel.pageSize||100,c=a*b,d=Math.min(c+b,this.table.rows.length),e="",f=c;f<d;f++){for(var g=this.table.rows[f],h="",i="",j=0;j<this.table.columns.length;j++)h+=this.renderCell(j,g[j],f===c);this.colorState.row&&(i=' style="background-color:'+this.colorState.row+';color: white"',this.colorState.row=null),e+="<tr "+i+">"+h+"</tr>"}return e},a}(),a("TableRenderer",e)}}});