<i18n>
{
  "en": {
    "title": "Delete this config? | Delete these {0} configs?"
  },
  "de": {
    "title": "Diese Konfiguration löschen? | Diese {0} Konfigurationen löschen?"
  }
}
</i18n>

<template>
  <v-card>
    <v-card-title class="dialog-title elevation-3">
      <div class="headline">{{ $tc('title', dialog.info.selected.length, [dialog.info.selected.length]) }}</div>
    </v-card-title>
    <v-card-text style="height: 100%">
      <div v-for="item in dialog.info.selected" class="grey--text" :key="item.id">[{{ item.id }}] {{ item.name }}</div>
    </v-card-text>
    <v-divider></v-divider>
    <v-card-actions>
      <v-spacer></v-spacer>
      <v-btn flat="flat" @click="setDialog({ show: false })">{{ $t('cancel') }}</v-btn>
      <v-btn color="error" @click="deleteItems">{{ $t('delete') }}</v-btn>
    </v-card-actions>
  </v-card>
</template>

<script>
import { mapState } from 'vuex'

export default {
  name: 'ConfiguratorModuleDelete',
  data () {
    return {
    }
  },
  computed: {
    ...mapState('configurator', ['dialog'])
  },
  methods: {
    setDialog (data) {
      this.$store.commit('configurator/setDialog', data)
    },
    async deleteItems () {
      await this.$http.post('/api/configurator/' + this.dialog.info.itemType + '/?delete', {
        ids: this.dialog.info.selected.map(x => x.id)
      })
      this.$store.dispatch('configurator/loadData')
      this.setDialog({ show: false })
    }
  }
}
</script>

<!-- Add "scoped" attribute to limit CSS to this component only -->
<style scoped>
.dialog-title {
  z-index: 1;
}
.selected-list {
  padding: 30px;
}
</style>
