import http from "node:http";
const TEST_PAGE_HTML = `<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="utf-8" />
  <title>VisionClaw E2E Test Page</title>
  <style>
    body { font-family: system-ui, sans-serif; margin: 24px; }
    #result { margin-top: 16px; padding: 12px; border: 1px solid #ccc; min-height: 24px; }
    #bottom-marker { margin-top: 1200px; padding: 12px; background: #eef; }
  </style>
</head>
<body>
  <h1>VisionClaw E2E</h1>
  <input id="text-input" type="text" placeholder="Type here" />
  <button id="click-button" type="button">Click me</button>
  <label><input id="checkbox" type="checkbox" /> Checked</label>
  <textarea id="clipboard-target" rows="3" cols="40"></textarea>
  <div id="result">idle</div>
  <div id="bottom-marker">bottom</div>
  <script>
    document.getElementById('click-button').addEventListener('click', () => {
      document.getElementById('result').textContent = 'clicked';
    });
    document.getElementById('text-input').addEventListener('input', (event) => {
      document.getElementById('result').textContent = event.target.value;
    });
    document.getElementById('checkbox').addEventListener('change', (event) => {
      document.getElementById('result').textContent = event.target.checked ? 'checked' : 'unchecked';
    });
    console.log('e2e-page-ready');
  </script>
</body>
</html>`;
export async function startLocalTestServer() {
    const server = http.createServer((req, res) => {
        const url = req.url ?? "/";
        if (url === "/health") {
            res.writeHead(200, { "Content-Type": "application/json" });
            res.end(JSON.stringify({ ok: true }));
            return;
        }
        if (url.startsWith("/api/echo")) {
            res.writeHead(200, { "Content-Type": "application/json" });
            res.end(JSON.stringify({ ok: true, path: url }));
            return;
        }
        if (url.startsWith("/api/fail")) {
            res.writeHead(500, { "Content-Type": "application/json" });
            res.end(JSON.stringify({ ok: false }));
            return;
        }
        if (url.startsWith("/e2e/browser") || url.startsWith("/e2e/cua")) {
            res.writeHead(200, { "Content-Type": "text/html; charset=utf-8" });
            res.end(TEST_PAGE_HTML);
            return;
        }
        res.writeHead(404);
        res.end("Not found");
    });
    await new Promise((resolve, reject) => {
        server.once("error", reject);
        server.listen(0, "127.0.0.1", () => resolve());
    });
    const address = server.address();
    const port = address.port;
    return {
        port,
        baseUrl: `http://127.0.0.1:${port}`,
        close: () => new Promise((resolve, reject) => {
            server.close((err) => (err ? reject(err) : resolve()));
        }),
    };
}
//# sourceMappingURL=local-test-server.js.map