var b = Object.defineProperty;
var p = (i, e, t) => e in i ? b(i, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : i[e] = t;
var s = (i, e, t) => (p(i, typeof e != "symbol" ? e + "" : e, t), t);
import w from "../blots/block.mjs";
import u from "../blots/container.mjs";
const h = class h extends w {
  static create(e) {
    const t = super.create();
    return e ? t.setAttribute("data-row", e) : t.setAttribute("data-row", m()), t;
  }
  static formats(e) {
    if (e.hasAttribute("data-row"))
      return e.getAttribute("data-row");
  }
  cellOffset() {
    return this.parent ? this.parent.children.indexOf(this) : -1;
  }
  format(e, t) {
    e === h.blotName && t ? this.domNode.setAttribute("data-row", t) : super.format(e, t);
  }
  row() {
    return this.parent;
  }
  rowOffset() {
    return this.row() ? this.row().rowOffset() : -1;
  }
  table() {
    return this.row() && this.row().table();
  }
};
s(h, "blotName", "table"), s(h, "tagName", "TD");
let l = h;
class c extends u {
  checkMerge() {
    if (super.checkMerge() && this.next.children.head != null) {
      const e = this.children.head.formats(), t = this.children.tail.formats(), r = this.next.children.head.formats(), n = this.next.children.tail.formats();
      return e.table === t.table && e.table === r.table && e.table === n.table;
    }
    return !1;
  }
  optimize(e) {
    super.optimize(e), this.children.forEach((t) => {
      if (t.next == null)
        return;
      const r = t.formats(), n = t.next.formats();
      if (r.table !== n.table) {
        const a = this.splitAfter(t);
        a && a.optimize(), this.prev && this.prev.optimize();
      }
    });
  }
  rowOffset() {
    return this.parent ? this.parent.children.indexOf(this) : -1;
  }
  table() {
    return this.parent && this.parent.parent;
  }
}
s(c, "blotName", "table-row"), s(c, "tagName", "TR");
class o extends u {
}
s(o, "blotName", "table-body"), s(o, "tagName", "TBODY");
class d extends u {
  balanceCells() {
    const e = this.descendants(c), t = e.reduce((r, n) => Math.max(n.children.length, r), 0);
    e.forEach((r) => {
      new Array(t - r.children.length).fill(0).forEach(() => {
        let n;
        r.children.head != null && (n = l.formats(r.children.head.domNode));
        const a = this.scroll.create(l.blotName, n);
        r.appendChild(a), a.optimize();
      });
    });
  }
  cells(e) {
    return this.rows().map((t) => t.children.at(e));
  }
  deleteColumn(e) {
    const [t] = this.descendant(o);
    t == null || t.children.head == null || t.children.forEach((r) => {
      const n = r.children.at(e);
      n != null && n.remove();
    });
  }
  insertColumn(e) {
    const [t] = this.descendant(o);
    t == null || t.children.head == null || t.children.forEach((r) => {
      const n = r.children.at(e), a = l.formats(r.children.head.domNode), f = this.scroll.create(l.blotName, a);
      r.insertBefore(f, n);
    });
  }
  insertRow(e) {
    const [t] = this.descendant(o);
    if (t == null || t.children.head == null)
      return;
    const r = m(), n = this.scroll.create(c.blotName);
    t.children.head.children.forEach(() => {
      const f = this.scroll.create(l.blotName, r);
      n.appendChild(f);
    });
    const a = t.children.at(e);
    t.insertBefore(n, a);
  }
  rows() {
    const e = this.children.head;
    return e == null ? [] : e.children.map((t) => t);
  }
}
s(d, "blotName", "table-container"), s(d, "tagName", "TABLE");
d.allowedChildren = [o];
o.requiredContainer = d;
o.allowedChildren = [c];
c.requiredContainer = o;
c.allowedChildren = [l];
l.requiredContainer = c;
function m() {
  return `row-${Math.random().toString(36).slice(2, 6)}`;
}
export {
  o as TableBody,
  l as TableCell,
  d as TableContainer,
  c as TableRow,
  m as tableId
};
