/**
 * Serves the desktop streaming HTML page.
 *
 * Instead of embedding HTML in a template literal, we read the standalone
 * `desktop.html` file and inject a small `<script>` with runtime config
 * (`window.__RDP_CONFIG__`) before the closing `</head>` tag.
 */
import fs from "node:fs";
import path from "node:path";
const HTML_PATH = path.join(new URL(".", import.meta.url).pathname, "desktop.html");
let cachedHtml = null;
let cachedMtime = 0;
function loadHtml() {
    const stat = fs.statSync(HTML_PATH);
    if (!cachedHtml || stat.mtimeMs !== cachedMtime) {
        cachedHtml = fs.readFileSync(HTML_PATH, "utf-8");
        cachedMtime = stat.mtimeMs;
    }
    return cachedHtml;
}
/**
 * Render the "link expired" error page returned for invalid / expired tokens.
 */
export function renderExpiredHtml() {
    return `<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Link Expired</title>
  <style>
    * { margin: 0; padding: 0; box-sizing: border-box; }
    body {
      display: flex;
      align-items: center;
      justify-content: center;
      min-height: 100vh;
      background: #111;
      color: #eee;
      font-family: system-ui, sans-serif;
    }
    .card {
      text-align: center;
      padding: 40px 48px;
      background: #1e1e1e;
      border-radius: 12px;
      border: 1px solid #333;
    }
    h1 { font-size: 2rem; margin-bottom: 12px; color: #f66; }
    p  { color: #aaa; line-height: 1.6; }
  </style>
</head>
<body>
  <div class="card">
    <h1>Link Expired</h1>
    <p>This remote desktop link is no longer valid.</p>
    <p>Please request a new link from the agent.</p>
  </div>
</body>
</html>`;
}
/**
 * Render the desktop streaming page with runtime config injected.
 */
export function renderDesktopHtml(wsUrl, expiresAt, screens = [], opts = {}) {
    const html = loadHtml();
    const hostname = opts.hostname ?? "";
    const agentName = opts.agentName ?? "";
    const agentAvatar = opts.agentAvatar ?? "";
    const config = JSON.stringify({
        wsUrl,
        expiresAt,
        screens,
        hostname,
        agentName,
        agentAvatar,
    });
    // Inject config script before the closing </head> tag
    const configScript = `<script>window.__RDP_CONFIG__=${config};</script>`;
    return html.replace("</head>", `${configScript}\n</head>`);
}
//# sourceMappingURL=desktop-ui.js.map