// packages/block-editor/src/hooks/grid-visualizer.js
import { createHigherOrderComponent } from "@wordpress/compose";
import { addFilter } from "@wordpress/hooks";
import { useSelect } from "@wordpress/data";
import { GridVisualizer, useGridLayoutSync } from "../components/grid";
import { store as blockEditorStore } from "../store";
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
function GridLayoutSync(props) {
  useGridLayoutSync(props);
}
function GridTools({ clientId, layout }) {
  const isVisible = useSelect(
    (select) => {
      const {
        isBlockSelected,
        isDraggingBlocks,
        getTemplateLock,
        getBlockEditingMode
      } = select(blockEditorStore);
      if (!isDraggingBlocks() && !isBlockSelected(clientId) || getTemplateLock(clientId) || getBlockEditingMode(clientId) !== "default") {
        return false;
      }
      return true;
    },
    [clientId]
  );
  return /* @__PURE__ */ jsxs(Fragment, { children: [
    /* @__PURE__ */ jsx(GridLayoutSync, { clientId }),
    isVisible && /* @__PURE__ */ jsx(GridVisualizer, { clientId, parentLayout: layout })
  ] });
}
var addGridVisualizerToBlockEdit = createHigherOrderComponent(
  (BlockEdit) => (props) => {
    if (props.attributes.layout?.type !== "grid") {
      return /* @__PURE__ */ jsx(BlockEdit, { ...props }, "edit");
    }
    return /* @__PURE__ */ jsxs(Fragment, { children: [
      /* @__PURE__ */ jsx(
        GridTools,
        {
          clientId: props.clientId,
          layout: props.attributes.layout
        }
      ),
      /* @__PURE__ */ jsx(BlockEdit, { ...props }, "edit")
    ] });
  },
  "addGridVisualizerToBlockEdit"
);
addFilter(
  "editor.BlockEdit",
  "core/editor/grid-visualizer",
  addGridVisualizerToBlockEdit
);
//# sourceMappingURL=grid-visualizer.js.map
