"use strict";
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
const jsxRuntime = require("react/jsx-runtime");
const ui = require("@contember/ui");
const utilities = require("@contember/utilities");
const react = require("react");
const Slate = require("slate");
const slateReact = require("slate-react");
const TableElement = require("./TableElement.cjs");
const TableModifications = require("./TableModifications.cjs");
const BlockElement = require("../../../baseEditor/BlockElement.cjs");
const TableElementRenderer = react.memo(function TableElementRenderer2(props) {
  const editor = slateReact.useSlateStatic();
  const isSelected = slateReact.useSelected();
  const isFocused = false;
  const extendTable = react.useCallback(
    (vector, index) => {
      if (vector === "row") {
        TableModifications.TableModifications.addTableRow(editor, props.element, index);
      } else if (vector === "column") {
        TableModifications.TableModifications.addTableColumn(editor, props.element, index);
      } else {
        utilities.assertNever(vector);
      }
    },
    [editor, props.element]
  );
  const shrinkTable = react.useCallback(
    (vector, index) => {
      if (vector === "row") {
        TableModifications.TableModifications.deleteTableRow(editor, props.element, index);
      } else if (vector === "column") {
        TableModifications.TableModifications.deleteTableColumn(editor, props.element, index);
      } else {
        utilities.assertNever(vector);
      }
    },
    [editor, props.element]
  );
  const toggleRowHeaderScope = react.useCallback(
    (index, scope) => {
      TableModifications.TableModifications.toggleTableRowHeaderScope(editor, props.element, index, scope);
    },
    [editor, props.element]
  );
  const toggleColumnHeaderScope = react.useCallback(
    (index, scope) => {
      TableModifications.TableModifications.toggleTableColumnHeaderScope(editor, props.element, index, scope);
    },
    [editor, props.element]
  );
  const justifyColumn = react.useCallback(
    (index, direction) => TableModifications.TableModifications.justifyTableColumn(editor, props.element, index, direction),
    [editor, props.element]
  );
  const deleteTable = react.useCallback(() => {
    Promise.resolve().then(() => {
      Slate.Transforms.removeNodes(editor, {
        at: slateReact.ReactEditor.findPath(editor, props.element),
        match: (node) => TableElement.isTableElement(node)
      });
    });
  }, [editor, props.element]);
  return /* @__PURE__ */ jsxRuntime.jsx(BlockElement.BlockElement, { element: props.element, attributes: props.attributes, withBoundaries: true, children: /* @__PURE__ */ jsxRuntime.jsx(
    ui.EditorTableElement,
    {
      rowCount: props.element.children.length,
      columnCount: props.element.children[0]?.children.length ?? 0,
      extendTable,
      shrinkTable,
      toggleRowHeaderScope,
      toggleColumnHeaderScope,
      justifyColumn,
      deleteTable,
      isSelected,
      isFocused,
      children: props.children
    }
  ) });
});
exports.TableElementRenderer = TableElementRenderer;
//# sourceMappingURL=TableElementRenderer.cjs.map
