import { createApp } from "vue";
import App from "./App.vue";
import router, { setupRouter } from "@/router";
import { setupStore } from "@/store";
import { setupNaive, setupNaiveDiscreteApi, setupDirectives } from "@/plugins";

// 样式
import "@/styles/index.scss";

async function appInit() {
  const app = createApp(App);

  // 注册全局常用的 naive-ui 组件
  setupNaive(app);

  // 挂载 naive-ui 脱离上下文的 Api
  setupNaiveDiscreteApi();

  setupDirectives(app);

  // 全局注册 状态管理(store)
  setupStore(app);

  // 挂载路由
  setupRouter(app);

  // 路由准备就绪后挂载APP实例
  await router.isReady();

  const meta = document.createElement("meta");
  meta.name = "naive-ui-style";
  document.head.appendChild(meta);

  // 挂载到页面
  app.mount("#app", true);
}

void appInit();
