<template>
  <div>
    <div class="text-left label"><label :for="`cpf-${getId}`">CPF:</label></div>
    <the-mask
      :id="`cpf-${getId}`"
      type="tel"
      class="form-control radius-theme"
      mask="###.###.###-##"
      placeholder="123.456.789-00"
      v-model.trim="getCurrentValue"
      :disabled="disabled"
    />
    <div class="text-left" v-show="error">
      <small class=" pt-2 text-danger" >Por favor, insira um CPF válido.</small>
    </div>
  </div>
</template>

<script>

import { validationCPF} from '@/utils/validation.js'

export default {
  name: 'cpf',
  props: {
    cpf: {
      type: String,
      // required: true,
    },
    disabled:{
      type: Boolean,
      default: false
    },
    submit:{
      type: Boolean,
      default: false
    }
  },
  model: {
    prop: 'cpf',
    event: 'change',
  },
  computed: {
    error(){
      return this.submit && !validationCPF(this.getCurrentValue);
    },
    getCurrentValue: {
      get() {
        return this.cpf;
      },
      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>
