const { join } = require("path");
const { pkg } = require("../config");

const __ = pkg.config ? pkg.config.paths || {} : {}; // custom configuration

const srcFolder = __.srcFolder || "src";
const destFolder = __.destFolder || "resources";
const publicFolder = __.publicFolder || "public";
const destUrl = __.destUrl || `/`;
const destFolders = {
  assets: "assets",
  chunks: "chunks",
  entries: "entries",
  images: "images",
  media: "media",
  fonts: "fonts",
  favicons: "favicons",
};

// ensure trailing slashes
const destRelativeUrls = {
  base: `/${destUrl}/`,
  assets: `/${destUrl}/${destFolders.assets}/`,
  chunks: `/${destUrl}/${destFolders.assets}/${destFolders.chunks}/`,
  entries: `/${destUrl}/${destFolders.assets}/${destFolders.entries}/`,
  images: `/${destUrl}/${destFolders.assets}/${destFolders.images}/`,
  media: `/${destUrl}/${destFolders.assets}/${destFolders.media}/`,
  favicons: `/${destUrl}/${destFolders.assets}/${destFolders.favicons}/`,
  fonts: `/${destUrl}/${destFolders.assets}/${destFolders.fonts}/`,
  serviceWorker: `/${destUrl}/${destFolders.assets}/service-worker.js`,
};
const destPublic = join(process.cwd(), publicFolder);
const destPath = join(process.cwd(), destFolder);
const srcPath = join(process.cwd(), srcFolder);

/**
 * All default paths are defined here
 */
module.exports = {
  src: {
    folder: srcFolder,
    base: srcPath,
    assets: join(srcPath, "assets"),
    favicons: join(srcPath, "assets"),
    images: join(srcPath, "assets/images"),
    media: join(srcPath, "assets/media"),
    fonts: join(srcPath, "assets/fonts"),
    svgicons: join(srcPath, "assets/svgicons"),
    config: join(srcPath, "config"),
    utils: join(srcPath, "utils"),
    vendor: join(srcPath, "vendor"),
    // interpreted:
    translations: join(srcPath, "translations"),
    layouts: join(srcPath, "layouts"),
    routes: join(srcPath, "routes"),
    core: join(srcPath, "core"),
    components: join(srcPath, "components"),
  },
  dest: {
    folders: destFolders,
    relativeUrls: destRelativeUrls,
    base: destPath,
    public: destPublic,
    assets: join(destPublic, destFolders.assets),
    favicons: join(destPublic, destFolders.assets, destFolders.favicons),
    images: join(destPublic, destFolders.assets, destFolders.images),
    media: join(destPublic, destFolders.assets, destFolders.media),
    fonts: join(destPublic, destFolders.assets, destFolders.fonts),
    chunks: join(destPublic, destFolders.assets, destFolders.chunks),
    entries: join(destPublic, destFolders.assets, destFolders.entries),
    // interpreted:
    translations: join(destPath, "translations"),
    layouts: join(destPath, "layouts"),
    routes: join(destPath, "routes"),
    utils: join(destPath, "components"),
    components: join(destPath, "components"),
    core: join(destPath, "components"),
    automated: join(destPath, "components"),
  },
};
