/**
 * @license
 * Copyright 2022-2026 Matter.js Authors
 * SPDX-License-Identifier: Apache-2.0
 */
import { BehaviorBacking } from "./BehaviorBacking.js";
class ClientBehaviorBacking extends BehaviorBacking {
  #elements;
  get elements() {
    if (this.#elements) {
      return this.#elements;
    }
    const { attributeList, acceptedCommandList } = this.endpoint.stateOf(this.type);
    const schema = this.type.schema;
    const attributes = /* @__PURE__ */ new Set();
    const attributeIds = new Set(attributeList);
    for (const attr of schema.attributes) {
      if (attributeIds.has(attr.id)) {
        attributes.add(attr.propertyName);
      }
    }
    const commands = /* @__PURE__ */ new Set();
    const commandIds = new Set(acceptedCommandList);
    for (const cmd of schema.commands) {
      if (cmd.isRequest && commandIds.has(cmd.id)) {
        commands.add(cmd.propertyName);
      }
    }
    return this.#elements = {
      features: schema.supportedFeatures,
      attributes,
      commands,
      events: /* @__PURE__ */ new Set()
      // Not published
    };
  }
  get datasourceOptions() {
    const options = super.datasourceOptions;
    options.primaryKey = "id";
    return options;
  }
  refreshForChangedType() {
    this.#elements = void 0;
    super.refreshForChangedType();
  }
  /**
   * Map attribute ID keys back to property names before broadcasting.
   *
   * The Datasource reports changed keys using the backing's primaryKey format.  Since this backing uses
   * `primaryKey: "id"`, props are attribute ID strings (e.g. "0" for onOff).  Downstream consumers
   * ({@link ChangeNotificationService}, {@link ProtocolService}) expect property names.
   */
  broadcastChanges(props) {
    const idToName = this.type.supervisor.propertyIdsAndNames;
    super.broadcastChanges(props.map((id) => idToName.get(id) ?? id));
  }
  close() {
    this.store.reclaimValues?.();
    return super.close();
  }
}
export {
  ClientBehaviorBacking
};
//# sourceMappingURL=ClientBehaviorBacking.js.map
