import Vue from 'vue'
import VueResource from 'vue-resource'
import Buefy from 'buefy'
import Gravatar from 'vue-gravatar'
import config from '../config.json'
import VueMoment from 'vue-moment'
import moment from 'moment'
import { mixinDefault } from '../../mixins/mixin-default'
// import {booleano, truncate, cep, cpfcnpj, numero, telefone} from './constantes'
// import { isMobile } from 'mobile-device-detect';
import VeeValidate, {Validator} from 'vee-validate'
import ptBR from 'vee-validate/dist/locale/pt_BR'
import es from 'vee-validate/dist/locale/es'

// Vue.filter('booleano', booleano)
// Vue.filter('truncate', truncate)
// Vue.filter('cep', cep)
// Vue.filter('cpfcnpj', cpfcnpj)
// Vue.filter('numero', numero)
// Vue.filter('telefone', telefone)

let locale = localStorage.language || navigator.language

switch (locale) {
  case 'pt': Validator.localize('pt_BR', ptBR); break;
  case 'es': Validator.localize('es', es); break;
}

moment.locale((locale === 'pt')? 'pt-BR' : locale)

Vue.use(VueResource)
Vue.use(VueMoment, {moment})
Vue.use(Buefy, config.buefy)
Vue.use(VeeValidate, { delay: '5' })

const BaseComponents = {
  install (Vue, options) {
    // Vue.prototype.$clonar = (obj) => JSON.parse(JSON.stringify(obj))
    Vue.prototype.$menu = options.menu
    Vue.prototype.$URL = process.env.VUE_APP_API_GATEWAY_ADDRESS
    Vue.prototype.$APP = {
      name: process.env.VUE_APP_NAME,
      version: process.env.VUE_APP_VERSION
    }
    Vue.prototype.$events = options.events
    Vue.prototype.$isMobile = true ///isMobile

    Vue.mixin(mixinDefault)

    Vue.component('Error404', () => import('../components/Error404.vue'))
    Vue.component('Error403', () => import('../components/Error403.vue'))
    Vue.component('LeanispApp', () => import('../components/App.vue'))
    Vue.component('LeanispTitle', () => import('../components/Title.vue'))
    Vue.component('LeanispEmpty', () => import('../components/Empty.vue'))
    Vue.component('LeanispList', () => import('../components/List.vue'))
    Vue.component('LeanispDialogForm', () => import('../components/DialogForm.vue'))
    Vue.component('LeanispDetail', () => import('../components/Detail.vue'))
    Vue.component('LeanispTag', () => import('../components/Tag.vue'))
    Vue.component('LeanispDetailObject', () => import('../components/DetailObject.vue'))
    Vue.component('LeanispEventList', () => import('../components/EventList.vue'))

    Vue.component('LeanispTableFieldView', () => import('../components/TableFieldView.vue'))
    Vue.component('LeanispTableFieldViewItem', () => import('../components/TableFieldViewItem.vue'))
    Vue.component('LeanispFieldView', () => import('../components/FieldView.vue'))

    Vue.component('LeanispInputTag', () => import('../components/InputTag.vue'))
    Vue.component('LeanispInputCustomField', () => import('../components/InputCustomField.vue'))
    Vue.component('LeanispDetailCustomField', () => import('../components/DetailCustomField.vue'))

    Vue.component('v-gravatar', Gravatar)
  }
}

export default BaseComponents