const fs = require("fs");
const path = require("path");

const getTranslationImports = () => {
  const translationsDir = path.resolve("dist/translations");

  const files = fs
    .readdirSync(translationsDir)
    .filter(file => file.endsWith(".json"));

  // Create a map like { "en": () => import("dist/translations/en.json") }
  const entries = files.map(file => {
    const lang = path.basename(file, ".json");

    return `"${lang}": () => import("${process.cwd()}/dist/translations/${file}")`;
  });

  return `{ ${entries.join(",\n")} }`;
};

module.exports = getTranslationImports;
