import './publice-path'
import { createApp, reactive } from 'vue';
import App from './App.vue';
import router from './router';
import store from './store';
import './assets/styles/index.less';
import './assets/iconfont/iconfont.css';


let instance: any = null;



function render(props: any = null) {
  instance = createApp(App);
  const token = JSON.parse(localStorage.getItem("token") || '')
  instance.config.globalProperties.$globalVariable = reactive({
    token,
    baseUrl: process.env.VUE_APP_BASE_URL,
    resourceBaseUrl: `${process.env.VUE_APP_BASE_URL}/file-bucket`,
  });
  instance.use(store).use(router);
  instance.mount(props ? props.container.querySelector('#app') : '#app')
}
// 独立运行时
if (!window.__POWERED_BY_QIANKUN__) {
  const token =
    "Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiI0NTRkYWMxMy1jZjVmLTQ3MTgtOWQ4MC00MjM5MzM5YWVhZDUiLCJhdXRoIjoxLCJiYXNlIjoxLCJvcmciOjEsImlhdCI6MTY5NTA5MDAwNiwiZXhwIjoxNjk1Njk0ODA2fQ.-ub4h04wpIY227ZJbamtuTv_XUjNG7YdX7VN6nMO4W4";
  localStorage.setItem('token', JSON.stringify(token));
  render();
  console.log('独立运行');
}

// 抛出qiankun执行依赖----------START
export async function bootstrap() {
  console.log('[vue] vue app bootstraped');
}
// 加载
export async function mount(props: any) {
  render(props);
}
// 注销
export async function unmount() {
  instance?.$destroy?.();
  instance && instance.$el && (instance.$el.innerHTML = '')
  instance = null;
}
// 抛出qiankun执行依赖----------END
