// The Vue build version to load with the `import` command
// (runtime-only or standalone) has been set in webpack.base.conf with an alias.
import Vue from 'vue'
import FastClick from 'fastclick'
import App from './App'
import Vuex from 'vuex'
import vuexI18n from 'vuex-i18n'
import router from './router/index'

import flexible from './common/ydui.flexible'

import {componentInstall, appStyle} from '../packages/index'

/**
 * 指令
 */
import directives from './scripts/directives'

import filter from './scripts/filter'

/**
 * 组件
 */

import {
  ViewBox,
  Tabbar,
  TabbarItem,
  XHeader,
  Picker,
  PopupHeader,
} from 'vux'

import './scripts/prototype'
import './scripts/vuePlatform'

/**
 * 弹框组件
 */
import hlsPopup from './scripts/hlsPopup'

/**
 * http
 */
import { post, get } from './scripts/hlsHttp'

/** 全局函数hlsUtil**/

import hlsUtil from './scripts/hlsUtil'

/** end**/

if (process.env.CONFIG_ENV === 'uat') {
  const VConsole = require('vconsole')
  new VConsole() // eslint-disable-line
}
Vue.use(componentInstall)
Vue.use(appStyle)
Vue.use(flexible)

Vue.use(directives)

Vue.use(filter)

Vue.use(Vuex)
// Vue.directive('transfer-dom', TransferDom);
Vue.component('x-header', XHeader)
Vue.component('view-box', ViewBox)
Vue.component('tabbar', Tabbar)
Vue.component('tabbar-item', TabbarItem)
Vue.component('PopupHeader', PopupHeader)
Vue.component('picker', Picker)

/** i18n **/
let store = new Vuex.Store({
  modules: {
    i18n: vuexI18n.store,
  },
})
Vue.use(vuexI18n.plugin, store)

Vue.prototype.hlsPopup = window.hlsPopup = hlsPopup
Vue.prototype.$devicePixelRatio = 2

Vue.prototype.$post = post
Vue.prototype.$get = get
let hlsHttp = {
  get: get,
  post: post,
}
Vue.prototype.hlsHttp = window.hlsHttp = hlsHttp

Vue.prototype.hlsUtil = window.hlsUtil = hlsUtil

/**
 * 全局返回上一页面
 * @param index
 */
let routeGo = function (index) {
  if (!index) {
    index = -1
  }
  this.$router.go(index)
}
Vue.prototype.$routeGo = routeGo

let hlsExit = function () {
  if (vum.Platform.isIOS()) {
    cordova.exec(null, null, 'BridgePlugin', 'closeWebView', [])
  } else if (vum.Platform.isIOS()) {
    var dict = {
      'className': 'WebBridge',
      'function': 'close',
      'successCallBack': 'sCallBack',
      'failureCallBack': 'eCallBack',
    }
    HandBridge.postMessage(JSON.stringify(dict))
  }
}
Vue.prototype.$hlsExit = hlsExit

FastClick.attach(document.body)

Vue.config.productionTip = false

vum.$vumPlatform.ready(function () {
  if ((vum.Platform.isAndroid()) || (vum.Platform.isIOS())) {
  }
})

vum.$vumPlatform.registerBackButtonAction(function (e) {
}, 101)

/* eslint-disable no-new */
new Vue({
  data () {
    return {
      pathList: [],
      transitionName: null,
    }
  },
  router,
  watch: { // 监听路由变化
    $route (to, from) {
      document.body.scrollTop = 0
      document.documentElement.scrollTop = 0
    },
  },
  render: h => h(App),
}).$mount('#app-box')