"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.default = void 0;
var Ariakit = _interopRequireWildcard(require("@ariakit/react"));
var _element = require("@wordpress/element");
var _warning = _interopRequireDefault(require("@wordpress/warning"));
var _toolbarContext = _interopRequireDefault(require("../toolbar-context"));
var _jsxRuntime = require("react/jsx-runtime");
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
/**
 * External dependencies
 */

/**
 * WordPress dependencies
 */

/**
 * Internal dependencies
 */

function ToolbarItem({
  children,
  as: Component,
  ...props
}, ref) {
  const accessibleToolbarStore = (0, _element.useContext)(_toolbarContext.default);
  const isRenderProp = typeof children === 'function';
  if (!isRenderProp && !Component) {
    globalThis.SCRIPT_DEBUG === true ? (0, _warning.default)('`ToolbarItem` is a generic headless component. You must pass either a `children` prop as a function or an `as` prop as a component. ' + 'See https://developer.wordpress.org/block-editor/components/toolbar-item/') : void 0;
    return null;
  }
  const allProps = {
    ...props,
    ref,
    'data-toolbar-item': true
  };
  if (!accessibleToolbarStore) {
    if (Component) {
      return /*#__PURE__*/(0, _jsxRuntime.jsx)(Component, {
        ...allProps,
        children: children
      });
    }
    if (!isRenderProp) {
      return null;
    }
    return children(allProps);
  }
  const render = isRenderProp ? children : Component && /*#__PURE__*/(0, _jsxRuntime.jsx)(Component, {
    children: children
  });
  return /*#__PURE__*/(0, _jsxRuntime.jsx)(Ariakit.ToolbarItem, {
    accessibleWhenDisabled: true,
    ...allProps,
    store: accessibleToolbarStore,
    render: render
  });
}
var _default = exports.default = (0, _element.forwardRef)(ToolbarItem);
//# sourceMappingURL=index.js.map