import formMixin from '@mixins/formMixin';
import axios from "axios";
import AdmVue from "@assets/js/adm-vue";
import initVue from "@assets/js/initVue";

const vm = new AdmVue({
  components: {
    BaseAlert: () => import(/* webpackChunkName: "BaseAlert" */ '@elements/BaseAlert/index.vue'),
  },
  data() {
    return {
      alert: {},
      btnSubmitLoading: false,
      disableForm: false,
      configurations: {},
    };
  },
  mixins: [formMixin],
  mounted() {
    this.isLoading = false;
  },
  methods: {
    onSubmit() {
      const form = this.$refs.form;
      const url = form.action;
      const data = new FormData(form);

      axios({
        method: 'post',
        url,
        data,
      }).then(({ data }) => {
        if (data.errors) {
          this.$refs.validationObserver.setErrors(data.errors);
        }else{
          this.alert = {
            type: 'success',
            message: data.success,
          };
        }
      });
    }
  },
});

initVue(vm);
