<template>
  <page-section :section-title="$t('pageTransfer.snmp.snmpTitle')">
    <b-row>
      <b-col>
        <div class="text-right">
          <b-button
            variant="primary"
            :disabled="isNotAdmin"
            @click="initSnmpModal()"
          >
            <icon-add />
            {{ $t('global.action.add') }}
          </b-button>
        </div>
        <b-table
          responsive="md"
          hover
          :fields="snmpTableFields"
          :items="form.snmpTableItems"
          :empty-text="$t('global.table.emptyMessage')"
          show-empty
        >
          <template #cell(actions)="{ item, index }">
            <table-row-action
              v-for="(action, actionIndex) in item.actions"
              :key="actionIndex"
              :value="action.value"
              :title="action.title"
              :enabled="action.enabled"
              @click-table-action="onSnmpTableAction(action, $event, index)"
            >
              <template #icon>
                <icon-edit v-if="action.value === 'edit'" />
                <icon-trashcan v-if="action.value === 'delete'" />
              </template>
            </table-row-action>
          </template>
        </b-table>
      </b-col>
    </b-row>
  </page-section>
</template>

<script>
import PageSection from '@/components/_sila/Global/PageSection';
import BVToastMixin from '@/components/_sila/Mixins/BVToastMixin';

import IconAdd from '@carbon/icons-vue/es/add--alt/20';
import IconEdit from '@carbon/icons-vue/es/edit/20';
import IconTrashcan from '@carbon/icons-vue/es/trash-can/20';
import TableRowAction from '@/components/_sila/Global/TableRowAction';

export default {
  name: 'Snmp',
  components: {
    IconAdd,
    IconEdit,
    IconTrashcan,
    PageSection,
    TableRowAction,
  },
  mixins: [BVToastMixin],

  data() {
    return {
      form: {
        snmpTableItems: [],
      },
      actions: [
        {
          value: 'edit',
          title: this.$t('global.action.edit'),
        },
        {
          value: 'delete',
          title: this.$t('global.action.delete'),
        },
      ],
      snmpTableFields: [
        {
          key: 'host',
          label: this.$t('pageTransfer.snmp.host'),
        },
        {
          key: 'port',
          label: this.$t('pageTransfer.snmp.port'),
        },
        { key: 'actions', label: '', tdClass: 'text-right' },
      ],
    };
  },
  computed: {
    isNotAdmin() {
      return (
        this.$store.getters['authentication/role'] === 'ReadOnly' ||
        this.$store.getters['authentication/role'] === 'Operator'
      );
    },
  },

  created() {
    this.getSnmpItems();
  },

  methods: {
    getSnmpItems() {},
    initSnmpModal() {},
    onSnmpTableAction() {},
  },
};
</script>
