"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 content_traverser_exports = {};
__export(content_traverser_exports, {
  ContentTraverser: () => ContentTraverser
});
module.exports = __toCommonJS(content_traverser_exports);
var import_react = __toESM(require("react"));
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_ricos_styles = require("./../../ricos-styles/index.js");
var import_bi_helpers_context = require("./../../_shared/bi-helpers-context/bi-helpers-context.js");
var import_wix_rich_content_common = require("./../../wix-rich-content-common/index.js");
var import_rich_content_viewer_scss = __toESM(require("../statics/rich-content-viewer-scss.js"));
var import_decorators = require("./rericos/decorators/index.js");
var import_renderers = require("./rericos/renderers/index.js");
var import_plugins = require("./rericos/renderers/plugins/index.js");
var import_spoiler_manager = require("./rericos/utils/spoiler-manager.js");
var import_ricos_nodes_renderer = require("./ricos-nodes-renderer.js");
const ContentTraverser = ({
  content,
  context,
  typeMappers,
  nodeViewRenderers,
  nodeViewDecorators,
  SpoilerViewerWrapper,
  addAnchorsPrefix
}) => {
  const nodes = (content.nodes ?? []).filter(import_wix_rich_content_common.isDefined);
  const spoilerManager = new import_spoiler_manager.SpoilerManager();
  const allRenderers = (0, import_react.useMemo)(
    () => ({
      ...import_renderers.renderers,
      ...(0, import_plugins.getPluginRenderers)(context, typeMappers, nodeViewRenderers, SpoilerViewerWrapper)
    }),
    []
  );
  const allDecorators = (0, import_react.useMemo)(() => {
    const decorators = (0, import_decorators.getDecorators)(context.plugins);
    return import_decorators.NodeViewDecorators.of([...decorators, ...nodeViewDecorators], context);
  }, [context]);
  const ricosContext = (0, import_react.useMemo)(() => {
    const { t, locale, isMobile, theme, experiments, languageDir, jsdomMode } = context;
    return {
      t,
      locale,
      localeContent: locale,
      isMobile,
      theme,
      experiments,
      languageDir,
      jsdomMode,
      tabIndex: 0
    };
  }, [
    context.t,
    context.locale,
    context.isMobile,
    context.theme,
    context.experiments,
    context.languageDir,
    context.jsdomMode
  ]);
  const zIndexService = (0, import_react.useMemo)(() => {
    return new import_ricos_styles.ZIndexService(context.isMobile, context.theme.settingsStyles);
  }, []);
  return /* @__PURE__ */ import_react.default.createElement(import_react.default.Fragment, null, /* @__PURE__ */ import_react.default.createElement(import_ricos_context.RicosContextProvider, { ...ricosContext }, /* @__PURE__ */ import_react.default.createElement(import_ricos_context.ZIndexContextProvider, { zIndexService }, /* @__PURE__ */ import_react.default.createElement(
    import_ricos_context.ContentTraverserContextProvider,
    {
      nodeViewDecorators: allDecorators,
      renderers: allRenderers,
      SpoilerViewerWrapper
    },
    /* @__PURE__ */ import_react.default.createElement(import_ricos_context.RicosViewerContextProvider, { contextualData: context }, /* @__PURE__ */ import_react.default.createElement(import_bi_helpers_context.BiHelpersProvider, { helpers: context.helpers || {} }, /* @__PURE__ */ import_react.default.createElement(import_ricos_context.RicosAlignmentContextProvider, { textAlignment: context.textAlignment }, /* @__PURE__ */ import_react.default.createElement(import_ricos_context.SpoilerContextProvider, { spoilerManager }, /* @__PURE__ */ import_react.default.createElement(import_ricos_context.VisibleIndentationContextProvider, { visibleIndentation: null }, /* @__PURE__ */ import_react.default.createElement(import_ricos_context.RicosNodeContextProvider, { parentNode: null, parentIndex: 0 }, /* @__PURE__ */ import_react.default.createElement(import_node_tree_map_context.NodeTreeMapContextProvider, { nodes }, /* @__PURE__ */ import_react.default.createElement("div", { className: import_rich_content_viewer_scss.default.rootedTraversedContent }, /* @__PURE__ */ import_react.default.createElement(
      import_ricos_nodes_renderer.RicosNodesRenderer,
      {
        nodes,
        isRoot: true,
        addAnchorsPrefix,
        shouldParagraphApplyTextStyle: true
      }
    )))))))))
  ))));
};
//# sourceMappingURL=content-traverser.js.map
