<i18n>
{
  "en": {
    "grant-role": "Grant Role",
    "revoke-role": "Revoke Role",
    "username": "Username",
    "name": "Name",
    "roles": "Roles"
  },
  "de": {
    "grant-role": "Rolle zuweisen",
    "revoke-role": "Rolle entziehen",
    "username": "Nutzername",
    "name": "Name",
    "roles": "Rollen"
  }
}
</i18n>

<template>
  <div>
    <v-card>
      <data-table :value="selectedUsers"  @input="$store.commit('permissions/setSelectedUsers', $event)" :headers="headers" :items="users">
        <div slot="roles" slot-scope="row">
          <template v-for="role in row.item.roles">
            <v-tooltip top :key="role.id">
              <v-chip small slot="activator">{{ role.name }}</v-chip>
              <span>{{ role.descr }}</span>
            </v-tooltip>
          </template>
        </div>
      </data-table>
    </v-card>
    <div class="text-xs-right">
      <v-btn color="error" flat @click="$store.commit('permissions/grantRevoke', { show: true, grant: false } )" :disabled="selectedUsers.length === 0">
        <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 } )" :disabled="selectedUsers.length === 0">
        <v-icon left>add_circle_outline</v-icon>{{ $t('grant-role') }}
      </v-btn>
    </div>
  </div>
</template>

<script>
import { mapState } from 'vuex'
import DataTable from '@/components/DataTable'

export default {
  name: 'PermissionModuleUserList',
  components: {
    DataTable
  },
  data () {
    return {
      headers: [
        { text: this.$t('username'), key: 'username' },
        { text: this.$t('name'), key: 'name' },
        { text: this.$t('roles'), key: 'roles' }
      ]
    }
  },
  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>
