<template>
  <page-section class="bootstrap-table__section">
    <b-table
      responsive="md"
      show-empty
      class="bootstrap-rounded-table"
      :items="items"
      :fields="fields"
      :empty-text="$t('global.table.emptyMessage')"
    >
    </b-table>
  </page-section>
</template>

<script>
import BVToastMixin from '@/components/Mixins/BVToastMixin';
import PageSection from '@/components/Global/PageSection';
import LoadingBarMixin from '@/components/Mixins/LoadingBarMixin';
import TableRowExpandMixin, {
  expandRowLabel,
} from '@/components/Mixins/TableRowExpandMixin';

export default {
  components: { PageSection },
  mixins: [BVToastMixin, TableRowExpandMixin, LoadingBarMixin],
  data() {
    return {
      fields: [
        {
          key: 'param',
          label: 'Параметр',
          formatter: this.dataFormatter,
          thClass: 'semi-bold-12px__caps bootstrap-rounded-table__head_bg',
          class: `bootstrap-rounded-table__column-first
            bootstrap-rounded-table__column-first___system-table`,
          tdClass: 'regular-12px bootstrap-rounded-table__td',
        },
        {
          key: 'value',
          label: 'Значение',
          formatter: this.dataFormatter,
          thClass: 'semi-bold-12px__caps bootstrap-rounded-table__head_bg',
          class: 'bootstrap-rounded-table__column-last',
          tdClass: 'regular-12px bootstrap-rounded-table__td',
        },
      ],
      expandRowLabel: expandRowLabel,
      items: null,
    };
  },
  computed: {
    systems() {
      return this.$store.getters['system/systems'];
    },
  },
  watch: {
    systems() {
      this.items = [
        {
          param: 'id',
          value: this.id,
        },
        { param: 'Модель', value: this.systems[0].model },
        { param: 'Производитель', value: '' },
        { param: 'Операционная система', value: '' },
        { param: 'Серийный номер', value: this.systems[0].serialNumber },
        {
          param: 'Свободное место на Flash-накопителе',
          value: '1 024 000 Мб',
        },
      ];
    },
  },
  created() {
    this.$store.dispatch('system/getSystem').finally(() => {
      // Emit initial data fetch complete to parent component
      this.$root.$emit('hardware-status-system-complete');
    });
    this.startLoader();
    const systemTablePromise = new Promise((resolve) => {
      this.$root.$on('hardware-status-system-complete', () => resolve());
    });
    Promise.all([systemTablePromise]).finally(() => this.endLoader());
  },
};
</script>
<style lang="scss">
.bootstrap-rounded-table__column-first___system-table {
  width: 50%;
}
</style>
