// import 'babel-polyfill'
import './public-path'

import Vue from 'vue'

import Cookies from 'js-cookie'

import 'normalize.css/normalize.css' // a modern alternative to CSS resets

import Element from 'element-ui'
import './styles/element-variables.scss'

import '@/styles/admin-lte/adminlte.min.css' // global css

import 'font-awesome/css/font-awesome.min.css'

import '@/styles/index.scss' // global css

import App from './App'
import store from './store'
import router from './router'

import './icons' // icon
import './permission' // permission control
import './utils/error-log' // error log

import * as filters from './filters' // global filters

import echarts from 'echarts'
/**
 * If you don't want to use mock-server
 * you want to use MockJs for mock api
 * you can execute: mockXHR()
 *
 * Currently MockJs will be used in the production environment,
 * please remove it before going online ! ! !
 */
//  if (process.env.NODE_ENV === 'production') {
//   const { mockXHR } = require('../mock')
//   mockXHR()
// }
Vue.prototype.$echarts = echarts

import VueKonva from 'vue-konva'

Vue.use(VueKonva)

Vue.use(Element, {
  size: Cookies.get('size') || 'medium' // set element-ui default size
})

import PermissionPlugin from './plugins/PermissionPlugin'
Vue.use(PermissionPlugin)

// register global utility filters
Object.keys(filters).forEach(key => {
  Vue.filter(key, filters[key])
})

Vue.config.productionTip = false

// new Vue({
//   el: '#app',
//   router,
//   store,
//   render: h => h(App)
// })

// let router = null;
let instance = null
function render(props = {}) {
  // const { container } = props
  // const router = new VueRouter({
  //   // histroy模式的路由需要设置base，app-history-vue根据项目名称来定
  //   base: window.__POWERED_BY_QIANKUN__ ? '/core' : '/',
  //   mode: 'history',
  //   // hash模式不需要上面两行
  //   routes: []
  // })
  instance = new Vue({
    router,
    store,
    data() {
      return {
        parentRouter: props.router,
        parentVuex: props.store
      }
    },
    render: h => h(App)
  }).$mount('#gridererectionApp')
}

// 全局变量来判断环境，独立运行时
if (!window.__POWERED_BY_QIANKUN__) {
  render()
}

export async function bootstrap() {
  console.log('emp-grider-erection模块启动')
  store.dispatch('app/enableLayout', false)
}
export async function mount(props) {
  console.log('props from main framework', props)
  render(props.data)
}
export async function unmount() {
  instance.$destroy()
  instance.$el.innerHTML = ''
  instance = null
  // router = null;
}
