"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 list_item_exports = {};
__export(list_item_exports, {
  default: () => list_item_default
});
module.exports = __toCommonJS(list_item_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_ricos_types = require("./../../../../../ricos-types/index.js");
var import_checkbox_list_style = require("./../../../../../_shared/list-checkbox/checkbox-list-style.js");
var import_get_block_default_font_size = require("./../../../../../_shared/list-checkbox/get-block-default-font-size.js");
var import_wix_rich_content_common = require("./../../../../../wix-rich-content-common/index.js");
var import_paywall_seo = require("../../utils/paywall-seo.js");
var import_heading = require("../heading/heading.js");
var import_get_start_margin = require("./get-start-margin.js");
var import_lists_scss = __toESM(require("./lists-scss.js"));
const ListItem = ({ node, nodeIndex, RicosNodesRenderer }) => {
  const listItemNode = node;
  const { seoMode } = (0, import_react.useContext)(import_ricos_context.RicosViewerContext);
  const { parentIndex } = (0, import_react.useContext)(import_ricos_context.RicosNodeContext);
  const { visibleIndentation } = (0, import_react.useContext)(import_ricos_context.VisibleIndentationContext);
  const firstChild = node.nodes[0];
  const dataProperty = `${firstChild?.type?.toLowerCase()}Data`;
  const { textAlignment } = firstChild?.[dataProperty]?.textStyle || {};
  const { textAlignment: parentAlignment } = (0, import_react.useContext)(import_ricos_context.RicosAlignmentContext);
  const finalAlignment = textAlignment && textAlignment !== import_v1.TextStyle_TextAlignment.AUTO ? textAlignment : parentAlignment;
  const listStylePosition = textAlignment && textAlignment === import_v1.TextStyle_TextAlignment.CENTER;
  const { parentNode } = (0, import_react.useContext)(import_ricos_context.RicosNodeContext);
  const indentation = visibleIndentation && visibleIndentation?.nodeId === parentNode?.id ? (0, import_wix_rich_content_common.normalizeOffset)(visibleIndentation?.indentation) : 0;
  const marginInlineStart = (0, import_get_start_margin.getStartMargin)(parentNode, visibleIndentation?.indentation || 0);
  const isCheckboxList = parentNode?.type === import_ricos_types.Node_Type.CHECKBOX_LIST;
  const marker = isCheckboxList ? "none" : parentNode ? (0, import_wix_rich_content_common.getListSymbol)(indentation, parentNode.type) : "";
  const isParentOfHeading = firstChild?.type === import_ricos_types.Node_Type.HEADING;
  const headingLevel = isParentOfHeading && firstChild.headingData?.level;
  const listItemClassName = (0, import_classnames.default)(
    import_lists_scss.default.listItem,
    (0, import_paywall_seo.isPaywallSeo)(seoMode) && (0, import_paywall_seo.getPaywallSeoClass)(seoMode?.paywall || {}, nodeIndex + parentIndex)
  );
  const childFontSize = firstChild?.nodes?.[0]?.textData?.decorations?.find(
    (decoration) => decoration.type === import_ricos_types.Decoration_Type.FONT_SIZE
  )?.fontSizeData?.value;
  const shouldFitChildFont = !!childFontSize && childFontSize < (0, import_get_block_default_font_size.getBlockDefaultFontSize)(headingLevel || void 0);
  return /* @__PURE__ */ import_react.default.createElement(
    "li",
    {
      dir: "auto",
      "aria-level": indentation + 1,
      className: listItemClassName,
      style: {
        textAlign: finalAlignment,
        fontSize: childFontSize,
        marginInlineStart,
        listStyleType: marker
      },
      ...shouldFitChildFont ? { "data-child-font-fit": "true" } : {},
      ...headingLevel ? {
        "data-heading-level": import_heading.levelToClassName[headingLevel]
      } : {},
      ...listStylePosition ? { "data-list-style-position": "inside" } : {},
      ...isCheckboxList ? {
        "data-list-style": import_checkbox_list_style.CHECKBOX_LIST_STYLE_ATTRIBUTE_VALUE,
        role: "checkbox",
        "aria-checked": listItemNode.listItemData?.checked ? "true" : "false"
      } : {}
    },
    isCheckboxList && // Viewer marker is presentational only; the actual checkbox control exists only in editing.
    /* @__PURE__ */ import_react.default.createElement(
      "span",
      {
        "aria-hidden": true,
        className: import_lists_scss.default.checkboxInput,
        "aria-checked": listItemNode.listItemData?.checked ? "true" : "false"
      }
    ),
    /* @__PURE__ */ import_react.default.createElement(import_ricos_context.RicosDirectionHandledContextProvider, { directionHandled: true }, /* @__PURE__ */ import_react.default.createElement(import_ricos_context.RicosNodeContextProvider, { parentNode: node, parentIndex: nodeIndex }, /* @__PURE__ */ import_react.default.createElement(RicosNodesRenderer, { nodes: node.nodes ?? [], shouldParagraphApplyTextStyle: true })))
  );
};
const ListItemRenderer = ({ node, ...props }) => {
  return /* @__PURE__ */ import_react.default.createElement(ListItem, { key: node.id, node, ...props });
};
var list_item_default = ListItemRenderer;
//# sourceMappingURL=list-item.js.map
