import { setupGlobalDirectives } from "@/directives";
import { installRouter } from "@/router";
import { installPinia } from "@/stores";
import { installI18n } from "@/utils";
import { createApp } from "vue";
import App from "./App.vue";
import "@/styles/index";
import { ElTableColumn, ElMessage } from "element-plus";
import "element-plus/es/components/base/style/css";
import "element-plus/es/components/table-column/style/css";

async function setupApp() {
  // 创建vue实例
  const app = createApp(App);
  // 注册模块 Pinia
  installPinia(app);
  // 注册模块 Vue-router
  await installRouter(app);
  // 注册全局自定义指令
  setupGlobalDirectives(app);
  // 注册国际化
  installI18n(app);
  // 将 ElMessage 注册为全局的 $message
  app.config.globalProperties.$message = ElMessage;
  // 挂载全局方法 $formatDateTWO
  app.config.globalProperties.$formatDateTWO = function (
    timestamp: string | number | Date
  ) {
    // console.log(timestamp, "formatDateTWO");
    const date = new Date(timestamp);
    const year = date.getFullYear();
    const month = String(date.getMonth() + 1).padStart(2, "0");
    const day = String(date.getDate()).padStart(2, "0");
    const hours = String(date.getHours()).padStart(2, "0");
    const minutes = String(date.getMinutes()).padStart(2, "0");
    // const seconds = String(date.getSeconds()).padStart(2, "0");:${seconds}
    return `${year}-${month}-${day} ${hours}:${minutes}`;
  };
  app.mount("#app");
}

setupApp().then();
