<template>
  <b-container fluid="xl">
    <page-title :description="$t('appPageTitle.dynamicInformation')" />
    <collapse id="collapse_1" title="Температра">
      <template #image>
        <img src="@/assets/images/_sila/collapsed/temperature.svg" />
      </template>
      <page-section section-title="Заголовок секции" style="">
        <b-row>
          <b-col sm="6" md="3">
            <b-form-group label="Не штатный режим">
              <b-form-input> </b-form-input>
            </b-form-group>
          </b-col>
          <b-col sm="6" md="3">
            <b-form-group label="Критический режим">
              <b-form-input> </b-form-input>
            </b-form-group>
          </b-col>
          <b-col sm="6" md="3">
            <b-form-group label="Значение предупреждения">
              <b-form-input> </b-form-input>
            </b-form-group>
          </b-col>
          <b-col sm="6" md="3">
            <b-button variant="primary">
              {{ 'Сохранить' }}
            </b-button>
          </b-col>
        </b-row>
        <chart
          type="processors"
          :data="filteredSensors"
          :warning="temperatureWarning"
          :non-normal="temperatureNonNormal"
          :critical-start="temperatureCriticalStart"
        ></chart>
        <b-table
          responsive="md"
          show-empty
          table-variant="accessory"
          hover
          :items="items"
          :fields="fields"
          :empty-text="$t('global.table.emptyMessage')"
        >
          <template #cell(name)="{ value, index }">
            <div
              class="item-color"
              :style="`background-color: ${colors[index]}`"
            ></div>
            {{ value }}
          </template>
          <template #cell(minDate)="{ value }">
            <span class="regular-12px">
              {{ value.time }}
            </span>
            <span class="regular-12px tretiatry">
              {{ value.date }}
            </span>
          </template>
          <template #cell(maxDate)="{ value }">
            <span class="regular-12px">
              {{ value.time }}
            </span>
            <span class="regular-12px tretiatry">
              {{ value.date }}
            </span>
          </template>
        </b-table>
      </page-section>
    </collapse>
  </b-container>
</template>
<script>
import PageTitle from '@/components/_sila/Global/PageTitle';
import Chart from '@/components/_sila/Global/Chart';
import PageSection from '@/components/Global/PageSection';

import DataFormatterMixin from '@/components/_sila/Mixins/DataFormatterMixin';
import LoadingBarMixin from '@/components/_sila/Mixins/LoadingBarMixin';
import TableFilterMixin from '@/components/_sila/Mixins/TableFilterMixin';
import Collapse from '@/components/_sila/Global/Collapse';

export default {
  components: { PageTitle, Collapse, PageSection, Chart },
  mixins: [DataFormatterMixin, LoadingBarMixin, TableFilterMixin],
  data() {
    return {
      activeFilters: [],
      temperatureWarning: 72,
      temperatureNonNormal: 44,
      temperatureCriticalStart: 55,
      fields: [
        {
          key: 'name',
          label: 'Имя модуля',
        },
        {
          key: 'currentTemperature',
          label: 'Текущее, С°',
        },
        {
          key: 'middleTemperature',
          label: 'Среднее, С°',
        },
        {
          key: 'minTemperature',
          label: 'Минимальное, С°',
        },
        {
          key: 'minDate',
          label: 'Дата минимального',
        },
        {
          key: 'maxTemperature',
          label: 'Максимальное, С°',
        },
        {
          key: 'maxDate',
          label: 'Дата максимального',
        },
      ],
      items: [
        {
          name: 'Процессор 1',
          currentTemperature: 19,
          middleTemperature: 40,
          minTemperature: 31,
          minDate: { time: '15:15', date: '11.11.2021' },
          maxTemperature: 88,
          maxDate: { time: '10:26', date: '15.11.2021' },
        },
        {
          name: 'Процессор 2',
          currentTemperature: 29,
          middleTemperature: 40,
          minTemperature: 20,
          minDate: { time: '15:45', date: '11.11.2021' },
          maxTemperature: 76,
          maxDate: { time: '16:59', date: '16.11.2021' },
        },
        {
          name: 'Процессор 3',
          currentTemperature: 48,
          middleTemperature: 46,
          minTemperature: 31,
          minDate: { time: '15:23', date: '11.11.2021' },
          maxTemperature: 69,
          maxDate: { time: '15:26', date: '15.11.2021' },
        },
        {
          name: 'Процессор 4',
          currentTemperature: 48,
          middleTemperature: 45,
          minTemperature: 5,
          minDate: { time: '16:45', date: '25.11.2021' },
          maxTemperature: 75,
          maxDate: { time: '11:26', date: '16.11.2021' },
        },
        {
          name: 'Процессор 5',
          currentTemperature: 39,
          middleTemperature: 44,
          minTemperature: 30,
          minDate: { time: '15:23', date: '11.11.2021' },
          maxTemperature: 80,
          maxDate: { time: '15:26', date: '17.11.2021' },
        },
        {
          name: 'Процессор 6',
          currentTemperature: 39,
          middleTemperature: 44,
          minTemperature: 5,
          minDate: { time: '16:45', date: '25.11.2021' },
          maxTemperature: 80,
          maxDate: { time: '15:26', date: '15.11.2021' },
        },
      ],
    };
  },

  computed: {
    allSensors() {
      let sensors = this.$store.getters['processors/processors'];
      return sensors;
    },

    filteredSensors() {
      return this.getFilteredTableData(this.allSensors, this.activeFilters);
    },
    colors() {
      return this.$randomColor({
        count: this.allSensors?.length,
        hue: 'random',
        luminosity: 'random',
      });
    },
  },

  created() {
    this.startLoader();
    this.$store.dispatch('processors/getProcessorsDynamic').finally(() => {
      this.endLoader();
    });
  },
};
</script>
