<template>
  <b-table
    sort-icon-left
    no-sort-reset
    :sort-desc="true"
    responsive="md"
    show-empty
    class="bootstrap-rounded-table"
    :items="processors"
    :fields="fields"
    :empty-text="$t('global.table.emptyMessage')"
    :empty-filtered-text="$t('global.table.emptySearchMessage')"
  >
    <template #cell(expandRow)="row">
      <b-button
        variant="link"
        data-test-id="hardwareStatus-button-expandProcessors"
        :title="expandRowLabel"
        class="btn-icon-only"
        @click="toggleRowDetails(row)"
      >
        <icon-chevron />
        <span class="sr-only">{{ expandRowLabel }}</span>
      </b-button>
    </template>
    <template #cell(status)="{ value }">
      <div v-if="value" class="fans-table-col-first__cell">
        <img class="status__img" src="@/assets/images/status/on.svg" />
        <span>
          {{ $t('global.status.inWork') }}
        </span>
      </div>
      <div v-else class="fans-table-col-first__cell">
        <img class="status__img" src="@/assets/images/status/off.svg" />
        <span>
          {{ $t('global.status.outWorking') }}
        </span>
      </div>
    </template>

    <template #row-details="{ index }">
      <b-container fluid>
        <!-- ProcessorCapabilityInfo -->
        <b-row>
          <b-col class="mt-3 mb-2 p-0 bold-12px__caps">
            {{ $t('pageInventory.table.processorCacheInfo') }}
          </b-col>
        </b-row>
        <b-row>
          <b-col class="mt-2 p-0" sm="3" xl="3">
            <dl class="light-12px">
              <!-- Attributes Names -->
              <dd class="attrib-names">{{ $t('global.table.attributes') }}</dd>
              <dd>{{ 'Уровень кеша' }}</dd>
              <dd>{{ 'Максимальный объем' }}</dd>
              <dd>{{ 'Установленный объем' }}</dd>
              <dd>{{ 'Тип кэша' }}</dd>
              <dd>{{ 'Локализация' }}</dd>
              <dd>{{ 'Политика записи' }}</dd>
              <dd>{{ 'Ассоциативность' }}</dd>
              <dd>{{ 'Тип исправления ошибки' }}</dd>
            </dl>
          </b-col>
          <b-col class="mt-2 p-0" sm="3" xl="3">
            <dl class="light-12px">
              <!-- Status КЭШ-1 -->
              <dd class="attrib-names">{{ 'КЭШ-1' }}</dd>
              <dd v-for="item in processors[index].cache_1" :key="item.cache_1">
                {{ dataFormatter(item) }}
              </dd>
            </dl>
          </b-col>
          <b-col class="mt-2 p-0" sm="3" xl="3">
            <dl class="light-12px">
              <!-- Status state -->
              <dd class="attrib-names">{{ 'КЭШ-2' }}</dd>
              <dd v-for="item in processors[index].cache_2" :key="item.cache_2">
                {{ dataFormatter(item) }}
              </dd>
            </dl>
          </b-col>
          <b-col class="mt-2 p-0" sm="3" xl="3">
            <dl class="light-12px">
              <dd class="attrib-names">{{ 'КЭШ-3' }}</dd>
              <dd v-for="item in processors[index].cache_3" :key="item.cache_3">
                {{ dataFormatter(item) }}
              </dd>
            </dl>
          </b-col>
        </b-row>
        <b-row>
          <b-col class="mt-3 mb-2 p-0 bold-12px__caps">
            {{ $t('pageInventory.table.SupportedTechnologies') }}
          </b-col>
        </b-row>
        <b-row>
          <b-col class="mt-2 p-0" sm="6" xl="6">
            <dl class="light-12px">
              <dd class="attrib-names">{{ $t('global.table.attributes') }}</dd>
              <dd></dd>
              <dd>{{ 'processor' }}</dd>
              <dd>{{ 'vendor_id' }}</dd>
              <dd>{{ 'cpu family' }}</dd>
              <dd>{{ 'model' }}</dd>
              <dd>{{ 'model name' }}</dd>
              <dd>{{ 'stepping' }}</dd>
              <dd>{{ 'microcode' }}</dd>
              <dd>{{ 'cpu MHz' }}</dd>
              <dd>{{ 'cache size' }}</dd>
              <dd>{{ 'physical id' }}</dd>
              <dd>{{ 'siblings' }}</dd>
              <dd>{{ 'core id' }}</dd>
              <dd>{{ 'cpu cores' }}</dd>
              <dd>{{ 'apicid' }}</dd>
              <dd>{{ 'initial apicid' }}</dd>
              <dd>{{ 'fpu' }}</dd>
              <dd>{{ 'fpu_exception' }}</dd>
              <dd>{{ 'cpuid level' }}</dd>
              <dd>{{ 'wp' }}</dd>
              <dd>{{ 'flags' }}</dd>
              <dd>{{ 'bugs' }}</dd>
            </dl>
          </b-col>
          <b-col class="mt-2 p-0" sm="6" xl="6">
            <dl class="light-12px">
              <dd class="attrib-names">{{ $t('global.table.value') }}</dd>
              <dd
                v-for="item in processors[index].description"
                :key="item.description"
              >
                {{ dataFormatter(item) }}
              </dd>
            </dl>
          </b-col>
        </b-row>
      </b-container>
    </template>
  </b-table>
</template>

<script>
import TableRowExpandMixin, {
  expandRowLabel,
} from '@/components/Mixins/TableRowExpandMixin';
import IconChevron from '@carbon/icons-vue/es/chevron--down/20';
import BVToastMixin from '@/components/Mixins/BVToastMixin';
import DataFormatterMixin from '@/components/Mixins/DataFormatterMixin';

import { processors } from './helpers';
export default {
  components: { IconChevron },
  mixins: [BVToastMixin, TableRowExpandMixin, DataFormatterMixin],
  data() {
    return {
      isBusy: true,
      isAddersСolon: false,
      processors,
      fields: [
        {
          key: 'expandRow',
          label: '',
          thClass: 'semi-bold-12px__caps bootstrap-rounded-table__head_bg',
          class: `bootstrap-rounded-table__without-border
            fans-table-col-expand`,
          tdClass: 'table-row-expand bootstrap-rounded-table__td',
          sortable: false,
        },
        {
          key: 'status',
          label: 'Статус',
          formatter: this.dataFormatter,
          thClass: 'semi-bold-12px__caps bootstrap-rounded-table__head_bg',
          class: `bootstrap-rounded-table__without-border
            fans-table-col-first`,
          tdClass: 'regular-12px bootstrap-rounded-table__td',
        },
        {
          key: 'name',
          label: 'Имя',
          formatter: this.dataFormatter,
          thClass: 'semi-bold-12px__caps bootstrap-rounded-table__head_bg',
          class: `bootstrap-rounded-table__without-border
            fans-table-col-second`,
          tdClass: 'regular-12px bootstrap-rounded-table__td',
        },
        {
          key: 'model',
          label: 'Модель',
          formatter: this.dataFormatter,
          thClass: 'semi-bold-12px__caps bootstrap-rounded-table__head_bg',
          class: `bootstrap-rounded-table__without-border
            fans-table-col-third`,
          tdClass: 'regular-12px bootstrap-rounded-table__td',
        },
        {
          key: 'serialNumber',
          label: 'Серийный номер',
          formatter: this.dataFormatter,
          thClass: 'semi-bold-12px__caps bootstrap-rounded-table__head_bg',
          class: `bootstrap-rounded-table__without-border
            fans-table-col-second`,
          tdClass: 'regular-12px bootstrap-rounded-table__td',
        },
        {
          key: 'version',
          label: 'Версия',
          formatter: this.dataFormatter,
          thClass: 'semi-bold-12px__caps bootstrap-rounded-table__head_bg',
          class: `bootstrap-rounded-table__without-border
            fans-table-col-fourth`,
          tdClass: 'regular-12px bootstrap-rounded-table__td',
        },
        {
          key: 'frequency',
          label: 'Частота',
          formatter: this.dataFormatter,
          thClass: 'semi-bold-12px__caps bootstrap-rounded-table__head_bg',
          class: `bootstrap-rounded-table__without-border
            fans-table-col-fourth`,
          tdClass: 'regular-12px bootstrap-rounded-table__td',
        },
        {
          key: 'cores',
          label: 'Ядра',
          formatter: this.dataFormatter,
          thClass: 'semi-bold-12px__caps bootstrap-rounded-table__head_bg',
          class: `bootstrap-rounded-table__column-last 
            fans-table-col-fourth`,
          tdClass: 'regular-12px bootstrap-rounded-table__td',
        },
      ],
      expandRowLabel: expandRowLabel,
    };
  },
};
</script>
<style lang="scss">
.fans-table-col-expand {
  width: 3%;
}
.fans-table-col-first {
  width: 17%;
}

.fans-table-col-second {
  width: 15%;
}

.fans-table-col-third {
  width: 12%;
}

.fans-table-col-fourth {
  width: 10%;
}
</style>

<style lang="scss" scoped>
.row {
  margin: 0px;
  flex-wrap: nowrap;
}
.fans-table-col-first__cell {
  display: flex;
  flex-flow: row nowrap;
  align-items: center;
  justify-content: flex-start;
}

.status__img {
  margin-right: 7px;
}

.bold-16px {
  margin: 24px 0 0 2rem;
}

.bold-12px__caps {
  color: $text-secondary;
}

.attrib-names {
  border-bottom: 1px solid $faint-secondary-primary-10;
  color: $text-secondary !important;
  font-weight: 600;
}

.custom-switch {
  margin: 0;
}

.btn-link {
  width: 30px !important;
  height: 20px !important;
}
</style>
