import antdLocale from "ant-design-vue/es/locale/en_US";
import { set } from "lodash-es";

import routesAccount from "./en-US/routes/account.js";
import routesBasic from "./en-US/routes/basic.js";
import routesDashboard from "./en-US/routes/dashboard.js";
import routesDemo from "./en-US/routes/demo.js";
import common from "./en-US/common.js";
import component from "./en-US/component.js";
import layout from "./en-US/layout.js";

function genMessage(langs, localeDir) {
  const obj = {};
  langs.keys().forEach((key) => {
    const langFileModule = langs(key).default;
    // 移除开头的 ./
    let fileName = key.replace(/^\.\//, "");
    const lastIndex = fileName.lastIndexOf(".");
    fileName = fileName.substring(0, lastIndex);
    const keyList = fileName.split("/");
    if (keyList[0] === localeDir) {
      keyList.shift();
    }
    const moduleName = keyList.shift();
    const objKey = keyList.join(".");

    if (moduleName) {
      if (objKey) {
        set(obj, moduleName, obj[moduleName] || {});
        set(obj[moduleName], objKey, langFileModule);
      } else {
        set(obj, moduleName, langFileModule || {});
      }
    }
  });
  return obj;
}

const modulesFiles = (key) => {
  const map = {
    "./en-US/common.js": common,
    "./en-US/component.js": component,
    "./en-US/layout.js": layout,
    "./en-US/routes/account.js": routesAccount,
    "./en-US/routes/basic.js": routesBasic,
    "./en-US/routes/dashboard.js": routesDashboard,
    "./en-US/routes/demo.js": routesDemo,
  };
  return { default: map[key] };
};
modulesFiles.keys = () => [
  "./en-US/common.js",
  "./en-US/component.js",
  "./en-US/layout.js",
  "./en-US/routes/account.js",
  "./en-US/routes/basic.js",
  "./en-US/routes/dashboard.js",
  "./en-US/routes/demo.js",
];

export default {
  message: {
    ...genMessage(modulesFiles, "en-US"),
    antdLocale,
  },
  dateLocale: null,
  dateLocaleName: "en-US",
};
