<script>
export default {
  props: {
    state: {type: String, default: ''},
    format: {type: [String, Array], default: ''},
    form: {type: Boolean, default: false},
    size: {type: String, default: 'md'},
    value: {default: ''},
    placeholder: {type: String, default: ''},
    is_error: {type: Boolean, default: false},
    options: {type: Array, default: ({})},
  },
  data() {
    return {
      input_class: "form-control",
      disabled: false,
      readonly: false,
      localValue: ""
    }
  },


  watch: {
    is_error: function () {
      this.generateInputClass()
    },

    form: function () {
      this.generateInputClass()
    },

    state: function () {
      this.generateStateInputField()
    },

    value: function () {
      this.localValue = this.value
    }
  },

  mounted() {
    this.generateStateInputField()
  },

  methods: {
    updateValue(value) {
      this.$emit('input', (value) ? value : '')
    },

    convertSizeToClass(size) {
      switch (size) {
        case  'md' :
          return 'form-control'
          break;
        case  'sm' :
          return 'form-control-sm'
          break;
        case  'lg' :
          return 'form-control-lg'
          break;
        default:
          return "form-control"
      }
    },

    generateInputClass() {
      this.input_class = this.convertSizeToClass(this.size)
    },

    generateStateInputField() {
      switch (this.state) {
        case 'readonly' :
          this.readonly = true
          this.disabled = false
          return
        case 'disabled' :
          this.readonly = true
          this.disabled = true
          return
        default :
          this.readonly = false
          this.disabled = false
          return
      }
    },

  }
}
</script>
<template>
  <b-form-radio-group v-model="localValue" @change="updateValue">
    <b-form-radio v-for="(list, index) in options" :value="list.value" :key="index"
                  :disabled="(list.disabled) ? true : false">
      {{ list.text }}
    </b-form-radio>
  </b-form-radio-group>

</template>
