<template>
  <b-container
    :style="{ display: 'flex', 'flex-direction': 'column' }"
    fluid="xxl pt-0 m-0"
  >
    <page-title :description="$t('appNavigation.ethernetAdapters')" />
    <data-tabs
      :slots="adaptersSlots"
      :switch-tab="switchAdapterSlot"
      :current-tab="currentAdapterSlot"
      :slot-width="85"
      :slider-width="60"
      style="margin-top: 16px"
    />
    <page-section class="bootstrap-table__section">
      <div class="settings-container">
        <span class="bold-16px">{{ $t('appNavigation.settings') }}</span>
        <apply-settings-popover
          :appaly-on-reload="appalyOnReload"
          :appaly-option1="appalyOption1"
          :appaly-option2="appalyOption2"
          :apply-type="applyType"
        />
        <b-button variant="primary" class="apply-button">
          {{ $t('global.action.acceptChanges') }}
        </b-button>
      </div>
      <span class="bold-12px__caps">
        {{ $t('pageNetwork.macAddress') }}
      </span>
      <b-table
        responsive="md"
        class="bootstrap-table bootstrap-table__stripes_odd"
        :items="items"
        :fields="fields"
      >
        <template #cell(value)="data">
          <b-row>
            <b-col>
              <span>
                {{ data.value }}
              </span>
            </b-col>
            <b-col>
              <img
                src="@/assets/images/icon-edit.svg"
                class="icon-chevron icon-edit"
              />
            </b-col>
          </b-row>
        </template>
      </b-table>
      <span class="bold-12px__caps">
        {{ $t('adapters.settings') }}
      </span>
      <b-table
        responsive="md"
        class="bootstrap-table bootstrap-table__stripes_odd"
        :items="items_2"
        :fields="fields"
      >
        <template #cell(value)="data">
          <b-row v-if="data.index === 3" class="multiple-select-container">
            <b-col v-if="selected.length" class="chip-column">
              <b-row class="chip-container">
                <div
                  v-for="item in selected"
                  :key="item.value"
                  class="custom-chip"
                >
                  <span> {{ item.text }} </span>
                  <img
                    class="clear-icon"
                    src="@/assets/images/popups/x-icon.svg"
                    @click="optionRemove(item.value)"
                  />
                </div>
              </b-row>
            </b-col>
            <b-col v-else>
              {{ 'Не выбрано ' }}
            </b-col>
            <b-col class="icon-container">
              <b-button id="popover-boot" variant="toogle-popover">
                <img :is="iconChevron" class="icon-chevron" />
              </b-button>
              <b-popover
                placement="left"
                triggers="focus"
                :show.sync="show"
                custom-class="boot-popover"
                target="popover-boot"
              >
                <b-form-group
                  v-slot="{ ariaDescribedby }"
                  class="checkbox-group"
                >
                  <b-form-checkbox-group
                    v-model="selected"
                    :options="options"
                    :aria-describedby="ariaDescribedby"
                    class="regular-14px checkbox-container"
                    stacked
                  ></b-form-checkbox-group>
                </b-form-group>
              </b-popover>
            </b-col>
          </b-row>
          <b-row v-else>
            <b-col>
              <span>
                {{ data.value ? 'Возможно' : 'Не возможно' }}
              </span>
            </b-col>
            <b-col>
              <img :is="iconChevron" class="icon-chevron icon-options" />
            </b-col>
          </b-row>
        </template>
      </b-table>
      <span class="bold-12px__caps">
        {{ $t('adapters.propherties') }}
      </span>
      <b-table
        responsive="md"
        class="bootstrap-table bootstrap-table__stripes"
        :items="items_3"
        :fields="fields"
      >
      </b-table>
      <div class="settings-container">
        <span class="bold-16px">{{ $t('adapters.PXE') }}</span>
        <apply-settings-popover
          :id="2"
          :appaly-on-reload="appalyOnReload"
          :appaly-option1="appalyOption1"
          :appaly-option2="appalyOption2"
          :apply-type="applyType"
        />
      </div>
      <b-table
        responsive="md"
        class="bootstrap-table bootstrap-table__stripes_odd"
        :items="items_4"
        :fields="fields"
      >
        <template #cell(value)="data">
          <b-row class="flex-row">
            <b-col>
              <span>
                {{ data.value ? 'Включено' : 'Выключено' }}
              </span>
            </b-col>
            <b-col>
              <b-form-checkbox v-model="items_4[data.index].value" switch>
              </b-form-checkbox>
            </b-col>
          </b-row>
        </template>
      </b-table>
      <div class="settings-container">
        <span class="bold-16px">{{ $t('adapters.links') }}</span>
      </div>
      <b-table
        responsive="md"
        class="bootstrap-table bootstrap-table__stripes"
        :items="items_5"
        :fields="fields"
      >
      </b-table>
      <div class="settings-container">
        <span class="bold-16px">{{ $t('adapters.transceivers') }}</span>
      </div>
      <b-table
        responsive="md"
        show-empty
        class="bootstrap-rounded-table"
        :items="items_6"
        :fields="fields_2"
        :empty-text="$t('global.table.emptyMessage')"
      >
      </b-table>
      <div class="microcode-container">
        <span class="bold-16px">{{
          $t('SystemDescription.microcodeAdapter')
        }}</span>
        <popover
          id="popover-reactive-1"
          description="adapters.microcodeUpdate"
          popup="adapters.microcodeUpdate_popup"
          button="global.action.refresh"
          :is-microcode-drivers="true"
        />
      </div>
    </page-section>
  </b-container>
</template>

<script>
import PageTitle from '@/components/Global/PageTitle';
import PageSection from '@/components/Global/PageSection';
import Popover from '@/components/Global/Popover';
import ApplySettingsPopover from '@/components/Global/SilaComponents/ApplySettingsPopover';
import DataTabs from '@/components/Global/SilaComponents/DataTabs';

import iconChevron from '@carbon/icons-vue/es/chevron--down/16';
import { items, items_2, items_3, items_4, items_5, items_6 } from './helpers';

export default {
  components: {
    PageTitle,
    PageSection,
    DataTabs,
    Popover,
    ApplySettingsPopover,
  },
  data() {
    return {
      items,
      items_2,
      items_3,
      items_4,
      items_5,
      items_6,
      iconChevron,
      selected: [],
      show: false,
      options: [
        { text: 'PXE', value: { text: 'PXE', value: 'pxe' } },
        { text: 'ISCSI-PXE', value: { text: 'ISCSI-PXE', value: 'iscsi-pxe' } },
        { text: 'ISCSI', value: { text: 'ISCSI', value: 'iscsi' } },
        { text: 'PXE2', value: { text: 'PXE2', value: 'pxe2' } },
        { text: 'ISCSI 2', value: { text: 'ISCSI 2', value: 'iscsi2' } },
        {
          text: 'ISCSI-PXE 2',
          value: { text: 'ISCSI-PXE 2', value: 'iscsi-pxe2' },
        },
      ],
      applyType: 'reload',
      currentAdapterSlot: 1,
      adaptersSlots: [
        { id: 1, name: 'Адаптер 1' },
        { id: 2, name: 'Адаптер 2' },
        { id: 3, name: 'Адаптер 3' },
      ],
      fields: [
        {
          key: 'param',
          label: '',
          formatter: this.dataFormatter,
          thClass: 'bootstrap-table__head_bg',
          class: 'bootstrap-table__column-first',
          tdClass: 'regular-12px bootstrap-table__td',
        },
        {
          key: 'value',
          label: '',
          formatter: this.dataFormatter,
          thClass: 'bootstrap-table__head_bg',
          class: `bootstrap-table__column-last
            bootstrap-table__server-param`,
          tdClass: 'regular-12px bootstrap-table__td',
        },
      ],
      fields_2: [
        {
          key: 'name',
          label: 'Параметр',
          formatter: this.dataFormatter,
          thClass: 'semi-bold-12px__caps bootstrap-rounded-table__head_bg',
          class: 'bootstrap-rounded-table__column-first',
          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__column-center',
          tdClass: 'regular-12px bootstrap-rounded-table__td',
        },
        {
          key: 'number',
          label: 'Серийный номер',
          formatter: this.dataFormatter,
          thClass: 'semi-bold-12px__caps bootstrap-rounded-table__head_bg',
          class: 'bootstrap-rounded-table__column-center',
          tdClass: 'regular-12px bootstrap-rounded-table__td',
        },
        {
          key: 'type',
          label: 'Тип устройства',
          formatter: this.dataFormatter,
          thClass: 'semi-bold-12px__caps bootstrap-rounded-table__head_bg',
          class: 'bootstrap-rounded-table__column-center',
          tdClass: 'regular-12px bootstrap-rounded-table__td',
        },
        {
          key: 'firmware',
          label: 'Прошивка',
          formatter: this.dataFormatter,
          thClass: 'semi-bold-12px__caps bootstrap-rounded-table__head_bg',
          class: 'bootstrap-rounded-table__column-center',
          tdClass: 'regular-12px bootstrap-rounded-table__td',
        },
        {
          key: 'status',
          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',
        },
      ],
    };
  },
  methods: {
    switchAdapterSlot(period) {
      this.currentAdapterSlot = period;
    },
    appalyOnReload() {
      this.applyType = 'reload';
    },
    appalyOption1() {
      this.applyType = 'option1';
    },
    appalyOption2() {
      this.applyType = 'option2';
    },
    optionRemove(value) {
      this.selected.splice(
        this.selected.findIndex((el) => el.value === value),
        1
      );
      console.log(value);
    },
  },
};
</script>
<style lang="scss">
.bootstrap-table__section {
  width: auto;
}

.bootstrap-table__server-param {
  width: 30%;
}
</style>

<style lang="scss" scoped>
.bold-16px {
  display: block;
  margin: 25px 0 16px 0;
}

.settings-container {
  display: flex;
  align-items: center;
  justify-content: flex-start;
}

.apply-button {
  width: 245px;
  height: 36px;
}

.microcode-container {
  display: flex;
  flex-direction: row;
  flex-wrap: nowrap;
  align-items: baseline;
  justify-content: space-between;
}

.bold-12px__caps {
  display: block;
  margin: 20px 0 8px 0;
}

.flex-row {
  align-items: center;
}

.multiple-select-container {
  justify-content: flex-end;
}

.chip-column {
  padding-right: 0px;
}

.chip-container {
  margin-left: -5px;
}

.custom-chip {
  display: flex;
  align-items: center;
  height: 24px;
  margin: 2px 3px;
  padding: 0 10px;
  background-color: $faint-secondary-primary-10;
  border-radius: 94px;
}

.icon-container {
  flex-grow: 0;
  padding: 0px;
  margin: 0 11px 0 5px;
}

.clear-icon {
  width: 10px;
  margin-left: 6px;
  cursor: pointer;
}

.checkbox-group {
  margin: 0;
}

.checkbox-container {
  display: flex;
  flex-direction: column;
  flex-wrap: nowrap;
  gap: 7px;
}
</style>
