<template>
  <div>
    <div class="text-left label"><label :for="`gov-agent-${getId}`">{{ title }}</label></div>
    <the-mask
      :id="`gov-agent-${getId}`"
      type="text"
      class="form-control radius-theme"
      mask="FFFFFFFFFFFFFFFF"
      :tokens="tokens"
      placeholder="SSO/GO"
      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: 'gov-agent',
  data :() => ({
    tokens: {
      F: {
        pattern: /[a-zA-Z/-]/,
        transform: v => v.toLocaleUpperCase()
      }
    }
  }),
  props: {
    govAgent: {
      type: String,
      required: true,
    },
    title: {
      type: String,
      default: 'Orgão Emissor:',
    },
    submit: {
      type: Boolean,
      default: false
    },
  },
  model: {
    prop: 'govAgent',
    event: 'change',
  },
  computed: {
    error(){
      return this.submit && this.getCurrentValue.length == 0;
    },
    getCurrentValue: {
      get() {
        return this.govAgent;
      },
      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>
