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/index.scss' // global css

import App from './App'
import store from './store'
import router from './router'
import './public-path';
import VueRouter from 'vue-router';

import './icons' // icon
import './permission' // permission control

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

import permission from '@/directive/permission/index.js' // 权限判断指令

import Print from '@/utils/print' // 打印
Vue.use(Print)

import ZkTable from 'vue-table-with-tree-grid'
Vue.use(ZkTable)

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

Vue.directive('permission', permission)

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

Element.Table.props.stripe={type:Boolean,default:true}

Vue.config.productionTip = false

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

let instance = null;
let routers = null;
function render(props = {}) {
   
  //这里处理权限
  const { container } = props;
  routers = new VueRouter({
    base: window.__POWERED_BY_QIANKUN__ ? '/jzmall' : '/',
    mode: 'history',
    router,
  });

  instance = new Vue({
    router,
    store,
    data(){
      return {
        parentStore: props.parentStore,
      }
    },
    render: (h) => h(App),
  }).$mount(container ? container.querySelector('#app-mall') : '#app-mall'); 

}

// 独立运行时
if (!window.__POWERED_BY_QIANKUN__) {
  console.info('render')
  render();
}

export async function bootstrap() {
  console.log('[vue] vue app bootstraped');
}
export async function mount(props) {
  console.log('[vue] props from main framework', props);
  render(props);
}
export async function unmount() {
  instance.$destroy();
  instance.$el.innerHTML = '';
  instance = null;
}
