import { defineConfig } from "vite";
import { viteStaticCopy } from "vite-plugin-static-copy";
import { resolve } from "node:path";

export default defineConfig(({ mode }) => {
  const browser = mode === "firefox" ? "firefox" : "chrome";

  return {
    root: "src",
    build: {
      outDir: `../dist/${browser}`,
      emptyOutDir: true,
      rollupOptions: {
        input: {
          popup: resolve(__dirname, "src/popup.html"),
          "import-wallet": resolve(__dirname, "src/import-wallet.html"),
          print: resolve(__dirname, "src/print.html"),
          background: resolve(__dirname, "src/background.ts"),
          content: resolve(__dirname, "src/content.ts"),
          provider: resolve(__dirname, "src/provider.ts")
        },
        output: {
          entryFileNames: "[name].js",
          chunkFileNames: "chunks/[name]-[hash].js",
          assetFileNames: "assets/[name]-[hash][extname]"
        }
      }
    },
    plugins: [
      viteStaticCopy({
        targets: [
          {
            src: `manifest.${browser}.json`,
            dest: ".",
            rename: "manifest.json"
          },
          { src: "assets/contractless-logo*.png", dest: "." }
        ]
      })
    ]
  };
});
