import {
  ToolpadApp
} from "./chunk-VMTJ5W2A.mjs";

// src/runtime/entrypoint.tsx
import Button from "@mui/material/Button";
import React from "react";
import ReactDOM from "react-dom/client";
import { Emitter } from "@mui/toolpad-utils/events";
import createCache from "@emotion/cache";
import { CacheProvider } from "@emotion/react";
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 })));
}
function init({ ToolpadApp: ToolpadApp2 = ToolpadApp, initialState, base }) {
  ReactDOM.createRoot(document.getElementById("root")).render(
    /* @__PURE__ */ React.createElement(Root, { base, ToolpadApp: ToolpadApp2, initialState })
  );
}
export {
  init,
  setComponents
};
//# sourceMappingURL=index.mjs.map