import React, { useMemo } from "react";
import {
  ContentTraverserContextProvider,
  RicosAlignmentContextProvider,
  RicosContextProvider,
  RicosNodeContextProvider,
  RicosViewerContextProvider,
  SpoilerContextProvider,
  VisibleIndentationContextProvider,
  ZIndexContextProvider
} from "./../../ricos-context/index.js";
import { NodeTreeMapContextProvider } from "./../../ricos-context/viewer/node-tree-map-context.js";
import { ZIndexService } from "./../../ricos-styles/index.js";
import { BiHelpersProvider } from "./../../_shared/bi-helpers-context/bi-helpers-context.js";
import { isDefined } from "./../../wix-rich-content-common/index.js";
import styles from "../statics/rich-content-viewer-scss.js";
import { NodeViewDecorators, getDecorators } from "./rericos/decorators/index.js";
import { renderers } from "./rericos/renderers/index.js";
import { getPluginRenderers } from "./rericos/renderers/plugins/index.js";
import { SpoilerManager } from "./rericos/utils/spoiler-manager.js";
import { RicosNodesRenderer } from "./ricos-nodes-renderer.js";
const ContentTraverser = ({
  content,
  context,
  typeMappers,
  nodeViewRenderers,
  nodeViewDecorators,
  SpoilerViewerWrapper,
  addAnchorsPrefix
}) => {
  const nodes = (content.nodes ?? []).filter(isDefined);
  const spoilerManager = new SpoilerManager();
  const allRenderers = useMemo(
    () => ({
      ...renderers,
      ...getPluginRenderers(context, typeMappers, nodeViewRenderers, SpoilerViewerWrapper)
    }),
    []
  );
  const allDecorators = useMemo(() => {
    const decorators = getDecorators(context.plugins);
    return NodeViewDecorators.of([...decorators, ...nodeViewDecorators], context);
  }, [context]);
  const ricosContext = 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 = useMemo(() => {
    return new ZIndexService(context.isMobile, context.theme.settingsStyles);
  }, []);
  return /* @__PURE__ */ React.createElement(React.Fragment, null, /* @__PURE__ */ React.createElement(RicosContextProvider, { ...ricosContext }, /* @__PURE__ */ React.createElement(ZIndexContextProvider, { zIndexService }, /* @__PURE__ */ React.createElement(
    ContentTraverserContextProvider,
    {
      nodeViewDecorators: allDecorators,
      renderers: allRenderers,
      SpoilerViewerWrapper
    },
    /* @__PURE__ */ React.createElement(RicosViewerContextProvider, { contextualData: context }, /* @__PURE__ */ React.createElement(BiHelpersProvider, { helpers: context.helpers || {} }, /* @__PURE__ */ React.createElement(RicosAlignmentContextProvider, { textAlignment: context.textAlignment }, /* @__PURE__ */ React.createElement(SpoilerContextProvider, { spoilerManager }, /* @__PURE__ */ React.createElement(VisibleIndentationContextProvider, { visibleIndentation: null }, /* @__PURE__ */ React.createElement(RicosNodeContextProvider, { parentNode: null, parentIndex: 0 }, /* @__PURE__ */ React.createElement(NodeTreeMapContextProvider, { nodes }, /* @__PURE__ */ React.createElement("div", { className: styles.rootedTraversedContent }, /* @__PURE__ */ React.createElement(
      RicosNodesRenderer,
      {
        nodes,
        isRoot: true,
        addAnchorsPrefix,
        shouldParagraphApplyTextStyle: true
      }
    )))))))))
  ))));
};
export {
  ContentTraverser
};
//# sourceMappingURL=content-traverser.js.map
