<template>
   <div>
     <vue-table-dynamic :params="params"></vue-table-dynamic>
   </div>
</template>

<script>
export default {
  props: ['data'],
  name: 'Stats',
  data() {
    return {
      params: {
        data: [
          ['', 'Min', 'Max', 'Avg', 'Current'],
        ],
        header: 'row',
        border: true,
        stripe: true
      }
    }
  },
  mounted: function () {
      console.log("Mounted");
      console.log(this.data);
      let min = null;
      let max = null;
      let avg = 0;
      let current = null;
      for (var index = 0; index < this.data.length; ++index) {
        let row = this.data[index];
        let val = row[1];
        
        if (min == null) min = val;
        else if (min > val) min = val;

        if (max == null) max = val;
        else if (max < val) max = val;

        avg = avg + val;
        current = val;
      }
      avg = avg / this.data.length;

      this.params.data.push(['Hodnota',min,max,avg.toFixed(2),current]);
  }
}
</script>