<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>
        </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,
    };
  },

  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>
