<i18n>
{
  "en": {
    "setPassword": "Set"
  },
  "de": {
    "setPassword": "Setzen"
  }
}
</i18n>
<template>
  <div>
    <template v-for="element in elements">
      <v-text-field
        v-if="element.type === 'text'"
        :label="element.name"
        :key="element.id"
        v-model="element.value"
        :prepend-icon="element.icon"
      ></v-text-field>

      <div v-else-if="element.type === 'password'" :key="element.id">
        <v-layout>
          <v-text-field
            :disabled="element.disabled === undefined ? init(element) : element.disabled"
            :ref="element.id"
            :label="element.name"
            :key="element.id"
            :append-icon="element.show ? 'visibility_off' : 'visibility'"
            :type="element.show ? 'text' : 'password'"
            @click:append="element.show = !element.show"
            v-model="element.value"
            :prepend-icon="element.icon"
          ></v-text-field>
          <v-btn @click="setPassword(element)" flat icon><v-icon color="primary">edit</v-icon></v-btn>
        </v-layout>
      </div>

      <div v-else-if="element.type === 'switch'" :key="element.id">
        <v-switch
          v-model="element.value"
          :label="element.name"
          :key="element.id"
          color="primary"
          :prepend-icon="element.icon"
        ></v-switch>
        <backend-module-edit-dynamic-fields :elements="element.elements" v-if="element.value"/>
      </div>
      <v-select
        menu-props="offsetY"
        v-else-if="element.type === 'select'"
        :items="element.items"
        :label="element.name"
        :key="element.id"
        v-model="element.value"
        :prepend-icon="element.icon"
      ></v-select>
    </template>
  </div>
</template>

<script>
import BackendModuleEditDynamicFields from '@/components/BackendModuleEditDynamicFields'

export default {
  props: ['elements'],
  data () {
    return {
    }
  },
  methods: {
    init (element) {
      element.disabled = true
      element.value = '********'
      return element.disabled
    },
    setPassword (element) {
      element.disabled = !element.disabled
      if (element.disabled) element.value = '********'
      else element.value = ''
    }
  },
  watch: {
  },
  computed: {
  },
  created () {
    this.$options.components['BackendModuleEditDynamicFields'] = BackendModuleEditDynamicFields
  }
}

</script>

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