"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.default = BlockParentSelectorMenuItem;
var _element = require("@wordpress/element");
var _components = require("@wordpress/components");
var _compose = require("@wordpress/compose");
var _data = require("@wordpress/data");
var _i18n = require("@wordpress/i18n");
var _blockIcon = _interopRequireDefault(require("../block-icon"));
var _utils = require("../block-toolbar/utils");
var _store = require("../../store");
var _jsxRuntime = require("react/jsx-runtime");
/**
 * WordPress dependencies
 */

/**
 * Internal dependencies
 */

function BlockParentSelectorMenuItem({
  parentClientId,
  parentBlockType
}) {
  const isSmallViewport = (0, _compose.useViewportMatch)('medium', '<');
  const {
    selectBlock
  } = (0, _data.useDispatch)(_store.store);

  // Allows highlighting the parent block outline when focusing or hovering
  // the parent block selector within the child.
  const menuItemRef = (0, _element.useRef)();
  const gesturesProps = (0, _utils.useShowHoveredOrFocusedGestures)({
    ref: menuItemRef,
    highlightParent: true
  });
  if (!isSmallViewport) {
    return null;
  }
  return /*#__PURE__*/(0, _jsxRuntime.jsx)(_components.MenuItem, {
    ...gesturesProps,
    ref: menuItemRef,
    icon: /*#__PURE__*/(0, _jsxRuntime.jsx)(_blockIcon.default, {
      icon: parentBlockType.icon
    }),
    onClick: () => selectBlock(parentClientId),
    children: (0, _i18n.sprintf)( /* translators: %s: Name of the block's parent. */
    (0, _i18n.__)('Select parent block (%s)'), parentBlockType.title)
  });
}
//# sourceMappingURL=block-parent-selector-menu-item.js.map