// packages/block-editor/src/components/block-controls/slot.js
import { useContext, useMemo } from "@wordpress/element";
import {
  privateApis,
  __experimentalToolbarContext as ToolbarContext,
  ToolbarGroup,
  __experimentalUseSlotFills as useSlotFills
} from "@wordpress/components";
import warning from "@wordpress/warning";
import groups from "./groups";
import { unlock } from "../../lock-unlock";
import { jsx } from "react/jsx-runtime";
var { ComponentsContext } = unlock(privateApis);
function BlockControlsSlot({ group = "default", ...props }) {
  const toolbarState = useContext(ToolbarContext);
  const contextState = useContext(ComponentsContext);
  const fillProps = useMemo(
    () => ({
      forwardedContext: [
        [ToolbarContext.Provider, { value: toolbarState }],
        [ComponentsContext.Provider, { value: contextState }]
      ]
    }),
    [toolbarState, contextState]
  );
  const slotFill = groups[group];
  const fills = useSlotFills(slotFill.name);
  if (!slotFill) {
    warning(`Unknown BlockControls group "${group}" provided.`);
    return null;
  }
  if (!fills?.length) {
    return null;
  }
  const { Slot } = slotFill;
  const slot = /* @__PURE__ */ jsx(Slot, { ...props, bubblesVirtually: true, fillProps });
  if (group === "default") {
    return slot;
  }
  return /* @__PURE__ */ jsx(ToolbarGroup, { children: slot });
}
export {
  BlockControlsSlot as default
};
//# sourceMappingURL=slot.js.map
