import {
  Hydrate,
  T
} from "../../chunk.W5KB2WD5.js";
import {
  AuthContext
} from "../../chunk.IH25ZNBZ.js";
import {
  QueryClient,
  QueryClientProvider
} from "../../chunk.22IV34P4.js";
import {
  N,
  defaultMarkupProps,
  x
} from "../../chunk.MLFHAVWF.js";
import {
  register
} from "../../chunk.6Z6KE2FG.js";
import {
  LazyContext
} from "../../chunk.KDX7KSFL.js";
import {
  BrowserRouter
} from "../../chunk.43AVWB5L.js";
import "../../chunk.IOTCVWDR.js";
import "../../chunk.JNDOIKBN.js";
import "../../chunk.DYBFOFDN.js";
import "../../chunk.NFF22PP7.js";

// src/runtime/internal/bootstrap/bootstrap.tsx
import {
  createElement
} from "react";
import {
  hydrate
} from "react-dom";
var DEFAULT_BROWSER_STALE_TIME = 16;
async function hydrateNostalgie(App, options) {
  if (process.env.NODE_ENV === "development") {
    if (options.automaticReload) {
      const eventSource = new EventSource("/.nostalgie/events");
      eventSource.addEventListener("reload", (e) => {
        window.location.reload();
      });
    }
    const errStack = options.errStack;
    if (errStack) {
      const errorDiv = document.createElement("div");
      errorDiv.style.position = "absolute";
      errorDiv.style.right = "0";
      errorDiv.style.bottom = "0";
      errorDiv.style.fontFamily = "monospace";
      errorDiv.style.backgroundColor = "red";
      errorDiv.style.color = "#f5f5f5";
      errorDiv.style.whiteSpace = "pre";
      errorDiv.style.zIndex = "9999";
      errorDiv.style.padding = "1em 1.5em";
      errorDiv.innerHTML = errStack.map((entry) => {
        const vscodeUri = encodeURI(`vscode://file/${entry.file}:${entry.line}:${entry.column}`);
        return `<div><a href=${JSON.stringify(vscodeUri)}>${entry.callee}</a></div>`;
      }).join("\n");
      document.body.prepend(errorDiv);
    }
  }
  const queryClient = new QueryClient({
    defaultOptions: {
      queries: {
        staleTime: DEFAULT_BROWSER_STALE_TIME
      }
    }
  });
  const chunkCtx = {
    chunks: [],
    lazyComponentState: new Map()
  };
  const rootEl = document.getElementById("root");
  if (options.enableTailwind) {
    const {setup} = await import("../../_.._/_.._/node_modules/twind/shim/shim.js");
    setup({
      mode: "silent",
      prefix: true,
      preflight: true,
      plugins: {
        ...T()
      },
      target: rootEl
    });
  }
  const promises = options.lazyComponents.map(({chunk, lazyImport}) => {
    return import(`${options.publicUrl}${chunk}`).then((m) => {
      register(chunkCtx, chunk, lazyImport, m);
    });
  });
  await Promise.all(promises);
  hydrate(/* @__PURE__ */ createElement(LazyContext.Provider, {
    value: chunkCtx
  }, /* @__PURE__ */ createElement(QueryClientProvider, {
    client: queryClient
  }, /* @__PURE__ */ createElement(Hydrate, {
    state: options.reactQueryState
  }, /* @__PURE__ */ createElement(x, null, /* @__PURE__ */ createElement(AuthContext.Provider, {
    value: options.auth
  }, /* @__PURE__ */ createElement(BrowserRouter, null, /* @__PURE__ */ createElement(N, {
    ...defaultMarkupProps
  }), /* @__PURE__ */ createElement(App, null))))))), rootEl);
}
export {
  hydrateNostalgie
};
