import Vue from 'vue';
import App from './App.vue';
import store from './store';
import router from './router';
import permission from './utils/permission';
import { MAP_KEY, LICENSE_CODE } from '@/config/setting';
import EleAdmin from 'ele-admin';
import i18n from './i18n';
import './styles/index.scss';
import DictSelection from '@/components/Dict/DictSelection';
import { registerMicroApps, start, setDefaultMountApp } from 'qiankun';
import microApps from './micro-app';
// // register globally
import '@/icons';

Vue.component('DictSelection', DictSelection);
Vue.config.productionTip = false;

Vue.use(EleAdmin, {
  response: {
    dataName: 'list'
  },
  mapKey: MAP_KEY,
  license: LICENSE_CODE,
  i18n: (key, value) => i18n.t(key, value)
});
Vue.use(permission);

// new Vue({
//   router,
//   store,
//   i18n,
//   render: (h) => h(App)
// }).$mount('#app');

const instance = new Vue({
  router,
  store,
  i18n,
  render: (h) => h(App)
}).$mount('#app');
console.log(instance.$store, ' mian-store', instance.$store.state);

// 定义loader方法，loading改变时，将变量赋值给App.vue的data中的isLoading
function loader (loading) {
  if (instance && instance.$children) {
    // instance.$children[0] 是App.vue，此时直接改动App.vue的isLoading
    instance.$children[0].isLoading = loading;
  }
}

// 给子应用配置加上loader方法
const apps = microApps.map((item) => {
  return {
    ...item,
    loader
  };
});

registerMicroApps(apps, {
  beforeLoad: (app) => {
    console.log('before load app.name====>>>>>', app.name);
  },
  beforeMount: [
    (app) => {
      console.log('[LifeCycle] before mount %c%s', 'color: green;', app.name);
    }
  ],
  afterMount: [
    (app) => {
      console.log('[LifeCycle] after mount %c%s', 'color: green;', app.name);
    }
  ],
  afterUnmount: [
    (app) => {
      console.log('[LifeCycle] after unmount %c%s', 'color: green;', app.name);
    }
  ]
});
// setDefaultMountApp('/main-data');
start();
