<i18n>
{
  "en": {
  },
  "de": {
  }
}
</i18n>

<template>
  <v-dialog :value="editDialog" @input="setEditDialog" max-width="600px">
    <v-card>
      <div class="input-fields">
        <v-text-field v-model="name" label="Name" box color="primary"></v-text-field>
      </div>
      <div class="action-buttons text-xs-right">
        <v-btn flat @click="$emit('close')">Cancel</v-btn>
        <v-btn color="primary" @click="saveData">Save</v-btn>
      </div>
    </v-card>
  </v-dialog>
</template>

<script>
import { mapState, mapMutations } from 'vuex'

export default {
  name: 'GroupModuleEditDialog',
  props: ['id', 'client'],
  data () {
    return {
      name: ''
    }
  },
  computed: {
    ...mapState('groups', ['editDialog'])
  },
  methods: {
    ...mapMutations('groups', ['setEditDialog']),
    loadData () {
      if (!this.id) return
      if (this.client) {
        // TODO
      } else {
        this.$http('/api/groups?action=getInfo&id=' + this.id).then(response => {
          this.name = response.data.name
        })
      }
    },
    saveData () {
      if (this.client) {
        // TODO
      } else {
        this.$http.post('/api/groups', {
          action: 'setInfo',
          id: this.id,
          name: this.name
        }).then(response => {
          console.log(response)
        })
      }
      this.$emit('close')
      this.$emit('reload')
    }
  },
  created () {
    this.loadData()
  }
}
</script>

<!-- Add "scoped" attribute to limit CSS to this component only -->
<style scoped>
.input-fields {
  padding: 40px;
  padding-bottom: 0;
}

.action-buttons {
  padding: 10px;
}

</style>
