<i18n>
{
  "en": {
  },
  "de": {
  }
}
</i18n>

<template>
  <div>
    <v-data-table
      class="group-table"
      :headers="headers"
      :items="groups"
      item-key="id"
      hide-actions
      select-all
      v-model="selected"
    >
      <template slot="items" slot-scope="props">
        <tr @click="loadGroup(props.item)">
          <td>
            <v-checkbox
              color="primary"
              v-model="props.selected"
              hide-details
              @click.native.stop
            ></v-checkbox>
          </td>
          <td>{{ props.item.id }}</td>
          <td>{{ props.item.name }}</td>
          <td>
            <v-layout>
              <v-btn icon @click.stop><v-icon color="primary">edit</v-icon></v-btn>
              <v-btn class="next-arrow" icon><v-icon>keyboard_arrow_right</v-icon></v-btn>
            </v-layout>
          </td>
        </tr>
      </template>
    </v-data-table>
  </div>
</template>

<script>
import GroupModuleGroupView from '@/components/GroupModuleGroupView'

export default {
  name: 'GroupModuleGroupList',
  components: {
    GroupModuleGroupView
  },
  props: ['tabIndex'],
  data () {
    return {
      headers: [
        { text: 'ID', value: 'id' },
        { text: 'Name', value: 'name', width: '10000px' },
        { sortable: false }
      ],
      selected: []
    }
  },
  computed: {
    groups () {
      return this.$store.state.groups.groupChain[this.tabIndex].subGroups
    }
  },
  methods: {
    loadGroup (group) {
      this.$store.dispatch('groups/loadGroupInChain', {
        tabIndex: this.tabIndex + 1, id: group.id, name: group.name, switchTab: true
      })
    }
  }
}
</script>

<!-- Add "scoped" attribute to limit CSS to this component only -->
<style scoped>
.next-arrow {
  margin-left: 20px;
  margin-right: -10px;
}
</style>
