<template>
  <div class="text-center">
    <v-dialog v-model="show" width="250">
      <v-card>
        <DialogHeading title="Model Info" @hide="show = false" />

        <v-card-text class="pt-2 pb-0">
          <v-text-field v-model="name" label="Name" required/>
          {{ modelMaterialCount }} {{ modelMaterialCount | pluralize('material') }}
        </v-card-text>

        <v-card-actions>
          <v-spacer/>
          <v-btn
            color="primary"
            small
            class="black--text mb-2"
            @click="show = false">OK</v-btn>
          <v-spacer/>
        </v-card-actions>
      </v-card>
    </v-dialog>
  </div>
</template>

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

export default {
  components: {
    DialogHeading,
  },
  props: {
    value: Boolean,
  },
  data: () => ({
  }),
  computed: {
    show: {
      get() {
        return this.value
      },
      set(value) {
        this.$emit('input', value)
      }
    },

    name: {
      get() {
        var model = this.selectedModel()
        return model ? model.name : '(none)'
      },
      set(value) {
        var section = this.selectedSection()
        var model = this.selectedModel()
        this.setModelName({ section: section, model: model, name: value })
      }
    },

    modelMaterialCount() {
      let model = this.selectedModel()
      if (model) {
        return model.ids.length
      }
      return 0
    },
  },

  methods: {
    ...mapGetters([
      'selectedSection',
      'selectedModel',
    ]),
    ...mapActions([
      'setModelName',
    ]),
  },
}
</script>

<style>

</style>
