"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 checkbox_state_normalizing_exports = {};
__export(checkbox_state_normalizing_exports, {
  createCheckboxStateNormalizingTransactionPlugin: () => createCheckboxStateNormalizingTransactionPlugin
});
module.exports = __toCommonJS(checkbox_state_normalizing_exports);
var import_v1 = require("./../../ricos-schema/legacy/wix/rich_content/v1/index.js");
var import_state = require("./../../tiptap/pm/state.js");
var import_commons = require("../list-item/commands/commons.js");
const createCheckboxStateNormalizingTransactionPlugin = () => new import_state.Plugin({
  key: new import_state.PluginKey("normalize-checkbox-state"),
  appendTransaction: (_, oldState, newState) => {
    if (newState.doc === oldState.doc) {
      return;
    }
    const tr = newState.tr;
    let changed = false;
    newState.doc.descendants((node, pos) => {
      if (node.type.name !== import_v1.Node_Type.LIST_ITEM || node.attrs.checked === null) {
        return;
      }
      const parentList = (0, import_commons.findParentList)(newState.doc.resolve(pos));
      if (!parentList || parentList.node.type.name !== import_v1.Node_Type.CHECKBOX_LIST) {
        tr.setNodeAttribute(pos, "checked", null);
        changed = true;
      }
    });
    return changed ? tr : void 0;
  }
});
//# sourceMappingURL=checkbox-state-normalizing.js.map
