"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-library/src/list-item/hooks/use-indent-list-item.js
var use_indent_list_item_exports = {};
__export(use_indent_list_item_exports, {
  default: () => useIndentListItem
});
module.exports = __toCommonJS(use_indent_list_item_exports);
var import_element = require("@wordpress/element");
var import_data = require("@wordpress/data");
var import_block_editor = require("@wordpress/block-editor");
var import_blocks = require("@wordpress/blocks");
function useIndentListItem(clientId) {
  const { replaceBlocks, selectionChange, multiSelect } = (0, import_data.useDispatch)(import_block_editor.store);
  const {
    getBlock,
    getPreviousBlockClientId,
    getSelectionStart,
    getSelectionEnd,
    hasMultiSelection,
    getMultiSelectedBlockClientIds
  } = (0, import_data.useSelect)(import_block_editor.store);
  return (0, import_element.useCallback)(() => {
    const _hasMultiSelection = hasMultiSelection();
    const clientIds = _hasMultiSelection ? getMultiSelectedBlockClientIds() : [clientId];
    const clonedBlocks = clientIds.map(
      (_clientId) => (0, import_blocks.cloneBlock)(getBlock(_clientId))
    );
    const previousSiblingId = getPreviousBlockClientId(clientId);
    const newListItem = (0, import_blocks.cloneBlock)(getBlock(previousSiblingId));
    if (!newListItem.innerBlocks?.length) {
      newListItem.innerBlocks = [(0, import_blocks.createBlock)("core/list")];
    }
    newListItem.innerBlocks[newListItem.innerBlocks.length - 1].innerBlocks.push(...clonedBlocks);
    const selectionStart = getSelectionStart();
    const selectionEnd = getSelectionEnd();
    replaceBlocks([previousSiblingId, ...clientIds], [newListItem]);
    if (!_hasMultiSelection) {
      selectionChange(
        clonedBlocks[0].clientId,
        selectionEnd.attributeKey,
        selectionEnd.clientId === selectionStart.clientId ? selectionStart.offset : selectionEnd.offset,
        selectionEnd.offset
      );
    } else {
      multiSelect(
        clonedBlocks[0].clientId,
        clonedBlocks[clonedBlocks.length - 1].clientId
      );
    }
    return true;
  }, [clientId]);
}
//# sourceMappingURL=use-indent-list-item.js.map
