import { readFileSync } from "node:fs";
import { defineConfig } from "astro/config";

const siteConfig = JSON.parse(
  readFileSync(new URL("./src/config/site.json", import.meta.url)),
);
import mdx from "@astrojs/mdx";
import tailwindcss from "@tailwindcss/vite";

const site =
  process.env.SITE_URL || process.env.PUBLIC_SITE_URL || siteConfig.url;

export default defineConfig({
  site,
  // astroagent overrides outDir for isolated preview builds (PREVIEW_OUT);
  // falls back to the live output for normal/cron builds.
  outDir: process.env.PREVIEW_OUT || "../public",
  // For previews, PREVIEW_BASE prefixes asset paths (/_preview/<id>) so the
  // preview is self-contained and doesn't pull _astro/fonts from the live site.
  base: process.env.PREVIEW_BASE || undefined,
  integrations: [mdx()],
  vite: {
    plugins: [tailwindcss()],
    build: {
      emptyOutDir: false,
    },
  },
});
