<template>
  <v-row justify="center">
    <v-dialog v-model="show" max-width="300">
      <v-card>
        <DialogHeading title="Delete Section" @hide="show = false" />

        <v-card-text class="pt-4 pb-2">
          Really delete catalog section?
          <div class="subheading black--text font-weight-medium mt-2">
            {{ name }}
          </div>
        </v-card-text>

        <v-card-actions>
          <v-spacer/>
          <v-btn
            small
            class="mb-2"
            @click="show = false">Cancel</v-btn>
          <v-btn
            color="primary"
            class="black--text ml-4 mb-2"
            small
            @click="doDelete()">OK</v-btn>
          <v-spacer/>
        </v-card-actions>
      </v-card>
    </v-dialog>
  </v-row>
</template>

<script>
import DialogHeading from './DialogHeading'
import { mapGetters, mapActions } from 'vuex'

export default {
  components: {
    DialogHeading,
  },
  props: {
    value: Boolean,
    section: {
      type: Number,
      required: false,
      default: null,
    }
  },
  data: () => ({
  }),
  computed: {
    show: {
      get() {
        return this.value
      },
      set(value) {
        this.$emit('input', value)
      }
    },
    name: {
      get() {
        let section = this.selectedSection()
        return section ? section.name : '(none)'
      }
    }
  },
  methods: {
    doDelete() {
      this.deleteSection(this.selectedSection())
      this.show = false
    },
    ...mapGetters([
      'selectedSection',
    ]),
    ...mapActions([
      'deleteSection',
    ]),
  },
}
</script>

<style>

</style>
