// packages/block-editor/src/components/writing-flow/use-multi-selection.js
import { useRefEffect } from "@wordpress/compose";
import { useSelect } from "@wordpress/data";
import { store as blockEditorStore } from "../../store";
function selector(select) {
  const {
    isMultiSelecting,
    getMultiSelectedBlockClientIds,
    hasMultiSelection,
    getSelectedBlockClientId,
    getSelectedBlocksInitialCaretPosition,
    __unstableIsFullySelected
  } = select(blockEditorStore);
  return {
    isMultiSelecting: isMultiSelecting(),
    multiSelectedBlockClientIds: getMultiSelectedBlockClientIds(),
    hasMultiSelection: hasMultiSelection(),
    selectedBlockClientId: getSelectedBlockClientId(),
    initialPosition: getSelectedBlocksInitialCaretPosition(),
    isFullSelection: __unstableIsFullySelected()
  };
}
function useMultiSelection() {
  const {
    initialPosition,
    isMultiSelecting,
    multiSelectedBlockClientIds,
    hasMultiSelection,
    selectedBlockClientId,
    isFullSelection
  } = useSelect(selector, []);
  return useRefEffect(
    (node) => {
      const { ownerDocument } = node;
      const { defaultView } = ownerDocument;
      if (initialPosition === void 0 || initialPosition === null) {
        return;
      }
      if (!hasMultiSelection || isMultiSelecting) {
        return;
      }
      const { length } = multiSelectedBlockClientIds;
      if (length < 2) {
        return;
      }
      if (!isFullSelection) {
        return;
      }
      node.contentEditable = true;
      node.focus();
      defaultView.getSelection().removeAllRanges();
    },
    [
      hasMultiSelection,
      isMultiSelecting,
      multiSelectedBlockClientIds,
      selectedBlockClientId,
      initialPosition,
      isFullSelection
    ]
  );
}
export {
  useMultiSelection as default
};
//# sourceMappingURL=use-multi-selection.js.map
