"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.default = void 0;
var _deprecated = _interopRequireDefault(require("@wordpress/deprecated"));
var _components = require("@wordpress/components");
var _i18n = require("@wordpress/i18n");
var _data = require("@wordpress/data");
var _element = require("@wordpress/element");
var _icons = require("@wordpress/icons");
var _listView = _interopRequireDefault(require("../list-view"));
var _store = require("../../store");
var _jsxRuntime = require("react/jsx-runtime");
/**
 * WordPress dependencies
 */

/**
 * WordPress dependencies
 */

/**
 * Internal dependencies
 */

function BlockNavigationDropdownToggle({
  isEnabled,
  onToggle,
  isOpen,
  innerRef,
  ...props
}) {
  return /*#__PURE__*/(0, _jsxRuntime.jsx)(_components.Button, {
    ...props,
    ref: innerRef,
    icon: _icons.listView,
    "aria-expanded": isOpen,
    "aria-haspopup": "true",
    onClick: isEnabled ? onToggle : undefined
    /* translators: button label text should, if possible, be under 16 characters. */,
    label: (0, _i18n.__)('List view'),
    className: "block-editor-block-navigation",
    "aria-disabled": !isEnabled
  });
}
function BlockNavigationDropdown({
  isDisabled,
  ...props
}, ref) {
  (0, _deprecated.default)('wp.blockEditor.BlockNavigationDropdown', {
    since: '6.1',
    alternative: 'wp.components.Dropdown and wp.blockEditor.ListView'
  });
  const hasBlocks = (0, _data.useSelect)(select => !!select(_store.store).getBlockCount(), []);
  const isEnabled = hasBlocks && !isDisabled;
  return /*#__PURE__*/(0, _jsxRuntime.jsx)(_components.Dropdown, {
    contentClassName: "block-editor-block-navigation__popover",
    popoverProps: {
      placement: 'bottom-start'
    },
    renderToggle: ({
      isOpen,
      onToggle
    }) => /*#__PURE__*/(0, _jsxRuntime.jsx)(BlockNavigationDropdownToggle, {
      ...props,
      innerRef: ref,
      isOpen: isOpen,
      onToggle: onToggle,
      isEnabled: isEnabled
    }),
    renderContent: () => /*#__PURE__*/(0, _jsxRuntime.jsxs)("div", {
      className: "block-editor-block-navigation__container",
      children: [/*#__PURE__*/(0, _jsxRuntime.jsx)("p", {
        className: "block-editor-block-navigation__label",
        children: (0, _i18n.__)('List view')
      }), /*#__PURE__*/(0, _jsxRuntime.jsx)(_listView.default, {})]
    })
  });
}
var _default = exports.default = (0, _element.forwardRef)(BlockNavigationDropdown);
//# sourceMappingURL=dropdown.js.map