import {
  AppLayout,
  ComponentsContextProvider,
  DomContextProvider,
  RenderedPage,
  ToolpadApp,
  api_default,
  componentsStore,
  pageComponentsStore
} from "./chunk-UO6UIBP6.mjs";
import "./chunk-ZUJ4UAKT.mjs";

// src/runtime/index.tsx
import Button from "@mui/material/Button";
import * as React from "react";
import * as ReactDOM from "react-dom/client";
import createCache from "@emotion/cache";
import { CacheProvider } from "@emotion/react";
import { Box } from "@mui/material";
import { errorFrom } from "@mui/toolpad-utils/errors";
var cache = createCache({
  key: "css",
  prepend: true
});
cache.compat = true;
function setComponents(newComponents, pageComponents) {
  componentsStore.setState(newComponents);
  pageComponentsStore.setState(pageComponents);
}
function Root({ ToolpadApp: ToolpadApp2, initialState, base }) {
  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 }), /* @__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 })
  );
}
function createRemoteFunction(functionFile, functionName) {
  return async function remote(...params) {
    const { data, error } = await api_default.methods.execFunction(functionFile, functionName, params);
    if (error) {
      throw errorFrom(error);
    }
    return data;
  };
}
export {
  AppLayout,
  ComponentsContextProvider,
  DomContextProvider,
  RenderedPage,
  createRemoteFunction,
  init,
  setComponents
};
//# sourceMappingURL=runtime.mjs.map