import AdmVue from '@assets/js/adm-vue.js';
import initVue from '@assets/js/initVue.js';
import axiosApi from '@assets/js/axios-api';
import formMixin from '@assets/components/mixins/formMixin';

const BASE_URL = document.getElementById('base-urls').dataset.baseUrlLoja;

const vm = new AdmVue({
  components: {
    BaseCard: () => import(/* webpackChunkName: "BaseCard" */ '@elements/BaseCard/index.vue'),
    BaseModal: () => import(/* webpackChunkName: "BaseModal" */ '@components/BaseModal/index.vue'),
  },
  data() {
    return {
      celular: '',
      pessoa: '',
    };
  },
  mounted() {
    const isPessoaJuridica = this.fields_register_brazil_tipo_de_pessoa == this.Type_CadastroPessoa.Tp_Juridico;
    this.pessoa = isPessoaJuridica ? 'J' : 'F';

    if (typeof success != 'undefined') {
      this.alert = {
        type: 'success',
        message: success,
      };
    }

    if (typeof warning != 'undefined') {
      this.alert = {
        type: 'error',
        message: warning,
      };
    }

  },
  updated() {},
  computed: {
    sendData() {
      return Object.assign(
        {
          celular: this.celular,
        }
      );

    },
  },
  methods: {
    goToError() {
      setTimeout(() => {
        const errorInput = document.querySelector('.field-error');
        if (errorInput) {
          window.scrollTo(0, errorInput.offsetTop);
        }
      }, 400);
    },
    formError({ errors }) {
      this.$refs.validationObserver.setErrors(errors);
      this.goToError();
    },
    onSubmit() {
      formMixin.methods.onSubmit.call(this);
    },
    handleSubmitForm() {
      this.$refs.validationObserver.validate().then(valid => {
        if (valid) {
          this.onSubmit();
        } else {
          this.goToError();
        }
      });
    },
    parseBoolean(value) {
      return Boolean(Number(value));
    },
  },
});

initVue(vm);
