import 'uno.css';
import '@/design/index.less';
import 'ant-design-vue/dist/reset.css';
// Register icon sprite
import 'virtual:svg-icons-register';

import { createApp } from 'vue';

import { setupGlobDirectives } from '@/directives';
import { setupI18n } from '@/locales/setupI18n';
import { setupErrorHandle } from '@/logics/error-handle';
import { initAppConfigStore } from '@/logics/initAppConfig';
import { router, setupRouter } from '@/router';
import { setupRouterGuard } from '@/router/guard';
import { setupStore } from '@/store';

import App from './App.vue';

import ElementPlus from 'element-plus';
import 'element-plus/theme-chalk/index.css';
import VForm3 from '@/../lib/vform/designer.umd.js';
import '../lib/vform/designer.style.css';

import Antd from 'ant-design-vue';
import { signal } from './utils/signalR';
// 新增
// 引入全局样式
import '@/styles/pages/index.scss';
// 引入动画
import 'animate.css/animate.min.css';
// 引入标尺
import 'vue3-sketch-ruler/lib/style.css';
import uimIcons from '@iconify/json/json/uim.json';
import lineMdIcons from '@iconify/json/json/line-md.json';
import wiIcons from '@iconify/json/json/wi.json';
import { addCollection } from 'iconify-icon';
import { setupNaive, setupDirectives, setupCustomComponents, initFunction } from '@/plugins';
import { i18n } from '@/i18n';

// 注册图标
addCollection(uimIcons);
addCollection(lineMdIcons);
addCollection(wiIcons);
async function bootstrap() {
  const app = createApp(App);
  app.use(Antd);
  // 语言注册
  app.use(i18n);
  // 在Vue应用挂载后绑定$t到window对象
  app.config.globalProperties.$t = i18n.global.t;
  window['$t'] = i18n.global.t;
  // 注册全局常用的 naive-ui 组件
  setupNaive(app);

  // 注册全局自定义指令
  setupDirectives(app);

  // 注册全局自定义组件
  setupCustomComponents(app);
  // Configure store
  // 配置 store
  setupStore(app);

  // Initialize internal system configuration
  // 初始化内部系统配置
  initAppConfigStore();

  // Multilingual configuration
  // 多语言配置
  // Asynchronous case: language files may be obtained from the server side
  // 异步案例：语言文件可能从服务器端获取
  await setupI18n(app);

  // Configure routing
  // 配置路由
  setupRouter(app);

  // router-guard
  // 路由守卫
  setupRouterGuard(router);

  // Register global directive
  // 注册全局指令
  setupGlobDirectives(app);

  // Configure global error handling
  // 配置全局错误处理
  setupErrorHandle(app);

  // https://next.router.vuejs.org/api/#isready
  // await router.isReady();

  app.use(ElementPlus);
  app.use(VForm3);
  app.use(signal);
  app.mount('#app');
  // 挂载到 window
  window['$vue'] = app;
}

bootstrap().then(() => {
  initFunction();
});
