import {
  AppLayout,
  ComponentsContextProvider,
  DomContextProvider,
  RenderedPage,
  ToolpadApp
} from "./chunk-VF5J6VTL.mjs";

// src/runtime/index.tsx
import Button from "@mui/material/Button";
import * as React from "react";
import * as ReactDOM from "react-dom/client";
import { Emitter } from "@mui/toolpad-utils/events";
import createCache from "@emotion/cache";
import { CacheProvider } from "@emotion/react";
import { Box } from "@mui/material";
var componentsStore = {};
var events = new Emitter();
var cache = createCache({
  key: "css",
  prepend: true
});
cache.compat = true;
function setComponents(newComponents) {
  componentsStore = newComponents;
  events.emit("update", {});
}
var subscribe = (cb) => events.subscribe("update", cb);
var getSnapshot = () => componentsStore;
function useComponents() {
  return React.useSyncExternalStore(subscribe, getSnapshot);
}
function Root({ ToolpadApp: ToolpadApp2, initialState, base }) {
  const components = useComponents();
  const loadComponents = React.useMemo(() => async () => components, [components]);
  return /* @__PURE__ */ React.createElement(React.StrictMode, null, /* @__PURE__ */ React.createElement(CacheProvider, { value: cache }, /* @__PURE__ */ React.createElement(Button, { sx: { display: "none" } }), /* @__PURE__ */ React.createElement(ToolpadApp2, { basename: base, state: initialState, loadComponents }), /* @__PURE__ */ React.createElement(Box, { "data-testid": "page-ready-marker", sx: { display: "none" } })));
}
function init({ ToolpadApp: ToolpadApp2 = ToolpadApp, initialState, base }) {
  ReactDOM.createRoot(document.getElementById("root")).render(
    /* @__PURE__ */ React.createElement(Root, { base, ToolpadApp: ToolpadApp2, initialState })
  );
}
export {
  AppLayout,
  ComponentsContextProvider,
  DomContextProvider,
  RenderedPage,
  init,
  setComponents
};
//# sourceMappingURL=runtime.mjs.map