"use strict";
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
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 __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);

// packages/block-editor/src/components/convert-to-group-buttons/toolbar.js
var toolbar_exports = {};
__export(toolbar_exports, {
  default: () => toolbar_default
});
module.exports = __toCommonJS(toolbar_exports);
var import_data = require("@wordpress/data");
var import_blocks = require("@wordpress/blocks");
var import_components = require("@wordpress/components");
var import_icons = require("@wordpress/icons");
var import_i18n = require("@wordpress/i18n");
var import_convert_to_group_buttons = require("../convert-to-group-buttons");
var import_store = require("../../store");
var import_jsx_runtime = require("react/jsx-runtime");
var layouts = {
  group: { type: "constrained" },
  row: { type: "flex", flexWrap: "nowrap" },
  stack: { type: "flex", orientation: "vertical" },
  grid: { type: "grid" }
};
function BlockGroupToolbar() {
  const { blocksSelection, clientIds, groupingBlockName, isGroupable } = (0, import_convert_to_group_buttons.useConvertToGroupButtonProps)();
  const { replaceBlocks } = (0, import_data.useDispatch)(import_store.store);
  const { canRemove, variations } = (0, import_data.useSelect)(
    (select) => {
      const { canRemoveBlocks } = select(import_store.store);
      const { getBlockVariations } = select(import_blocks.store);
      return {
        canRemove: canRemoveBlocks(clientIds),
        variations: getBlockVariations(
          groupingBlockName,
          "transform"
        )
      };
    },
    [clientIds, groupingBlockName]
  );
  const onConvertToGroup = (layout) => {
    const newBlocks = (0, import_blocks.switchToBlockType)(
      blocksSelection,
      groupingBlockName
    );
    if (typeof layout !== "string") {
      layout = "group";
    }
    if (newBlocks && newBlocks.length > 0) {
      newBlocks[0].attributes.layout = layouts[layout];
      replaceBlocks(clientIds, newBlocks);
    }
  };
  const onConvertToRow = () => onConvertToGroup("row");
  const onConvertToStack = () => onConvertToGroup("stack");
  const onConvertToGrid = () => onConvertToGroup("grid");
  if (!isGroupable || !canRemove) {
    return null;
  }
  const canInsertRow = !!variations.find(
    ({ name }) => name === "group-row"
  );
  const canInsertStack = !!variations.find(
    ({ name }) => name === "group-stack"
  );
  const canInsertGrid = !!variations.find(
    ({ name }) => name === "group-grid"
  );
  return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_components.ToolbarGroup, { children: [
    /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
      import_components.ToolbarButton,
      {
        icon: import_icons.group,
        label: (0, import_i18n._x)("Group", "action: convert blocks to group"),
        onClick: onConvertToGroup
      }
    ),
    canInsertRow && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
      import_components.ToolbarButton,
      {
        icon: import_icons.row,
        label: (0, import_i18n._x)("Row", "action: convert blocks to row"),
        onClick: onConvertToRow
      }
    ),
    canInsertStack && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
      import_components.ToolbarButton,
      {
        icon: import_icons.stack,
        label: (0, import_i18n._x)("Stack", "action: convert blocks to stack"),
        onClick: onConvertToStack
      }
    ),
    canInsertGrid && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
      import_components.ToolbarButton,
      {
        icon: import_icons.grid,
        label: (0, import_i18n._x)("Grid", "action: convert blocks to grid"),
        onClick: onConvertToGrid
      }
    )
  ] });
}
var toolbar_default = BlockGroupToolbar;
//# sourceMappingURL=toolbar.js.map
