"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 heading_exports = {};
__export(heading_exports, {
  default: () => heading_default,
  levelToClassName: () => levelToClassName
});
module.exports = __toCommonJS(heading_exports);
var import_classnames = __toESM(require("classnames"));
var import_react = __toESM(require("react"));
var import_ricos_context = require("./../../../../../ricos-context/index.js");
var import_v1 = require("./../../../../../ricos-schema/legacy/wix/rich_content/v1/index.js");
var import_get_heading_anchor = require("./../../../../../_shared/get-heading-anchor.js");
var import_get_text_from_nodes = require("./../../../../../_shared/get-text-from-nodes.js");
var import_line_spacing_utils = require("./../../../../../_shared/line-spacing-utils.js");
var import_alignment_scss = __toESM(require("../../../../statics/alignment-scss.js"));
var import_indentation_scss = __toESM(require("../../../../statics/indentation-scss.js"));
var import_anchorable = require("../../utils/anchorable.js");
var import_paywall_seo = require("../../utils/paywall-seo.js");
var import_consts = require("../consts.js");
var import_heading_scss = __toESM(require("./heading-scss.js"));
const levelToClassName = {
  1: "headerOne",
  2: "headerTwo",
  3: "headerThree",
  4: "headerFour",
  5: "headerFive",
  6: "headerSix"
};
const levelToTag = {
  1: "h1",
  2: "h2",
  3: "h3",
  4: "h4",
  5: "h5",
  6: "h6"
};
const FALLBACK_LEVEL = 1;
const Heading = ({ node, nodeIndex, RicosNodesRenderer }) => {
  const { seoMode } = (0, import_react.useContext)(import_ricos_context.RicosViewerContext);
  const { textAlignment: parentAlignment } = (0, import_react.useContext)(import_ricos_context.RicosAlignmentContext);
  const { parentNode } = (0, import_react.useContext)(import_ricos_context.RicosNodeContext);
  const directionHandled = (0, import_react.useContext)(import_ricos_context.RicosDirectionHandledContext);
  const { level = 0, textStyle, indentation = 0, renderedLevel } = node.headingData || {};
  const tagLevel = renderedLevel && renderedLevel >= 1 && renderedLevel <= 6 ? renderedLevel : level;
  const { textAlignment, lineHeight } = textStyle || {};
  const headingClassName = (0, import_classnames.default)(
    import_heading_scss.default[levelToClassName[level] ?? levelToClassName[FALLBACK_LEVEL]],
    import_alignment_scss.default[textAlignment || parentAlignment || import_v1.TextStyle_TextAlignment.AUTO],
    import_indentation_scss.default[import_consts.indentLevelToClassName[indentation]],
    !parentNode && (0, import_paywall_seo.isPaywallSeo)(seoMode) && (0, import_paywall_seo.getPaywallSeoClass)(seoMode?.paywall || {}, nodeIndex)
  );
  const childClassName = (0, import_classnames.default)(
    import_heading_scss.default.child,
    textAlignment === import_v1.TextStyle_TextAlignment.JUSTIFY && import_alignment_scss.default[textAlignment]
  );
  const Tag = levelToTag[tagLevel] ?? levelToTag[FALLBACK_LEVEL];
  const nodeStyle = node.style ? { ...node.style } : {};
  lineHeight && (nodeStyle.lineHeight = (0, import_line_spacing_utils.normalizeLineHeight)(lineHeight));
  const isEmpty = !node.nodes?.length;
  const doesEndWithSoftLine = !isEmpty && node.nodes?.[node.nodes.length - 1]?.textData?.text?.slice(-1) === "\n";
  const Content = isEmpty ? /* @__PURE__ */ import_react.default.createElement("br", { role: "presentation" }) : /* @__PURE__ */ import_react.default.createElement(import_ricos_context.RicosNodeContextProvider, { parentNode: node, parentIndex: nodeIndex }, /* @__PURE__ */ import_react.default.createElement(RicosNodesRenderer, { key: `children-${node.id}`, nodes: node.nodes ?? [] }));
  return /* @__PURE__ */ import_react.default.createElement(import_anchorable.Anchorable, { nodeId: node.id }, /* @__PURE__ */ import_react.default.createElement(
    Tag,
    {
      className: headingClassName,
      style: nodeStyle,
      dir: directionHandled ? "" : "auto",
      tabIndex: -1
    },
    /* @__PURE__ */ import_react.default.createElement(
      "span",
      {
        "aria-hidden": "true",
        id: (0, import_get_heading_anchor.getHeadingAnchor)({
          id: node.id,
          text: (0, import_get_text_from_nodes.getTextFromNodes)(node.nodes)
        })
      }
    ),
    /* @__PURE__ */ import_react.default.createElement("span", { className: childClassName }, Content),
    doesEndWithSoftLine && /* @__PURE__ */ import_react.default.createElement("br", { role: "presentation" })
  ));
};
const HeadingRenderer = ({ node, ...props }) => {
  return /* @__PURE__ */ import_react.default.createElement(Heading, { key: node.id, node, ...props });
};
var heading_default = HeadingRenderer;
//# sourceMappingURL=heading.js.map
