"use strict";
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
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 __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var element_imperative_handles_exports = {};
__export(element_imperative_handles_exports, {
  getElementImperativeHandles: () => getElementImperativeHandles,
  reducer: () => reducer
});
module.exports = __toCommonJS(element_imperative_handles_exports);
var import_actions = require("../actions");
function getElementImperativeHandles(state) {
  return state;
}
function getInitialState() {
  return /* @__PURE__ */ new Map();
}
function reducer(state = getInitialState(), action) {
  if (!(0, import_actions.isKnownAction)(action))
    return state;
  switch (action.type) {
    case import_actions.ActionTypes.REGISTER_COMPONENT_HANDLE:
      return new Map(state).set(
        action.payload.documentKey,
        new Map(new Map(state.get(action.payload.documentKey) ?? [])).set(
          action.payload.elementKey,
          action.payload.componentHandle
        )
      );
    case import_actions.ActionTypes.UNREGISTER_COMPONENT_HANDLE: {
      const byElementKey = new Map(state.get(action.payload.documentKey) ?? []);
      const deleted = byElementKey.delete(action.payload.elementKey);
      if (!deleted)
        return state;
      return new Map(state).set(action.payload.documentKey, byElementKey);
    }
    default:
      return state;
  }
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
  getElementImperativeHandles,
  reducer
});
//# sourceMappingURL=element-imperative-handles.js.map