import App from './App'
import _extends from './_extends'
import store from './store'
import 'normalize.css/normalize.css' // a modern alternative to CSS resets
import './styles/element-variables.scss'
import './styles/index.scss' // global css
import { initRouter, default as router } from './router'
import Vue from 'vue'
import i18n from './lang'
import './permission'
import './icons' // icon
import './utils/error-log' // error log

export const VERSION = process.env.VERSION

export function register(globalOptions) {
  globalOptions = Object.assign(
    {
      // 绑定节点
      el: '#app',
      // window键值
      currentAppKey: '__currentApp',
      // 路由
      router: {
        routes: []
      },
      // vuex store
      store: {
        state: {},
        getters: {},
        mutations: {},
        actions: {}
      },
      // 系统信息
      sysInfo: {}
    },
    globalOptions
  )
  // 添加状态管理模块
  if (globalOptions.store) {
    store.registerModule('custom', globalOptions.store)
  }
  _extends.register()
  if (globalOptions.el) {
    window[globalOptions.currentAppKey] = new Vue({
      router,
      store,
      i18n,
      render: h => h(App)
    }).$mount(globalOptions.el)
  }
  if (typeof window !== 'undefined' && typeof window.Vue === 'undefined') {
    window.Vue = Vue
  }
  // console.log(process.env.VERSION)
  return { router, store }
}
export default {
  register
}
