import { jsxDEV } from "react/jsx-dev-runtime";
import { EditorTableElement } from "@contember/ui";
import { assertNever } from "@contember/utilities";
import { memo, useCallback } from "react";
import { Transforms } from "slate";
import { useSlateStatic, useSelected, ReactEditor } from "slate-react";
import { isTableElement } from "./TableElement.js";
import { TableModifications } from "./TableModifications.js";
import { BlockElement } from "../../../baseEditor/BlockElement.js";
const TableElementRenderer = memo(function TableElementRenderer2(props) {
  const editor = useSlateStatic();
  const isSelected = useSelected();
  const isFocused = false;
  const extendTable = useCallback(
    (vector, index) => {
      if (vector === "row") {
        TableModifications.addTableRow(editor, props.element, index);
      } else if (vector === "column") {
        TableModifications.addTableColumn(editor, props.element, index);
      } else {
        assertNever(vector);
      }
    },
    [editor, props.element]
  );
  const shrinkTable = useCallback(
    (vector, index) => {
      if (vector === "row") {
        TableModifications.deleteTableRow(editor, props.element, index);
      } else if (vector === "column") {
        TableModifications.deleteTableColumn(editor, props.element, index);
      } else {
        assertNever(vector);
      }
    },
    [editor, props.element]
  );
  const toggleRowHeaderScope = useCallback(
    (index, scope) => {
      TableModifications.toggleTableRowHeaderScope(editor, props.element, index, scope);
    },
    [editor, props.element]
  );
  const toggleColumnHeaderScope = useCallback(
    (index, scope) => {
      TableModifications.toggleTableColumnHeaderScope(editor, props.element, index, scope);
    },
    [editor, props.element]
  );
  const justifyColumn = useCallback(
    (index, direction) => TableModifications.justifyTableColumn(editor, props.element, index, direction),
    [editor, props.element]
  );
  const deleteTable = useCallback(() => {
    Promise.resolve().then(() => {
      Transforms.removeNodes(editor, {
        at: ReactEditor.findPath(editor, props.element),
        match: (node) => isTableElement(node)
      });
    });
  }, [editor, props.element]);
  return /* @__PURE__ */ jsxDEV(BlockElement, { element: props.element, attributes: props.attributes, withBoundaries: true, children: /* @__PURE__ */ jsxDEV(
    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
    },
    void 0,
    false,
    {
      fileName: "/__w/interface/interface/packages/admin/src/components/bindingFacade/richText/plugins/element/tables/TableElementRenderer.tsx",
      lineNumber: 107,
      columnNumber: 4
    },
    this
  ) }, void 0, false, {
    fileName: "/__w/interface/interface/packages/admin/src/components/bindingFacade/richText/plugins/element/tables/TableElementRenderer.tsx",
    lineNumber: 106,
    columnNumber: 3
  }, this);
});
export {
  TableElementRenderer
};
//# sourceMappingURL=TableElementRenderer.js.map
