"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.useHasBlockToolbar = useHasBlockToolbar;
var _data = require("@wordpress/data");
var _blocks = require("@wordpress/blocks");
var _store = require("../../store");
var _useHasBlockControls = require("../block-controls/use-has-block-controls");
/**
 * WordPress dependencies
 */

/**
 * Internal dependencies
 */

/**
 * Returns true if the block toolbar should be shown.
 *
 * @return {boolean} Whether the block toolbar component will be rendered.
 */
function useHasBlockToolbar() {
  const {
    isToolbarEnabled,
    isBlockDisabled
  } = (0, _data.useSelect)(select => {
    const {
      getBlockEditingMode,
      getBlockName,
      getBlockSelectionStart
    } = select(_store.store);

    // we only care about the 1st selected block
    // for the toolbar, so we use getBlockSelectionStart
    // instead of getSelectedBlockClientIds
    const selectedBlockClientId = getBlockSelectionStart();
    const blockType = selectedBlockClientId && (0, _blocks.getBlockType)(getBlockName(selectedBlockClientId));
    return {
      isToolbarEnabled: blockType && (0, _blocks.hasBlockSupport)(blockType, '__experimentalToolbar', true),
      isBlockDisabled: getBlockEditingMode(selectedBlockClientId) === 'disabled'
    };
  }, []);
  const hasAnyBlockControls = (0, _useHasBlockControls.useHasAnyBlockControls)();
  if (!isToolbarEnabled || isBlockDisabled && !hasAnyBlockControls) {
    return false;
  }
  return true;
}
//# sourceMappingURL=use-has-block-toolbar.js.map