// packages/block-editor/src/components/block-settings-menu-controls/index.js
import {
  createSlotFill,
  MenuGroup,
  __experimentalStyleProvider as StyleProvider
} from "@wordpress/components";
import { hasBlockSupport } from "@wordpress/blocks";
import { useSelect } from "@wordpress/data";
import {
  useConvertToGroupButtonProps,
  ConvertToGroupButton
} from "../convert-to-group-buttons";
import { BlockLockMenuItem, useBlockLock } from "../block-lock";
import { store as blockEditorStore } from "../../store";
import BlockModeToggle from "../block-settings-menu/block-mode-toggle";
import { ModifyContentOnlySectionMenuItem } from "../content-lock";
import { BlockRenameControl, useBlockRename } from "../block-rename";
import { BlockVisibilityMenuItem } from "../block-visibility";
import { EditSectionMenuItem } from "./edit-section-menu-item";
import { jsx, jsxs } from "react/jsx-runtime";
var { Fill, Slot } = createSlotFill("BlockSettingsMenuControls");
var BlockSettingsMenuControlsSlot = ({ fillProps, clientIds = null }) => {
  const {
    selectedBlocks,
    selectedClientIds,
    isContentOnly,
    canToggleSelectedBlocksVisibility
  } = useSelect(
    (select) => {
      const {
        getBlocksByClientId,
        getBlockNamesByClientId,
        getSelectedBlockClientIds,
        getBlockEditingMode
      } = select(blockEditorStore);
      const ids = clientIds !== null ? clientIds : getSelectedBlockClientIds();
      return {
        selectedBlocks: getBlockNamesByClientId(ids),
        selectedClientIds: ids,
        isContentOnly: getBlockEditingMode(ids[0]) === "contentOnly",
        canToggleSelectedBlocksVisibility: getBlocksByClientId(
          ids
        ).every(
          (block) => hasBlockSupport(block.name, "visibility", true)
        )
      };
    },
    [clientIds]
  );
  const { canLock } = useBlockLock(selectedClientIds[0]);
  const { canRename } = useBlockRename(selectedBlocks[0]);
  const showLockButton = selectedClientIds.length === 1 && canLock && !isContentOnly;
  const showRenameButton = selectedClientIds.length === 1 && canRename && !isContentOnly;
  const showVisibilityButton = canToggleSelectedBlocksVisibility && !isContentOnly;
  const convertToGroupButtonProps = useConvertToGroupButtonProps(selectedClientIds);
  const { isGroupable, isUngroupable } = convertToGroupButtonProps;
  const showConvertToGroupButton = (isGroupable || isUngroupable) && !isContentOnly;
  return /* @__PURE__ */ jsx(
    Slot,
    {
      fillProps: {
        ...fillProps,
        selectedBlocks,
        selectedClientIds
      },
      children: (fills) => {
        if (!fills?.length > 0 && !showConvertToGroupButton && !showLockButton) {
          return null;
        }
        return /* @__PURE__ */ jsxs(MenuGroup, { children: [
          showConvertToGroupButton && /* @__PURE__ */ jsx(
            ConvertToGroupButton,
            {
              ...convertToGroupButtonProps,
              onClose: fillProps?.onClose
            }
          ),
          selectedClientIds.length === 1 && /* @__PURE__ */ jsx(
            EditSectionMenuItem,
            {
              clientId: selectedClientIds[0],
              onClose: fillProps?.onClose
            }
          ),
          showLockButton && /* @__PURE__ */ jsx(
            BlockLockMenuItem,
            {
              clientId: selectedClientIds[0]
            }
          ),
          showRenameButton && /* @__PURE__ */ jsx(
            BlockRenameControl,
            {
              clientId: selectedClientIds[0]
            }
          ),
          showVisibilityButton && /* @__PURE__ */ jsx(
            BlockVisibilityMenuItem,
            {
              clientIds: selectedClientIds
            }
          ),
          fills,
          selectedClientIds.length === 1 && /* @__PURE__ */ jsx(
            ModifyContentOnlySectionMenuItem,
            {
              clientId: selectedClientIds[0],
              onClose: fillProps?.onClose
            }
          ),
          fillProps?.count === 1 && !isContentOnly && /* @__PURE__ */ jsx(
            BlockModeToggle,
            {
              clientId: fillProps?.firstBlockClientId,
              onToggle: fillProps?.onClose
            }
          )
        ] });
      }
    }
  );
};
function BlockSettingsMenuControls({ ...props }) {
  return /* @__PURE__ */ jsx(StyleProvider, { document, children: /* @__PURE__ */ jsx(Fill, { ...props }) });
}
BlockSettingsMenuControls.Slot = BlockSettingsMenuControlsSlot;
var block_settings_menu_controls_default = BlockSettingsMenuControls;
export {
  block_settings_menu_controls_default as default
};
//# sourceMappingURL=index.js.map
