"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_EndpointInitializer = require("#endpoint/properties/EndpointInitializer.js");
var import_ServerNodeStore = require("#node/storage/ServerNodeStore.js");
/**
 * @license
 * Copyright 2022-2024 Matter.js Authors
 * SPDX-License-Identifier: Apache-2.0
 */
class ClientEndpointInitializer extends import_EndpointInitializer.EndpointInitializer {
  #node;
  #store;
  constructor(node) {
    super();
    this.#node = node;
    this.#store = node.env.get(import_ServerNodeStore.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 import_ClientBehaviorBacking.ClientBehaviorBacking(endpoint, behavior, store, endpoint.behaviors.optionsFor(behavior));
  }
}
//# sourceMappingURL=ClientEndpointInitializer.js.map
