import { defineConfig } from "vite";
import react from "@vitejs/plugin-react-swc";
import tailwindcss from "@tailwindcss/vite";
import path from "path";
import { viteSingleFile } from "vite-plugin-singlefile";
import { tailwindShadowDom } from "./vite-plugins";

/**
 * Build the playground as a single self-contained HTML file.
 *
 * All JS/CSS is inlined so the file can be served from a CDN and
 * embedded in Mintlify docs via an iframe.
 */
export default defineConfig({
  plugins: [react(), tailwindcss(), tailwindShadowDom(), viteSingleFile()],
  define: {
    "process.env.NODE_ENV": JSON.stringify("production"),
    // When true, prefab-ui source is bundled into the playground HTML so
    // Pyodide loads it from the filesystem instead of micropip (which can't
    // install pydantic-core). Set via VITE_LOCAL_PLAYGROUND=1 in build-docs.
    __LOCAL_BUNDLE__: process.env.VITE_LOCAL_PLAYGROUND === "1",
  },
  resolve: {
    alias: {
      "@": path.resolve(__dirname, "./src"),
    },
  },
  build: {
    outDir: "dist",
    emptyOutDir: false,
    rollupOptions: {
      input: {
        playground: path.resolve(__dirname, "playground.html"),
      },
    },
  },
});
