import classnames from "classnames";
import React, { useContext } from "react";
import {
  RicosAlignmentContext,
  RicosNodeContext,
  RicosNodeContextProvider,
  RicosViewerContext
} from "./../../../../../ricos-context/index.js";
import { TextStyle_TextAlignment } from "./../../../../../ricos-schema/legacy/wix/rich_content/v1/index.js";
import { normalizeLineHeight } from "./../../../../../_shared/line-spacing-utils.js";
import alignmentStyle from "../../../../statics/alignment-scss.js";
import { Anchorable } from "../../utils/anchorable.js";
import { getPaywallSeoClass, isPaywallSeo } from "../../utils/paywall-seo.js";
import styles from "./codeblock-scss.js";
const CodeBlock = ({ node, nodeIndex, RicosNodesRenderer }) => {
  const { seoMode } = useContext(RicosViewerContext);
  const { textAlignment: parentAlignment } = useContext(RicosAlignmentContext);
  const { parentNode } = useContext(RicosNodeContext);
  const { textAlignment, lineHeight } = node.codeBlockData?.textStyle || {};
  const codeBlockClassName = classnames(
    styles.codeBlock,
    alignmentStyle[textAlignment || parentAlignment || TextStyle_TextAlignment.AUTO],
    !parentNode && isPaywallSeo(seoMode) && getPaywallSeoClass(seoMode?.paywall || {}, nodeIndex)
  );
  const nodeStyle = {
    ...node.style,
    ...lineHeight && { lineHeight: normalizeLineHeight(lineHeight) }
  };
  return /* @__PURE__ */ React.createElement(Anchorable, { nodeId: node.id }, /* @__PURE__ */ React.createElement("pre", { className: codeBlockClassName, style: nodeStyle, dir: "auto" }, /* @__PURE__ */ React.createElement(
    "span",
    {
      className: classnames(
        textAlignment === TextStyle_TextAlignment.JUSTIFY && alignmentStyle[textAlignment]
      )
    },
    /* @__PURE__ */ React.createElement(RicosNodeContextProvider, { parentNode: node, parentIndex: nodeIndex }, /* @__PURE__ */ React.createElement(RicosNodesRenderer, { nodes: node.nodes ?? [] }))
  )));
};
const CodeBlockRenderer = ({ node, ...props }) => {
  return /* @__PURE__ */ React.createElement(CodeBlock, { key: node.id, node, ...props });
};
var codeblock_default = CodeBlockRenderer;
export {
  codeblock_default as default
};
//# sourceMappingURL=codeblock.js.map
