import { Component, OnInit } from '@angular/core';
import {ActivatedRoute} from '@angular/router';
import {Api} from '../../service/api';
import {Load} from '../../service/load';
import { NgxDatatableModule } from '@swimlane/ngx-datatable';

@Component({
  selector: 'v-env-history',
  templateUrl: './env-history.page.html',
  styleUrls: ['./env-history.page.scss'],
})
export class EnvHistoryPage implements OnInit {

  constructor(private api: Api, private ac: ActivatedRoute, private load: Load) { }
  item = {fieldRegionNo: ''};

  // TODO 以下为假数据 待删除
  analResult = '优';

  chartOption = {
    backgroundColor: '#F0F8FF',
    visualMap: [{
      show: false,
      type: 'continuous',
      seriesIndex: 0,
      min: 0,
      max: 400},
      {
      show: false,
      type: 'continuous',
      seriesIndex: 1,
      dimension: 0,
      min: 0,
      max: 400
    }],

    xAxis: {
      name: '时间',
      type: 'category',
      data: ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun']
    },
    yAxis: [{
      name: '温度(℃)',
      type: 'value',
      splitLine: {show: false}
    },
      {
        name: '湿度(%)',
        type: 'value',
        max: 100,
        splitLine: {show: false}
      }],
    series: [{
      data: [28, 32, 35, 34, 30, 29, 27],
      type: 'line'
    },{
      data: [15, 13, 12, 11, 12, 11, 87],
      yAxisIndex: 1,
      type: 'line'
    },{
      data: [76, 45, 43, 23, 34, 54, 23],
      yAxisIndex: 1,
      type: 'line'
    }]
  };

  // 时间 热应激 温度 湿度 光照 风机 喷淋 照明
  rows = [
    { time: '17:00', thi: '轻', temp: '23.8', humi: '56', AA: '70', BB: '55%', CC: 'O', DD: 'X'},
    { time: '17:30', thi: '中', temp: '27.2', humi: '43', AA: '80', BB: '55%', CC: 'X', DD: 'O' },
    { time: '18:00', thi: '轻', temp: '23.2', humi: '61', AA: '99', BB: '55%', CC: 'O', DD: 'X' },
    { time: '18:30', thi: '轻', temp: '23.1', humi: '47', AA: '100', BB: '55%', CC: 'X', DD: 'O'},
    { time: '19:00', thi: '轻', temp: '20.2', humi: '43', AA: '60', BB: '55%', CC: 'O', DD: 'X' },
    { time: '19:30', thi: '轻', temp: '21.6', humi: '34', AA: '50', BB: '55%', CC: 'O', DD: 'X' },
    { time: '20:00', thi: '轻', temp: '22.5', humi: '43', AA: '40', BB: '55%', CC: 'X', DD: 'O' },

  ];

  ngOnInit() {
    this.ac.queryParams.subscribe((data) => {
      this.item.fieldRegionNo = data.no;
    });
    this.getData(0);

    // TODO 待删除
    for (let i = 0; i < 8; i ++) {
      this.chartOption.xAxis.data = ['8', '7', '6', '5', '4', '3', '2', '1'];
    }
  }

  getData(time) {
    if (time) {
      this.load.toLoad('加载中...', false);
    }
    this.api.cowshedApp.getRealDataByFieldRegionNo([{'fieldRegionNo' : this.item.fieldRegionNo}, (data) => {

      if (data) {
        this.item = data;
      }
    }]);
  }

}
