import fs from "node:fs";
import path from "node:path";
import { html } from "common-tags";
import { normalizePath } from "vite";
import { getLogger } from "./util/logger.js";
export const injectIndexVitePlugin = (pluginParams) => {
    const assetsCdnUrl = pluginParams.assetsCdnUrl ?? "https://prod-cdn.superblocks.com";
    const indexHtml = html `
    <!doctype html>
    <html lang="en">
      <head>
        <meta charset="utf-8" />
        <meta name="viewport" content="width=device-width, initial-scale=1" />
        <title>Code Mode</title>
        <link
          rel="icon"
          type="image/x-icon"
          href="${assetsCdnUrl}/favicon.ico"
        />
        <link rel="preconnect" href="https://fonts.googleapis.com" />
        <link rel="preconnect" href="https://fonts.gstatic.com" crossorigin />
        <link
          href="https://fonts.googleapis.com/css2?family=Geist+Mono:wght@100..900&family=Inter:ital,opsz,wght@0,14..32,100..900;1,14..32,100..900&display=swap"
          rel="stylesheet"
        />
        <script>
          window._SB_VIEW_MODE = "deployed";
        </script>
        <script src="./root.tsx" type="module"></script>
      </head>
      <body>
        <div id="root"></div>
      </body>
    </html>
  `;
    return {
        name: "sb-inject-index-html",
        apply: "build",
        enforce: "pre",
        configResolved(config) {
            const indexPath = normalizePath(path.join(config.root, "index.html"));
            const logger = getLogger();
            if (!fs.existsSync(indexPath)) {
                logger.info("Injecting index.html");
                fs.writeFileSync(indexPath, indexHtml);
            }
        },
    };
};
//# sourceMappingURL=inject-index-vite-plugin.js.map