"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/provider.tsx
var provider_exports = {};
__export(provider_exports, {
  SlotFillProvider: () => SlotFillProvider,
  default: () => provider_default
});
module.exports = __toCommonJS(provider_exports);
var import_element = require("@wordpress/element");
var import_context = __toESM(require("./context.cjs"), 1);
var import_compose = require("@wordpress/compose");
var import_jsx_runtime = require("react/jsx-runtime");
function createSlotRegistry() {
  const slots = (0, import_compose.observableMap)();
  const fills = (0, import_compose.observableMap)();
  function registerSlot(name, instance) {
    slots.set(name, instance);
  }
  function unregisterSlot(name, instance) {
    if (slots.get(name) !== instance) {
      return;
    }
    slots.delete(name);
  }
  function registerFill(name, instance, children) {
    fills.set(name, [...fills.get(name) || [], {
      instance,
      children
    }]);
  }
  function unregisterFill(name, instance) {
    const fillsForName = fills.get(name);
    if (!fillsForName) {
      return;
    }
    fills.set(name, fillsForName.filter((fill) => fill.instance !== instance));
  }
  function updateFill(name, instance, children) {
    const fillsForName = fills.get(name);
    if (!fillsForName) {
      return;
    }
    const fillForInstance = fillsForName.find((f) => f.instance === instance);
    if (!fillForInstance) {
      return;
    }
    if (fillForInstance.children === children) {
      return;
    }
    fills.set(name, fillsForName.map((f) => {
      if (f.instance === instance) {
        return {
          instance,
          children
        };
      }
      return f;
    }));
  }
  return {
    slots,
    fills,
    registerSlot,
    unregisterSlot,
    registerFill,
    unregisterFill,
    updateFill
  };
}
function SlotFillProvider({
  children
}) {
  const [contextValue] = (0, import_element.useState)(createSlotRegistry);
  return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_context.default.Provider, {
    value: contextValue,
    children
  });
}
var provider_default = SlotFillProvider;
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
  SlotFillProvider
});
//# sourceMappingURL=provider.cjs.map
