import { createApp } from 'vue';
import App from './App';
import router, { setupRouter } from './router/index';
import dayjs from 'dayjs';
import { setupNaive } from './plugins';
import { setupStore } from './store';
import 'dayjs/locale/zh-cn';
import './styles/index.less';
import './utils/rem';
// import { storage } from './utils/storage';
// import { ACCESS_TOKEN_ADMIN } from './store/mutation-types';
import useErrorLog from './hooks/useErrorLog';

async function setupApp() {
  // 处理token
  // const authLoadNum = sessionStorage.getItem('authLoadNum');
  // const search = location.href.split('??');
  // if (search[1] && authLoadNum !== '1') {
  //   const parse = search[1];
  //   console.log(parse, 'parse');
  //   const result = parseQuery(parse);
  //   if (result.Authorization) {
  //     const ex = 7 * 24 * 60 * 60 * 1000;
  //     storage.set(ACCESS_TOKEN_ADMIN, result.Authorization, ex);
  //     sessionStorage.setItem('authLoadNum', '1');
  //     sessionStorage.setItem('authSource', result.source?.toString() || '');
  //   }
  //   console.log(result, 'result');
  // } else {
  //   sessionStorage.removeItem('authLoadNum');
  //   storage.remove(ACCESS_TOKEN_ADMIN);
  // }
  // app loading
  // const appLoading = createApp(AppLoading);
  // appLoading.mount('#appLoading');
  const app = createApp(App);

  setupNaive(app);

  // store plugin: pinia
  setupStore(app);

  setupRouter(app);

  dayjs.locale('zh-ch');

  // app.use(router);
  await router.isReady();

  // 监听错误信息

  const errorLog = useErrorLog();
  errorLog.startListenErrorLog();

  // mount app

  app.mount('#app');
}

setupApp();
