<i18n>
{
  "en": {
    "create-event": "Create Event",
    "delete-event": "Delete {0} Event | Delete {0} Events",
    "name": "Name",
    "description": "Description",
    "config": "Configuration",
    "times": "Times"
  },
  "de": {
    "create-event": "Veranstaltung erstellen",
    "delete-event": "Lösche {0} Veranstaltung | Lösche {0} Veranstaltungen",
    "name": "Name",
    "description": "Beschreibung",
    "config": "Konfiguration",
    "times": "Zeiten"
  }
}
</i18n>

<template>
  <div>
    <v-card>
      <data-table v-model="selectedEvents" :headers="headers" :items="events" @dblclick="editEvent($event)">
        <div slot="action" slot-scope="row" style="text-align: right">
          <v-btn flat icon color="primary" @click.stop="editEvent(row.item)" :class="row.index === 0 ? 'tutorial-element label-top-left element-icon' : ''" style="--label-number: '3'"><v-icon>edit</v-icon></v-btn>
        </div>
      </data-table>
    </v-card>
    <div class="text-xs-right">
      <v-btn color="error" flat @click="deleteEvent" :disabled="selectedEvents.length === 0" class="tutorial-element label-left" style="--label-number: '2'">
        <v-icon left>remove_circle_outline</v-icon>{{ $tc('delete-event', selectedEvents.length, [selectedEvents.length]) }}
      </v-btn>
      <v-btn color="success" flat @click="createEvent" class="tutorial-element label-right" style="--label-number: '1'">
        <v-icon left>add_circle_outline</v-icon>{{ $t('create-event') }}
      </v-btn>
    </div>
  </div>
</template>

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

export default {
  name: 'EventModuleEventList',
  components: {
    DataTable
  },
  data () {
    return {
      selectedEvents: []
    }
  },
  computed: {
    headers () {
      return [
        { text: this.$t('id'), key: 'id', width: '50px' },
        { text: this.$t('name'), key: 'name' },
        { text: this.$t('description'), key: 'description' },
        { text: this.$t('config'), key: 'configName' },
        { sortable: false, key: 'action', width: '60px' }
      ]
    },
    ...mapState('events', ['events'])
  },
  methods: {
    ...mapMutations('events', ['setDialog']),
    createEvent () {
      this.setDialog({ show: true, type: 'edit', info: {} })
    },
    deleteEvent () {
      this.setDialog({ show: true, type: 'delete', info: this.selectedEvents })
    },
    editEvent (event) {
      this.setDialog({ show: true, type: 'edit', info: event })
    }
  }
}
</script>

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

</style>
