<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 v-model="selectedRoles" :headers="headers" :items="roles" @dblclick="editRole($event)">
        <div slot="action" slot-scope="row" style="text-align: right">
          <v-btn flat icon color="primary" @click.stop="editRole(row.item)"><v-icon>edit</v-icon></v-btn>
        </div>
      </data-table>
    </v-card>
    <div class="text-xs-right">
      <v-btn color="error" flat @click="deleteRole" :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="createRole">
        <v-icon left>add_circle_outline</v-icon>{{ $t('create-role') }}
      </v-btn>
    </div>
  </div>
</template>

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

export default {
  name: 'PermissionModuleRoleList',
  components: {
    DataTable
  },
  data () {
    return {
      selectedRoles: []
    }
  },
  computed: {
    headers () {
      return [
        { text: this.$t('id'), key: 'id' },
        { text: this.$t('name'), key: 'name' },
        { text: this.$t('description'), key: 'descr' },
        { sortable: false, key: 'action', width: '60px' }
      ]
    },
    ...mapState('permissions', ['roles'])
  },
  methods: {
    ...mapMutations('permissions', ['setDialog']),
    createRole () {
      this.setDialog({ show: true, type: 'edit', info: {} })
    },
    deleteRole () {
      this.setDialog({ show: true, type: 'delete', info: this.selectedRoles })
    },
    editRole (role) {
      this.setDialog({ show: true, type: 'edit', info: role })
    }
  }
}
</script>

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

</style>
