<template>
  <div>
    <div class="text-left label">
      <label :for="`text-input-${getId}`">{{ title }}</label></div>

    <b-form-input
      :id="`text-input-${getId}`"
      class="radius-theme"
      :type="inputType"
      :disabled="disabled"
      :required="required"
      :placeholder="placeHolder"
      v-model.trim="getCurrentValue"
      @blur.native="$emit('blur')"
    ></b-form-input>

    <div class="text-left" v-show="error">
      <small class=" pt-2 text-danger" >Por favor, preencha este campo.</small>
    </div>
  </div>
</template>

<script>
export default {
  name: 'text-input',
  props: {
    textInput: {
      type: String,
    },
    title: {
      type: String,
      required: true,
    },
    placeHolder: {
      type: String,
      default: '',
    },
    inputType: {
      type: String,
      default: 'text',
    },
    submit:{
      type: Boolean,
      default: false
    },
    disabled:{
      type: Boolean,
      default: false
    },
    required:{
      type: Boolean,
      default: false
    }
  },
  model: {
    prop: 'textInput',
    event: 'change',
  },
  computed: {
    error(){
      return this.submit && this.getCurrentValue.length == 0;
    },
    getCurrentValue: {
      get() {
        return this.textInput;
      },
      set(value) {
        this.$emit('change', value);
      },
    },
    getId() {
      return Math.floor(Math.random() * 100);
    },
  },
};
</script>

<style scoped lang="scss">
@import '../../../assets/css/main.scss';
@import '../../../assets/css/cards.scss';
</style>
