/**
 * @license
 * Copyright 2022-2025 Matter.js Authors
 * SPDX-License-Identifier: Apache-2.0
 */
import { ClientBehaviorBacking } from "#behavior/internal/ClientBehaviorBacking.js";
import { ServerBehaviorBacking } from "#behavior/internal/ServerBehaviorBacking.js";
import { EndpointInitializer } from "#endpoint/properties/EndpointInitializer.js";
import { PeerBehavior } from "#node/client/PeerBehavior.js";
import { ClientNodeStore } from "#storage/client/ClientNodeStore.js";
import { ClientStructure } from "./ClientStructure.js";
class ClientEndpointInitializer extends EndpointInitializer {
  #node;
  #store;
  #structure;
  constructor(node) {
    super();
    this.#node = node;
    this.#store = node.env.get(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 ServerBehaviorBacking(endpoint, type, store2, endpoint.behaviors.optionsFor(type));
    }
    const peerType = PeerBehavior({ kind: "known", behavior: type });
    const store = this.structure.storeForRemote(endpoint, peerType);
    return new ClientBehaviorBacking(endpoint, peerType, store, endpoint.behaviors.optionsFor(peerType));
  }
  get structure() {
    if (this.#structure === void 0) {
      this.#structure = new ClientStructure(this.#node);
    }
    return this.#structure;
  }
}
export {
  ClientEndpointInitializer
};
//# sourceMappingURL=ClientEndpointInitializer.js.map
