"use strict";
var __create = Object.create;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getProtoOf = Object.getPrototypeOf;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
  for (var name in all)
    __defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
  if (from && typeof from === "object" || typeof from === "function") {
    for (let key of __getOwnPropNames(from))
      if (!__hasOwnProp.call(to, key) && key !== except)
        __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
  }
  return to;
};
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
  // If the importer is in node compatibility mode or this is not an ESM
  // file that has been converted to a CommonJS file using a Babel-
  // compatible transform (i.e. "__esModule" has not been set), then set
  // "default" to the CommonJS "module.exports" for node compatibility.
  isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
  mod
));
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);

// packages/components/src/slot-fill/bubbles-virtually/slot-fill-provider.tsx
var slot_fill_provider_exports = {};
__export(slot_fill_provider_exports, {
  default: () => SlotFillProvider
});
module.exports = __toCommonJS(slot_fill_provider_exports);
var import_element = require("@wordpress/element");
var import_is_shallow_equal = require("@wordpress/is-shallow-equal");
var import_compose = require("@wordpress/compose");
var import_slot_fill_context = __toESM(require("./slot-fill-context.cjs"), 1);
var import_jsx_runtime = require("react/jsx-runtime");
function createSlotRegistry() {
  const slots = (0, import_compose.observableMap)();
  const fills = (0, import_compose.observableMap)();
  const registerSlot = (name, ref, fillProps) => {
    slots.set(name, {
      ref,
      fillProps
    });
  };
  const unregisterSlot = (name, ref) => {
    const slot = slots.get(name);
    if (!slot) {
      return;
    }
    if (slot.ref !== ref) {
      return;
    }
    slots.delete(name);
  };
  const updateSlot = (name, ref, fillProps) => {
    const slot = slots.get(name);
    if (!slot) {
      return;
    }
    if (slot.ref !== ref) {
      return;
    }
    if ((0, import_is_shallow_equal.isShallowEqual)(slot.fillProps, fillProps)) {
      return;
    }
    slots.set(name, {
      ref,
      fillProps
    });
  };
  const registerFill = (name, ref) => {
    fills.set(name, [...fills.get(name) || [], ref]);
  };
  const unregisterFill = (name, ref) => {
    const fillsForName = fills.get(name);
    if (!fillsForName) {
      return;
    }
    fills.set(name, fillsForName.filter((fillRef) => fillRef !== ref));
  };
  return {
    slots,
    fills,
    registerSlot,
    updateSlot,
    unregisterSlot,
    registerFill,
    unregisterFill
  };
}
function SlotFillProvider({
  children
}) {
  const [registry] = (0, import_element.useState)(createSlotRegistry);
  return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_slot_fill_context.default.Provider, {
    value: registry,
    children
  });
}
//# sourceMappingURL=slot-fill-provider.cjs.map
