"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 ClientEndpointInitializer_exports = {};
__export(ClientEndpointInitializer_exports, {
  ClientEndpointInitializer: () => ClientEndpointInitializer
});
module.exports = __toCommonJS(ClientEndpointInitializer_exports);
var import_ClientBehaviorBacking = require("#behavior/internal/ClientBehaviorBacking.js");
var import_ServerBehaviorBacking = require("#behavior/internal/ServerBehaviorBacking.js");
var import_EndpointInitializer = require("#endpoint/properties/EndpointInitializer.js");
var import_PeerBehavior = require("#node/client/PeerBehavior.js");
var import_ClientNodeStore = require("#storage/client/ClientNodeStore.js");
var import_ClientStructure = require("./ClientStructure.js");
/**
 * @license
 * Copyright 2022-2026 Matter.js Authors
 * SPDX-License-Identifier: Apache-2.0
 */
class ClientEndpointInitializer extends import_EndpointInitializer.EndpointInitializer {
  #node;
  #store;
  #structure;
  constructor(node) {
    super();
    this.#node = node;
    this.#store = node.env.get(import_ClientNodeStore.ClientNodeStore);
  }
  async eraseDescendant(endpoint) {
    if (endpoint === this.#node) {
      await this.#store.erase();
      return;
    }
    if (!endpoint.lifecycle.hasId) {
      return;
    }
    const store = this.#store.storeForEndpoint(endpoint);
    await store.erase();
  }
  async deactivateDescendant(_endpoint) {
  }
  createBacking(endpoint, type) {
    if (type.cluster === void 0) {
      const store2 = this.structure.storeForLocal(endpoint, type);
      return new import_ServerBehaviorBacking.ServerBehaviorBacking(endpoint, type, store2, endpoint.behaviors.optionsFor(type));
    }
    const peerType = (0, import_PeerBehavior.PeerBehavior)({ kind: "known", behavior: type });
    const store = this.structure.storeForRemote(endpoint, peerType);
    return new import_ClientBehaviorBacking.ClientBehaviorBacking(endpoint, peerType, store, endpoint.behaviors.optionsFor(peerType));
  }
  get structure() {
    if (this.#structure === void 0) {
      this.#structure = new import_ClientStructure.ClientStructure(this.#node);
    }
    return this.#structure;
  }
}
//# sourceMappingURL=ClientEndpointInitializer.js.map
