<i18n>
{
  "en": {
    "create-role": "Create Role",
    "delete-role": "Delete {0} Role | Delete {0} Roles",
    "id": "ID",
    "name": "Name",
    "description": "Description"
  },
  "de": {
    "create-role": "Rolle erstellen",
    "delete-role": "Lösche {0} Rolle | Lösche {0} Rollen",
    "id": "ID",
    "name": "Name",
    "description": "Beschreibung"
  }
}
</i18n>

<template>
  <div>
    <v-card>
      <data-table :value="selectedRoles"  @input="$store.commit('permissions/setSelectedRoles', $event)" :headers="headers" :items="roles">
        <div slot="action" slot-scope="row">
          <v-btn flat icon color="primary" @click.stop="$store.commit('permissions/editRole', row.item.id)"><v-icon>edit</v-icon></v-btn>
        </div>
      </data-table>
    </v-card>
    <div class="text-xs-right">
      <v-btn color="error" flat @click="$store.commit('permissions/setDialog', true )" :disabled="selectedRoles.length === 0">
        <v-icon left>remove_circle_outline</v-icon>{{ $tc('delete-role', selectedRoles.length, [selectedRoles.length]) }}
      </v-btn>
      <v-btn color="success" flat @click="$store.commit('permissions/editRole', 0)">
        <v-icon left>add_circle_outline</v-icon>{{ $t('create-role') }}
      </v-btn>
    </div>
  </div>
</template>

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

export default {
  name: 'PermissionModuleRoleList',
  components: {
    DataTable
  },
  data () {
    return {
      headers: [
        { text: this.$t('id'), key: 'id' },
        { text: this.$t('name'), key: 'name' },
        { text: this.$t('description'), key: 'descr' },
        { sortable: false, key: 'action' }
      ]
    }
  },
  computed: {
    ...mapState('permissions', ['selectedRoles', 'roles'])
  },
  methods: {
  },
  created () {
    this.$store.dispatch('permissions/loadRoleData')
  }
}
</script>

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

</style>
