"use strict";

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