import { getPointBefore as a, getParentNode as c, getStartPoint as p, select as u } from "@udecode/slate";
import { KEY_ELEMENT_BREAK_AFTER_COLUMN as l } from "./createColumnBreakPlugin.es.js";
import { setColumnBreaks as f } from "./utils/setColumnBreaks.es.js";
import { updateColumnBreaks as m } from "./utils/updateColumnBreaks.es.js";
const C = (t, s) => {
  const e = p(t, s);
  setTimeout(() => {
    u(t, {
      anchor: e,
      focus: e
    });
  });
}, k = (t) => {
  var e;
  const s = t.plugins.find((o) => o.key === l);
  return ((e = s == null ? void 0 : s.options) == null ? void 0 : e.columns) ?? 1;
}, g = (t) => {
  const { apply: s } = t, e = k(t);
  t.apply = (o) => {
    switch (o.type) {
      case "split_node": {
        o.properties = { ...o.properties, breakAfterColumn: void 0 };
        break;
      }
      case "merge_node": {
        const n = a(t, o.path);
        if (!n)
          break;
        const r = c(t, n.path);
        if (f(t, { at: n, value: void 0 }), m(t, e), r != null && r[0].breakAfterColumn)
          return C(t, o.path), t;
        break;
      }
    }
    s(o);
  }, setTimeout(() => m(t, e));
};
export {
  g as columnBreakHandler
};
//# sourceMappingURL=columnBreakHandler.es.js.map
