<template>
  <b-container
    :style="{ display: 'flex', 'flex-direction': 'column' }"
    fluid="xxl pt-0 m-0"
  >
    <page-title />
    <div class="main-container">
      <data-tabs
        :slots="raidSlots"
        :switch-tab="switchRaidSlot"
        :current-tab="currentRaidSlot"
        :slot-width="100"
        :slider-width="79"
        style="margin-top: 16px"
      />
      <page-section class="bootstrap-table__section" style="margin-top: 0px">
        <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>
        <b-table
          responsive="md"
          show-empty
          class="bootstrap-rounded-table"
          :items="items"
          :fields="fields"
          :empty-text="$t('global.table.emptyMessage')"
        >
          <template #cell(action)="data">
            <b-row v-if="data.index <= 5">
              <b-col>
                <span>
                  {{ data.value }}
                </span>
              </b-col>
              <b-col>
                <b-button
                  :id="`popover-action-${data.index}`"
                  class="popover-action-ractive"
                  variant="toogle-popover"
                >
                  <img :is="iconChevron" class="icon-chevron" />
                </b-button>
                <action-settings-popover
                  :id="data.index"
                  :appaly-on-reload="appalyOnReload"
                  :appaly-option1="appalyOption1"
                  :appaly-option2="appalyOption2"
                  :apply-type="applyType"
                />
              </b-col>
            </b-row>
            <b-row v-else>
              <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>
      </page-section>
      <page-section class="bootstrap-table__section">
        <div class="settings-container">
          <span class="bold-16px">{{ $t('RAID.lun') }}</span>
          <b-button
            variant="primary"
            class="apply-button apply-button__lun"
            @click="$bvModal.show('add-tome-images')"
          >
            {{ $t('global.action.addNew') }}
          </b-button>
        </div>
        <b-table
          responsive="md"
          show-empty
          class="bootstrap-rounded-table"
          :items="items_2"
          :fields="fields_2"
          :empty-text="$t('global.table.emptyMessage')"
        >
          <template #cell(action)="data">
            <b-row>
              <b-col>
                <span>
                  {{ data.value }}
                </span>
              </b-col>
              <b-col>
                <b-button
                  :id="`popover-option-${data.index}`"
                  class="popover-option-ractive"
                  variant="toogle-popover"
                >
                  <img
                    src="@/assets/images/icon-options.svg"
                    class="icon-chevron icon-options"
                  />
                </b-button>
                <options-popover :id="data.index" />
                <tome-modal
                  :id="`edit-tome${data.index}`"
                  :title="'Настройка виртуального тома'"
                  :action="editTome"
                  :index="data.index"
                  :item="items_2[data.index]"
                />
              </b-col>
            </b-row>
          </template>
        </b-table>
        <div class="microcode-container">
          <span class="bold-16px">{{ $t('RAID.microcode') }}</span>
          <popover
            id="popover-reactive-1"
            description="RAID.microcode_update"
            popup="RAID.microcode_popoveer"
            button="global.action.refresh"
            :is-microcode-drivers="true"
          />
        </div>
      </page-section>
    </div>
    <tome-modal
      :id="'add-tome-images'"
      :title="'Новый виртуальный том'"
      :action="createTome"
    />
  </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 ActionSettingsPopover from './ActionSettingsPopover';
import OptionsPopover from './OptionsPopover';
import TomeModal from './TomeModal';
import { items, items_2 } from './helpers';

export default {
  components: {
    PageTitle,
    PageSection,
    DataTabs,
    Popover,
    ApplySettingsPopover,
    ActionSettingsPopover,
    OptionsPopover,
    TomeModal,
  },
  data() {
    return {
      items,
      items_2,
      iconChevron,
      applyType: 'reload',
      currentRaidSlot: 1,
      titleModal: '',
      editIndex: null,
      raidSlots: [
        { id: 1, name: 'Контроллер 1' },
        { id: 2, name: 'Контроллер 2' },
        { id: 3, name: 'Контроллер 3' },
      ],
      fields: [
        {
          key: 'parametr',
          label: 'Имя',
          formatter: this.dataFormatter,
          thClass: 'semi-bold-12px__caps bootstrap-rounded-table__head_bg',
          class: `bootstrap-rounded-table__column-first
              settings-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-center',
          tdClass: 'regular-12px bootstrap-rounded-table__td',
        },
        {
          key: 'action',
          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',
        },
      ],
      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: '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: 'size',
          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: 'action',
          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: {
    switchRaidSlot(period) {
      this.currentRaidSlot = period;
    },
    appalyOnReload() {
      this.applyType = 'reload';
    },
    appalyOption1() {
      this.applyType = 'option1';
    },
    appalyOption2() {
      this.applyType = 'option2';
    },
    createTome() {
      console.log('Новый том создан');
    },
    editTome(index) {
      console.log('Том изменен');
      console.log(index);
    },
  },
};
</script>
<style lang="scss">
.settings-table {
  width: 35%;
}
</style>

<style lang="scss" scoped>
.bootstrap-table__section {
  margin-bottom: 24px;
}

.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;
}

.popover-action-ractive {
  margin: 0 0 0 83%;
}

.popover-option-ractive {
  margin: 0 0 0 70%;
}

.apply-button__lun {
  width: 245px;
  height: 36px;
  margin-left: auto;
}

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