"use strict";
var __create = Object.create;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getProtoOf = Object.getPrototypeOf;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
  for (var name in all)
    __defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
  if (from && typeof from === "object" || typeof from === "function") {
    for (let key of __getOwnPropNames(from))
      if (!__hasOwnProp.call(to, key) && key !== except)
        __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
  }
  return to;
};
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
  // If the importer is in node compatibility mode or this is not an ESM
  // file that has been converted to a CommonJS file using a Babel-
  // compatible transform (i.e. "__esModule" has not been set), then set
  // "default" to the CommonJS "module.exports" for node compatibility.
  isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
  mod
));
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);

// packages/block-editor/src/components/grid/grid-item-movers.js
var grid_item_movers_exports = {};
__export(grid_item_movers_exports, {
  GridItemMovers: () => GridItemMovers
});
module.exports = __toCommonJS(grid_item_movers_exports);
var import_clsx = __toESM(require("clsx"));
var import_i18n = require("@wordpress/i18n");
var import_components = require("@wordpress/components");
var import_icons = require("@wordpress/icons");
var import_data = require("@wordpress/data");
var import_compose = require("@wordpress/compose");
var import_block_controls = __toESM(require("../block-controls"));
var import_use_get_number_of_blocks_before_cell = require("./use-get-number-of-blocks-before-cell");
var import_store = require("../../store");
var import_jsx_runtime = require("react/jsx-runtime");
function GridItemMovers({
  layout,
  parentLayout,
  onChange,
  gridClientId,
  blockClientId
}) {
  const { moveBlocksToPosition, __unstableMarkNextChangeAsNotPersistent } = (0, import_data.useDispatch)(import_store.store);
  const columnStart = layout?.columnStart ?? 1;
  const rowStart = layout?.rowStart ?? 1;
  const columnSpan = layout?.columnSpan ?? 1;
  const rowSpan = layout?.rowSpan ?? 1;
  const columnEnd = columnStart + columnSpan - 1;
  const rowEnd = rowStart + rowSpan - 1;
  const columnCount = parentLayout?.columnCount;
  const rowCount = parentLayout?.rowCount;
  const getNumberOfBlocksBeforeCell = (0, import_use_get_number_of_blocks_before_cell.useGetNumberOfBlocksBeforeCell)(
    gridClientId,
    columnCount
  );
  return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_block_controls.default, { group: "parent", children: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_components.ToolbarGroup, { className: "block-editor-grid-item-mover__move-button-container", children: [
    /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: "block-editor-grid-item-mover__move-horizontal-button-container is-left", children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
      GridItemMover,
      {
        icon: (0, import_i18n.isRTL)() ? import_icons.chevronRight : import_icons.chevronLeft,
        label: (0, import_i18n.__)("Move left"),
        description: (0, import_i18n.__)("Move left"),
        isDisabled: columnStart <= 1,
        onClick: () => {
          onChange({
            columnStart: columnStart - 1
          });
          __unstableMarkNextChangeAsNotPersistent();
          moveBlocksToPosition(
            [blockClientId],
            gridClientId,
            gridClientId,
            getNumberOfBlocksBeforeCell(
              columnStart - 1,
              rowStart
            )
          );
        }
      }
    ) }),
    /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "block-editor-grid-item-mover__move-vertical-button-container", children: [
      /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
        GridItemMover,
        {
          className: "is-up-button",
          icon: import_icons.chevronUp,
          label: (0, import_i18n.__)("Move up"),
          description: (0, import_i18n.__)("Move up"),
          isDisabled: rowStart <= 1,
          onClick: () => {
            onChange({
              rowStart: rowStart - 1
            });
            __unstableMarkNextChangeAsNotPersistent();
            moveBlocksToPosition(
              [blockClientId],
              gridClientId,
              gridClientId,
              getNumberOfBlocksBeforeCell(
                columnStart,
                rowStart - 1
              )
            );
          }
        }
      ),
      /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
        GridItemMover,
        {
          className: "is-down-button",
          icon: import_icons.chevronDown,
          label: (0, import_i18n.__)("Move down"),
          description: (0, import_i18n.__)("Move down"),
          isDisabled: rowCount && rowEnd >= rowCount,
          onClick: () => {
            onChange({
              rowStart: rowStart + 1
            });
            __unstableMarkNextChangeAsNotPersistent();
            moveBlocksToPosition(
              [blockClientId],
              gridClientId,
              gridClientId,
              getNumberOfBlocksBeforeCell(
                columnStart,
                rowStart + 1
              )
            );
          }
        }
      )
    ] }),
    /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: "block-editor-grid-item-mover__move-horizontal-button-container is-right", children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
      GridItemMover,
      {
        icon: (0, import_i18n.isRTL)() ? import_icons.chevronLeft : import_icons.chevronRight,
        label: (0, import_i18n.__)("Move right"),
        description: (0, import_i18n.__)("Move right"),
        isDisabled: columnCount && columnEnd >= columnCount,
        onClick: () => {
          onChange({
            columnStart: columnStart + 1
          });
          __unstableMarkNextChangeAsNotPersistent();
          moveBlocksToPosition(
            [blockClientId],
            gridClientId,
            gridClientId,
            getNumberOfBlocksBeforeCell(
              columnStart + 1,
              rowStart
            )
          );
        }
      }
    ) })
  ] }) });
}
function GridItemMover({
  className,
  icon,
  label,
  isDisabled,
  onClick,
  description
}) {
  const instanceId = (0, import_compose.useInstanceId)(GridItemMover);
  const descriptionId = `block-editor-grid-item-mover-button__description-${instanceId}`;
  return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment, { children: [
    /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
      import_components.ToolbarButton,
      {
        className: (0, import_clsx.default)(
          "block-editor-grid-item-mover-button",
          className
        ),
        icon,
        label,
        "aria-describedby": descriptionId,
        onClick: isDisabled ? null : onClick,
        disabled: isDisabled,
        accessibleWhenDisabled: true
      }
    ),
    /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_components.VisuallyHidden, { id: descriptionId, children: description })
  ] });
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
  GridItemMovers
});
//# sourceMappingURL=grid-item-movers.js.map
