/**
 * @license
 * Copyright 2022-2024 Matter.js Authors
 * SPDX-License-Identifier: Apache-2.0
 */
import { ClientBehaviorBacking } from "#behavior/internal/ClientBehaviorBacking.js";
import { EndpointInitializer } from "#endpoint/properties/EndpointInitializer.js";
import { ServerNodeStore } from "#node/storage/ServerNodeStore.js";
class ClientEndpointInitializer extends EndpointInitializer {
  #node;
  #store;
  constructor(node) {
    super();
    this.#node = node;
    this.#store = node.env.get(ServerNodeStore).clientStores.storeForNode(node);
  }
  async eraseDescendant(endpoint) {
    if (endpoint === this.#node) {
      await this.#store.erase();
      return;
    }
    if (!endpoint.lifecycle.hasId) {
      return;
    }
    const store = this.#store.endpointStores.storeForEndpoint(endpoint);
    await store.erase();
  }
  get ready() {
    return this.#store.construction.ready;
  }
  static async create(node) {
    const instance = new ClientEndpointInitializer(node);
    await instance.ready;
    return instance;
  }
  createBacking(endpoint, behavior) {
    const store = this.#store.endpointStores.storeForEndpoint(endpoint);
    return new ClientBehaviorBacking(endpoint, behavior, store, endpoint.behaviors.optionsFor(behavior));
  }
}
export {
  ClientEndpointInitializer
};
//# sourceMappingURL=ClientEndpointInitializer.js.map
