"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.STATIC_STARTER_HTML = void 0;
exports.ensureStaticStarterCanvas = ensureStaticStarterCanvas;
const fs_1 = __importDefault(require("fs"));
const path_1 = __importDefault(require("path"));
const logger_1 = require("../utils/logger");
const log = (0, logger_1.createLogger)('staticStarter');
/**
 * Minimal, dependency-free landing page written into an empty static workspace
 * so the visual editor has a real canvas to render — and the user has an actual
 * file on disk to save visual edits to.
 */
exports.STATIC_STARTER_HTML = `<!doctype html>
<html lang="en">
  <head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1" />
    <title>New Rivet project</title>
    <style>
      :root { color-scheme: light dark; }
      * { box-sizing: border-box; }
      body {
        margin: 0;
        min-height: 100vh;
        display: grid;
        place-items: center;
        font-family: ui-sans-serif, system-ui, -apple-system, 'Segoe UI', Roboto,
          sans-serif;
        background: #ffffff;
        color: #111111;
      }
      main {
        text-align: center;
        padding: 2rem;
        max-width: 32rem;
      }
      h1 {
        font-size: 1.5rem;
        font-weight: 600;
        margin: 0 0 0.5rem;
      }
      p {
        margin: 0;
        line-height: 1.5;
        color: #6b7280;
      }
    </style>
  </head>
  <body>
    <main>
      <h1>Your blank canvas</h1>
      <p>Edit this page visually in Rivet, or ask Claude to build something here.</p>
    </main>
  </body>
</html>
`;
/**
 * Ensure an empty static workspace has an `index.html` for the visual editor to
 * render. Static mode serves `index.html` at the root, so a truly empty folder
 * opens to a blank / 404 page with nothing to point-and-click. Writing a
 * minimal starter makes "open rivet on an empty folder" self-contained instead
 * of depending on the agent improvising a file.
 *
 * No-op when:
 *  - an `index.html` already exists (HTML-only project — never clobber), or
 *  - the folder is a `.rivet` history workspace (opened for browsing past
 *    variants, not as a blank canvas).
 *
 * Returns true iff a starter was written. Best-effort: a write failure is
 * logged and swallowed so it can't block opening the editor.
 */
function ensureStaticStarterCanvas(projectPath) {
    try {
        if (fs_1.default.existsSync(path_1.default.join(projectPath, 'index.html')))
            return false;
        if (fs_1.default.existsSync(path_1.default.join(projectPath, '.rivet')))
            return false;
        fs_1.default.writeFileSync(path_1.default.join(projectPath, 'index.html'), exports.STATIC_STARTER_HTML, 'utf8');
        log.info(`Wrote starter index.html into empty static workspace: ${projectPath}`);
        return true;
    }
    catch (err) {
        log.warn(`Failed to write starter index.html at ${projectPath}:`, err);
        return false;
    }
}
//# sourceMappingURL=staticStarter.js.map