import fs from "fs-extra";
import path from "path";
import haditha from "./hadithaRoute";

// dynamically importing styles.
const buildName = import.meta.env.VITE_BUILD_NAME;

export default defineNuxtConfig({
  hooks: {
    "build:before": () => {
      const sourceDir = path.resolve(
        __dirname,
        `./assets/${buildName}/images`
      ); // Source folder (e.g., assets/images)
      const targetDir = path.resolve(__dirname, `public/img/${buildName}`); // Target folder (e.g., public/img)

      // Ensure the target directory exists
      fs.ensureDirSync(targetDir);

      // Copy files from source to target
      fs.copySync(sourceDir, targetDir);

      console.log("Files copied successfully!");
    },

    "pages:extend"(pages) {
      // Add custom routes
      pages.push(...haditha);
      // pages.push(...search, ...research, ...haditha, ...chat, ...task);
    },
  },

  nitro: {
    prerender: {
      routes: ["/haditha", "/haditha/about-us", "/haditha/contact-us"], // Pre-render these routes
    },
  },
  icon: {
    // iconifyApiEndpoint: "iconifyApi",
    fallbackToApi: "client-only",
    // provider: "iconify",
    localApiEndpoint: "/iconifyapi/_nuxt_icon",
    customCollections: [
      {
        prefix: "haditha",
        dir: `./systems/${buildName}_ui/assets/${buildName}/images/font-icons`,
      },
    ],
  },

  alias: {
    "@haditha": "~/systems/haditha_ui",
  },
});
