import './assets/main.css'
import './publice-path'
import { createApp } from 'vue'
import App from './App.vue'
import router from './router'
import {
  renderWithQiankun,
  qiankunWindow
} from 'vite-plugin-qiankun/dist/helper'



let instance: any = null;
function render(props: any = null) {
  instance = createApp(App);
  instance.use(router)
  instance.mount(props ? props.container.querySelector('#app') : '#app')
}

// 独立运行时
if (!qiankunWindow.__POWERED_BY_QIANKUN__) {
  const token =
    "Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiI0NTRkYWMxMy1jZjVmLTQ3MTgtOWQ4MC00MjM5MzM5YWVhZDUiLCJhdXRoIjoxLCJiYXNlIjoxLCJvcmciOjEsImlhdCI6MTY5NTA5MDAwNiwiZXhwIjoxNjk1Njk0ODA2fQ.-ub4h04wpIY227ZJbamtuTv_XUjNG7YdX7VN6nMO4W4";
  localStorage.setItem('token', JSON.stringify(token));
  render();
  console.log('独立运行');
}

// 抛出qiankun执行依赖----------START
renderWithQiankun({
  mount(props) {
    console.log(router);
    console.log(props)
    render(props)
  },
  bootstrap() {
    // console.log(props, 'aaaaaaaaaaaaaa');
    console.log('bootstrap')
  },
  unmount(props) {
    console.log(props)
    instance.unmount()
    instance._container.innerHTML = ''
    router.options.history.destroy() // 不卸载  router 会导致其他应用路由失败
    // history.destroy() // 不卸载  router 会导致其他应用路由失败
    instance = null
  },
  update() { }
})