require('./bootstrap');
window.$ = window.jQuery = require('jquery');
window.Vue = require('vue').default;
window.FormMixin  = require("./FormMixin").default ;
window.DestroyMixin  = require("./DestroyMixin").default ;
window.FetchMixin  = require("./FetchMixin").default ;
import vSelect from 'vue-select'

Vue.component('v-select', vSelect)
Vue.component('admin-menu', require('./components/Menu.vue').default);
Vue.component('account', require('./components/Account.vue').default);
Vue.component('notif', require('./components/Notif.vue').default);
Vue.component('log-activity', require('./components/LogActivity.vue').default);

import i18n ,{fetchMessages} from './i18n'

Vue.mixin({
    i18n,
    data() {
        return {
            table: '',
        }
    },
    methods: {
        reload(){
          window.LaravelDataTables[this.table].ajax.reload();
        },
        formatPrice: function(price,currency){
            if(!currency)currency  = !this.cota?this.auth.account.currency_code:this.cota.currency_code;
            return new Intl.NumberFormat('en', { style: 'currency', currency: currency }).format(price/100);
        },
        error: function(error) {
            var msg = error;
            this.removeLoading();
            if(error.response){
                msg = error.response.status+': '+error.response.data.message;
            }
            toastr.error(msg);
        },
        success: function(message=this.$t("Task was successful")) {
            this.removeLoading();
            toastr.success(message);
        },
        removeLoading(){
          var btn = $('.link-submit');
          btn.find('.spinner-border').addClass('d-none');
          btn.attr("disabled", false);
        }
    }
});


fetchMessages(document.documentElement.lang);

