import { createI18n } from "vue-i18n";
import { getBrowserLang } from "@/utils";

import zh from "./modules/zh-cn";
import en from "./modules/en";
import zhCN from "vxe-table/lib/locale/lang/zh-CN";
import enUS from "vxe-table/lib/locale/lang/en-US";

const messages = {
  "zh-cn": { ...zh, ...zhCN },
  en: {
    ...en,
    ...enUS
  }
};

// const defaultLocal = await import.meta.glob(`./modules/*.ts`, { eager: true });
// const message = defaultLocal.default?.message ?? {};

// console.log("defaultLocal :>> ", defaultLocal);
// console.log("message :>> ", message);

// const messages: any = {};

// const files: Record<string, any> = await import.meta.glob(`./modules/*.ts`, { eager: true });

// console.log("files :>> ", files);

// Object.keys(files).forEach(c => {
//   const module = files[c].default;
//   const moduleName = c.replace(/^\.\/(.*)\/(.*)\.\w+$/, "$2");
//   messages[moduleName] = module;
// });

const i18n = createI18n({
  // Use Composition API, Set to false
  allowComposition: true,
  legacy: false,
  locale: getBrowserLang(),
  messages
});

export default i18n;
