"use strict";
var __create = Object.create;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getProtoOf = Object.getPrototypeOf;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
  for (var name in all)
    __defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
  if (from && typeof from === "object" || typeof from === "function") {
    for (let key of __getOwnPropNames(from))
      if (!__hasOwnProp.call(to, key) && key !== except)
        __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
  }
  return to;
};
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
  // If the importer is in node compatibility mode or this is not an ESM
  // file that has been converted to a CommonJS file using a Babel-
  // compatible transform (i.e. "__esModule" has not been set), then set
  // "default" to the CommonJS "module.exports" for node compatibility.
  isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
  mod
));
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var ricos_nodes_renderer_exports = {};
__export(ricos_nodes_renderer_exports, {
  RicosNodesRenderer: () => RicosNodesRenderer
});
module.exports = __toCommonJS(ricos_nodes_renderer_exports);
var import_react = __toESM(require("react"));
var import_gap_spacer_viewer = require("./../../ricos-common-plugins/gap-spacer/gap-spacer-viewer.js");
var import_ricos_context = require("./../../ricos-context/index.js");
var import_node_tree_map_context = require("./../../ricos-context/viewer/node-tree-map-context.js");
var import_anchor = require("./components/anchor.js");
var import_node_view_container = require("./rericos/renderers/plugins/node-view-container.js");
const Fallback = ({ node }) => {
  return false ? /* @__PURE__ */ import_react.default.createElement("div", null, `Type ${node.type} is not supported yet (:`) : null;
};
const RicosNodeDecorated = ({
  node,
  index,
  isRoot,
  shouldParagraphApplyTextStyle
}) => {
  const { renderers, nodeViewDecorators } = (0, import_react.useContext)(import_ricos_context.ContentTraverserContext);
  const Renderer = renderers[node.type];
  if (!Renderer) {
    console.error(`RicosNodeDedcorated Error: no renderer passed for node type - ${node.type}`);
    return /* @__PURE__ */ import_react.default.createElement(Fallback, { node });
  }
  return nodeViewDecorators.apply(
    /* @__PURE__ */ import_react.default.createElement(
      Renderer,
      {
        node,
        key: node.id || index.toString(),
        RicosNodesRenderer,
        isRoot,
        nodeIndex: index,
        NodeViewContainer: import_node_view_container.nodeViewContainer,
        shouldParagraphApplyTextStyle
      }
    ),
    node,
    !!isRoot
  );
};
const RicosNodesRenderer = ({
  nodes,
  isRoot,
  shouldParagraphApplyTextStyle,
  addAnchorsPrefix
}) => {
  const { nodeTreeMap, nodeRefMap } = (0, import_react.useContext)(import_node_tree_map_context.NodeTreeMapContext);
  return /* @__PURE__ */ import_react.default.createElement(import_react.default.Fragment, null, nodes.flatMap((node, index) => {
    if (!node) {
      console.error(`RicosNodesRenderer Error: node is undefined at index ${index}`);
      return [];
    }
    return [
      ...(0, import_gap_spacer_viewer.renderGapSpacerBeforeNodeIfNeeded)(node, index, nodeTreeMap, nodeRefMap),
      /* @__PURE__ */ import_react.default.createElement(
        RicosNodeDecorated,
        {
          isRoot,
          node,
          index,
          key: node.id || index.toString(),
          shouldParagraphApplyTextStyle
        }
      ),
      ...addAnchorsPrefix ? [(0, import_anchor.getAnchor)(node, index, addAnchorsPrefix)] : []
    ];
  }), (0, import_gap_spacer_viewer.renderGapSpacerAfterLastNodeIfNeeded)(nodes, nodeTreeMap, nodeRefMap));
};
//# sourceMappingURL=ricos-nodes-renderer.js.map
