import AdmVue from '@assets/js/adm-vue';
import axiosApi from '@assets/js/axios-api';
import param from '@assets/js/param';

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

const vm = new AdmVue({
  components: {
    BaseTabs: () => import(/* webpackChunkName: "BaseTabs" */ '@components/BaseTabs/index.vue'),
    BaseCard: () => import(/* webpackChunkName: "BaseCard" */ '@elements/BaseCard/index.vue'),
    BaseInput: () => import(/* webpackChunkName: "BaseInput" */ '@elements/BaseInput/index.vue'),
    BaseButton: () => import(/* webpackChunkName: "Basebutton" */ '@elements/BaseButton/index.vue'),
  },
  data() {
    return {
      tabs: [
        { text: 'Geral', active: true },
        { text: 'Status do Pagamento', active: false },
        { text: 'Configurações Avançadas', active: false },
      ],
      configurations: {},
      pixpdv_account_info: false,
      loading: false,
    }

  },
  methods: {
    //requests
    async getAccountInfo(errors) {
      this.$refs.provider.validate();
      if (errors[0] || 
          !this.configurations.pixpdv_account_info.cnpj || 
          !this.configurations.pixpdv_account_info.token || 
          !this.configurations.pixpdv_account_info.secret) return;
      this.loading = true;
      await axiosApi({
        method: 'POST',
        url: BASE_URL + 'admin/index.php?route=payment/pixpdv/getAccountInfo&token=' + this.token,
        data: param({ 
            cnpj: this.configurations.pixpdv_account_info.cnpj,
            token: this.configurations.pixpdv_account_info.token,
            secret: this.configurations.pixpdv_account_info.secret
         }),
      })
        .then(({ data }) => {
          if (data && !data.erros) {
            this.configurations.pixpdv_account_info.cnpj = data.data.cnpj;
            notificationMsg('Verificação realizada com sucesso!', 'success');
          } else {
            notificationMsg(data.erros, 'warning');
          }
          this.loading = false;
        })
        .catch(err => {
            console.log(err, err.response);
            this.loading = false;
            notificationMsg('Ocorreu um erro na requisição.', 'warning');
        });
    },
  },
  mounted() {
  }
});

AdmVue.init(vm);