"use strict";
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
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 __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var is_strikethrough_blocked_by_checkbox_list_selection_exports = {};
__export(is_strikethrough_blocked_by_checkbox_list_selection_exports, {
  isStrikethroughBlockedByCheckboxListSelection: () => isStrikethroughBlockedByCheckboxListSelection
});
module.exports = __toCommonJS(is_strikethrough_blocked_by_checkbox_list_selection_exports);
var import_v1 = require("./../../ricos-schema/legacy/wix/rich_content/v1/index.js");
const StrikethroughState = {
  Enabled: "enabled",
  Disabled: "disabled"
};
const getInnermostCheckboxListItemAtPos = ($pos) => {
  for (let depth = $pos.depth; depth > 0; depth--) {
    const node = $pos.node(depth);
    if (node.type.name !== import_v1.Node_Type.LIST_ITEM) {
      continue;
    }
    const parent = $pos.node(depth - 1);
    if (parent.type.name === import_v1.Node_Type.CHECKBOX_LIST) {
      return { checked: node.attrs.checked === true };
    }
  }
  return null;
};
const getStrikethroughStateAtPosition = ($pos) => getInnermostCheckboxListItemAtPos($pos)?.checked ? StrikethroughState.Disabled : StrikethroughState.Enabled;
const collectStrikethroughStates = (state) => {
  const { from, to } = state.selection;
  if (from === to) {
    return [getStrikethroughStateAtPosition(state.doc.resolve(from))];
  }
  const states = [];
  state.doc.nodesBetween(from, to, (node, pos) => {
    if (!node.isText) {
      return;
    }
    const textFrom = Math.max(from, pos);
    const textTo = Math.min(to, pos + node.nodeSize);
    states.push(getStrikethroughStateAtPosition(state.doc.resolve(textFrom)));
    if (textTo > textFrom + 1) {
      states.push(getStrikethroughStateAtPosition(state.doc.resolve(textTo - 1)));
    }
  });
  return states;
};
const isStrikethroughBlockedByCheckboxListSelection = (state) => {
  const states = collectStrikethroughStates(state);
  return states.length > 0 && states.every((s) => s === StrikethroughState.Disabled);
};
//# sourceMappingURL=is-strikethrough-blocked-by-checkbox-list-selection.js.map
