<template>
  <div>
    <div class="text-left label"><label :for="`date-${getId}`">{{ title }}</label></div>
    <b-form-input
      :id="`date-${getId}`"
      type="text"
      :disabled="disabled"
      class="form-control radius-theme"
      placeholder="20/01/2019"
      v-model.trim="getCurrentValue"
      v-mask="'##/##/####'"
    />
    <div class="text-left" v-show="error">
      <small class=" pt-2 text-danger" >Data inválida.</small>
    </div>
  </div>
</template>

<script>

import moment from 'moment'
import {validationDate} from '@/utils/validation'
export default {
  name: 'date',
  props: {
    currentDate: {
      type: String,
      required: true,
    },
    title: {
      type: String,
      default: 'Data de Nascimento:',
    },
    submit: {
      type: Boolean,
      default: false
    },
    disabled: {
      type: Boolean,
      default: false
    }
  },
  model: {
    prop: 'currentDate',
    event: 'change',
  },
  computed: {
    error(){

      return this.submit && !validationDate(this.getCurrentValue);
    },
    getCurrentValue: {
      get() {
        return this.currentDate;
      },
      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>
