<template>
  <div>
    <div class="text-left label"><label :for="`postal-code-${getId}`">{{ title }}</label></div>
    <the-mask
      :id="`postal-code-${getId}`"
      type="tel"
      class="form-control radius-theme"
      mask="##.###-###"
      placeholder="74.000-000"
      v-model.trim="getCurrentValue"
    />
    <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: 'postal-code',
  props: {
    cep: {
      type: String,
      required: true,
    },
    title: {
      type: String,
      default: 'CEP:',
    },
    submit: {
      type: Boolean,
      default: false,
    }
  },
  model: {
    prop: 'cep',
    event: 'change',
  },
  computed: {
    error(){
      return this.submit && this.getCurrentValue.length == 0;
    },
    getCurrentValue: {
      get() {
        return this.cep;
      },
      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>
