<i18n>
{
  "en": {
    "grant-role": "Grant Role",
    "revoke-role": "Revoke Role"
  },
  "de": {
    "grant-role": "Rolle zuweisen",
    "revoke-role": "Rolle entziehen"
  }
}
</i18n>

<template>
  <div>
    <v-card>
      <v-data-table
        :headers="headers"
        :items="users"
        item-key="id"
        hide-actions
        select-all
        :value="selectedUsers"
        @input="$store.commit('permissions/setSelectedUsers', $event)"
      >
        <template slot="items" slot-scope="props">
          <tr @click="props.selected = !props.selected">
            <td>
              <v-checkbox
                color="primary"
                v-model="props.selected"
                hide-details
                @click.native.stop
              ></v-checkbox>
            </td>
            <td hidden>{{ props.item.id }}</td>
            <td>{{ props.item.username }}</td>
            <td>{{ props.item.name }}</td>
            <td>
              <template v-for="role in props.item.roles">
                {{ role.name }}
              </template>
            </td>
          </tr>
        </template>
      </v-data-table>
    </v-card>
    <div class="text-xs-right">
      <v-btn color="error" flat @click="$store.commit('permissions/grantRevoke', { show: true, grant: false } )">
        <v-icon left>remove_circle_outline</v-icon>{{ $t('revoke-role') }}
      </v-btn>
      <v-btn color="success" flat @click="$store.commit('permissions/grantRevoke', { show: true, grant: true } )">
        <v-icon left>add_circle_outline</v-icon>{{ $t('grant-role') }}
      </v-btn>
    </div>
  </div>
</template>

<script>
import { mapState } from 'vuex'

export default {
  name: 'PermissionModuleUserList',
  data () {
    return {
      headers: [
        { text: 'Username', value: 'username' },
        { text: 'Name', value: 'name' },
        { text: 'Roles', value: 'id' }
      ]
    }
  },
  computed: {
    ...mapState('permissions', ['selectedUsers', 'users'])
  },
  methods: {
  },
  created () {
    this.$store.dispatch('permissions/loadUserData')
  }
}
</script>

<!-- Add "scoped" attribute to limit CSS to this component only -->
<style scoped>

</style>
