import { CssCollector } from "../css-collector.js";
import { Html } from "../html.js";
export const DEFAULT_CONFIG = {
  FILE_REGEX: /\.(m|c)?(j|t)sx?$/,
  CLIENT_ASSETS_DIR: "assets",
  RSC_DIR: "rsc",
  MODULE_BASE: "src",
  MODULE_BASE_PATH: "",
  MODULE_BASE_URL: "",
  PAGE: "src/page/page.tsx",
  PROPS: "src/page/props.ts",
  CLIENT_ENTRY: "src/client.tsx",
  SERVER_ENTRY: "src/server.tsx",
  PAGE_EXPORT_NAME: "Page",
  PROPS_EXPORT_NAME: "props",
  HTML_WORKER_PATH: `worker/html/html-worker.${
    process.env["NODE_ENV"] === "development" ? "development" : "production"
  }.js`,
  RSC_WORKER_PATH: `worker/rsc/rsc-worker.${
    process.env["NODE_ENV"] === "development" ? "development" : "production"
  }.js`,
  LOADER_PATH: "worker/loader.js",
  RSC_EXTENSION: ".rsc",
  CSS_COLLECTOR: CssCollector,
  HTML: Html,
  COLLECT_CSS: true,
  COLLECT_ASSETS: true,
  INLINE_CSS: true,
  DEV_PORT: 5173,
  PREVIEW_PORT: 4173,
  DEV_HOST: "localhost",
  PREVIEW_HOST: "localhost",
  ENV_PREFIX: "VITE_",
  BUILD: {
    pages: () => ["/"],
    client: "client",
    server: "server",
    static: "static",
    api: "api",
    outDir: "dist",
    assetsDir: "assets",
    hash: "hash",
    preserveModulesRoot: true,
  },
  CSS: {
    inlineThreshold: 4096, // 4KB
    inlinePatterns: [/\.module\.css$/], // Always inline CSS modules
    linkPatterns: [/node_modules/], // Always link node_modules CSS
  },
  MODULE_BASE_EXCEPTIONS: [] as string[],
  AUTO_DISCOVER: {
    modulePattern: (n: string) => DEFAULT_CONFIG.FILE_REGEX.test(n),
    pagePattern: (n: string) =>
      n.toLowerCase().endsWith("/page") || n.toLowerCase() === "page",
    propsPattern: (n: string) =>
      n.toLowerCase().endsWith("/props") || n.toLowerCase() === "props",
    clientComponents: (n: string) =>
      n.toLowerCase().endsWith(".client") || n.toLowerCase() === "client",
    serverFunctions: (n: string) =>
      n.toLowerCase().endsWith(".server") || n.toLowerCase() === "server",
    cssPattern: (n: string) => n.toLowerCase().endsWith(".css"),
    cssModulePattern: (n: string) => n.toLowerCase().endsWith(".css.js"),
    vendorPattern: (n: string) =>
      n.toLowerCase().startsWith("node_modules") ||
      n.toLowerCase().startsWith("_virtual"),
    htmlPattern: (n: string) => n.toLowerCase().endsWith(".html"),
    jsonPattern: (n: string) => n.toLowerCase().endsWith(".json"),
  },
  MODULE_ID: (id: string) => id,
} as const;
