import React, { useContext, useMemo } from "react";
import { RicosContext, RicosNodeContextProvider } from "./../../ricos-context/index.js";
import { SmartBlockView } from "../components/smart-block-view.js";
import { jtdBlockToViewModel } from "../utils/block-view-model.js";
import { resolveThemeSmartBlock } from "../utils/resolve-theme-smart-block.js";
const SmartBlockViewer = ({ node, nodeIndex, RicosNodesRenderer }) => {
  const smartBlockNode = node;
  const { theme } = useContext(RicosContext);
  const themeSmartBlock = useMemo(() => resolveThemeSmartBlock(theme), [theme]);
  const viewModel = useMemo(() => jtdBlockToViewModel(smartBlockNode), [smartBlockNode]);
  return /* @__PURE__ */ React.createElement(
    SmartBlockView,
    {
      viewModel,
      themeSmartBlock,
      contentSlot: (innerProps) => /* @__PURE__ */ React.createElement("div", { ...innerProps }, /* @__PURE__ */ React.createElement(RicosNodeContextProvider, { parentNode: node, parentIndex: nodeIndex }, /* @__PURE__ */ React.createElement(RicosNodesRenderer, { key: `children-${node.id}`, nodes: node.nodes ?? [] })))
    }
  );
};
const SmartBlockRenderer = ({ node, ...props }) => {
  return /* @__PURE__ */ React.createElement(SmartBlockViewer, { key: node.id, node, ...props });
};
var smart_block_default = SmartBlockRenderer;
export {
  smart_block_default as default
};
//# sourceMappingURL=smart-block.js.map
