var DashKPI = SuperWidget.extend({

init:function(){

var self=this;

window.addEventListener("dashboardData",function(e){

self.calcular(e.detail);

});

},

calcular:function(dados){

var total=dados.length;

var conformes=dados.filter(function(i){
return normalizaStatus(i)=="CONFORME";
}).length;

var nao=dados.filter(function(i){
return normalizaStatus(i)=="NAO_CONFORME";
}).length;

var pct= total ? Math.round((conformes/total)*100) : 0;

$("#kpi_total_"+this.instanceId).text(total);
$("#kpi_ok_"+this.instanceId).text(conformes);
$("#kpi_nok_"+this.instanceId).text(nao);
$("#kpi_pct_"+this.instanceId).text(pct+"%");

}

});

function normalizaStatus(item){
var raw = item.saidaAnalise || item.status || "";
return String(raw).trim().toUpperCase();
}
