"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.default = InspectorControlsSlot;
var _components = require("@wordpress/components");
var _element = require("@wordpress/element");
var _warning = _interopRequireDefault(require("@wordpress/warning"));
var _deprecated = _interopRequireDefault(require("@wordpress/deprecated"));
var _blockSupportToolsPanel = _interopRequireDefault(require("./block-support-tools-panel"));
var _blockSupportSlotContainer = _interopRequireDefault(require("./block-support-slot-container"));
var _groups = _interopRequireDefault(require("./groups"));
var _jsxRuntime = require("react/jsx-runtime");
/**
 * WordPress dependencies
 */

/**
 * Internal dependencies
 */

function InspectorControlsSlot({
  __experimentalGroup,
  group = 'default',
  label,
  fillProps,
  ...props
}) {
  if (__experimentalGroup) {
    (0, _deprecated.default)('`__experimentalGroup` property in `InspectorControlsSlot`', {
      since: '6.2',
      version: '6.4',
      alternative: '`group`'
    });
    group = __experimentalGroup;
  }
  const slotFill = _groups.default[group];
  const fills = (0, _components.__experimentalUseSlotFills)(slotFill?.name);
  const motionContextValue = (0, _element.useContext)(_components.__unstableMotionContext);
  const computedFillProps = (0, _element.useMemo)(() => {
    var _fillProps$forwardedC;
    return {
      ...fillProps,
      forwardedContext: [...((_fillProps$forwardedC = fillProps?.forwardedContext) !== null && _fillProps$forwardedC !== void 0 ? _fillProps$forwardedC : []), [_components.__unstableMotionContext.Provider, {
        value: motionContextValue
      }]]
    };
  }, [motionContextValue, fillProps]);
  if (!slotFill) {
    globalThis.SCRIPT_DEBUG === true ? (0, _warning.default)(`Unknown InspectorControls group "${group}" provided.`) : void 0;
    return null;
  }
  if (!fills?.length) {
    return null;
  }
  const {
    Slot
  } = slotFill;
  if (label) {
    return /*#__PURE__*/(0, _jsxRuntime.jsx)(_blockSupportToolsPanel.default, {
      group: group,
      label: label,
      children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_blockSupportSlotContainer.default, {
        ...props,
        fillProps: computedFillProps,
        Slot: Slot
      })
    });
  }
  return /*#__PURE__*/(0, _jsxRuntime.jsx)(Slot, {
    ...props,
    fillProps: computedFillProps,
    bubblesVirtually: true
  });
}
//# sourceMappingURL=slot.js.map