import App from './App.vue';
import { createApp } from 'vue';
import { setupStore } from '@/sheep/store';
import { setupSheep } from '@/sheep';
import { setupRouter } from '@/sheep/router';
// element-plus
import ElementPlus from 'element-plus';
import zhCn from 'element-plus/dist/locale/zh-cn.mjs';

// css reset
import 'normalize.css/normalize.css';

// unocss
import 'uno.css';

// iconify
import '@iconify/iconify';

// mock service
import { startMocking } from '@/sheep/mock';

async function bootstrap() {
  // 启动 Mock 服务（仅在开发环境且启用 Mock 时）
  if (import.meta.env.SHEEP_USE_MOCK === 'true') {
    await startMocking();
  }
  const app = createApp(App);

  // element-plus
  app.use(ElementPlus, { locale: zhCn });

  // pinia store
  setupStore(app);

  // sheepjs init
  await setupSheep(app);

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

  app.mount('#app');

  // 应用加载完成后，延迟一点时间确保页面完全渲染，然后隐藏加载页面
  setTimeout(() => {
    window.dispatchEvent(new Event('app-loaded'));
  }, 500);
}

bootstrap();
