import React, { useContext } from "react";
import { EditorContext, ModalServiceContext } from "./../../ricos-context/index.js";
import { logInvariant } from "./../../_shared/log-invariant.js";
import { SHAPES_CATEGORY_ID } from "./../../_shared/shape-select-modal/consts.js";
import { ShapeSelectModal } from "./../../_shared/shape-select-modal/shape-select-modal.js";
import { DATA_HOOKS } from "../data-hooks.js";
const SmartBlockShapePickerModal = (props) => {
  const { adapter } = useContext(EditorContext);
  const modalService = useContext(ModalServiceContext) || {};
  const closeModal = () => modalService.closeModal(DATA_HOOKS.CELL_SHAPE_PICKER);
  const onShapeSelect = (shape) => {
    const shapeData = shape.assets?.vector?.image;
    if (!shapeData) {
      logInvariant(new Error("Shape data not found"));
      return;
    }
    closeModal();
    const src = shapeData.id ? { id: shapeData.id } : { url: shapeData.url };
    if ("cellId" in props) {
      adapter.tiptapEditor.commands.updateNodeAttrsById(props.cellId, { shape: { src } });
      adapter.tiptapEditor.chain().selectSmartBlockCell(props.cellId).focus(void 0, { scrollIntoView: false }).run();
    } else {
      adapter.tiptapEditor.commands.applyShapeToAllCells({ src });
    }
  };
  return /* @__PURE__ */ React.createElement(
    ShapeSelectModal,
    {
      onShapeSelect,
      onClose: closeModal,
      allowedCategoryIds: [SHAPES_CATEGORY_ID]
    }
  );
};
export {
  SmartBlockShapePickerModal
};
//# sourceMappingURL=smart-block-shape-picker-modal.js.map
