"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 ClusterHelper_exports = {};
__export(ClusterHelper_exports, {
  getClusterNameById: () => getClusterNameById,
  resolveAttributeName: () => resolveAttributeName,
  resolveCommandName: () => resolveCommandName,
  resolveEventName: () => resolveEventName
});
module.exports = __toCommonJS(ClusterHelper_exports);
var import_general = require("@matter/general");
var import_model = require("@matter/model");
/**
 * @license
 * Copyright 2022-2026 Matter.js Authors
 * SPDX-License-Identifier: Apache-2.0
 */
function toHex(value) {
  return value === void 0 ? "*" : `0x${value.toString(16)}`;
}
function getClusterNameById(clusterId) {
  return import_model.Matter.clusters(clusterId)?.name ?? `Unknown cluster ${import_general.Diagnostic.hex(clusterId)}`;
}
function resolveEndpointClusterName(nodeId, endpointId, clusterId) {
  let elementName = nodeId === void 0 ? "" : `${toHex(nodeId)}/`;
  if (endpointId === void 0) {
    elementName += "*";
  } else {
    elementName += `${toHex(endpointId)}`;
  }
  if (clusterId === void 0) {
    return `${elementName}/*`;
  }
  const name = import_model.Matter.clusters(clusterId)?.name;
  if (name === void 0) {
    return `${elementName}/unknown(${toHex(clusterId)})`;
  }
  return `${elementName}/${name}(${toHex(clusterId)})`;
}
function resolveElementName(cluster, tag, elementId) {
  if (cluster === void 0) {
    return void 0;
  }
  for (const child of cluster.children) {
    if (child.tag === tag && child.id === elementId) {
      return child.name;
    }
  }
  return void 0;
}
function resolveAttributeName({
  nodeId,
  endpointId,
  clusterId,
  attributeId
}) {
  const endpointClusterName = resolveEndpointClusterName(nodeId, endpointId, clusterId);
  if (endpointId === void 0 || clusterId === void 0 || attributeId === void 0) {
    return `${endpointClusterName}/${toHex(attributeId)}`;
  }
  const cluster = import_model.Matter.clusters(clusterId);
  const name = resolveElementName(cluster, import_model.AttributeModel.Tag, attributeId);
  if (name === void 0) {
    return `${endpointClusterName}/unknown(${toHex(attributeId)})`;
  }
  return `${endpointClusterName}/${name}(${toHex(attributeId)})`;
}
function resolveEventName({
  nodeId,
  endpointId,
  clusterId,
  eventId,
  isUrgent
}) {
  const isUrgentStr = isUrgent ? "!" : "";
  const endpointClusterName = resolveEndpointClusterName(nodeId, endpointId, clusterId);
  if (endpointId === void 0 || clusterId === void 0 || eventId === void 0) {
    return `${isUrgentStr}${endpointClusterName}/${toHex(eventId)}`;
  }
  const cluster = import_model.Matter.clusters(clusterId);
  const name = resolveElementName(cluster, import_model.EventModel.Tag, eventId);
  if (name === void 0) {
    return `${isUrgentStr}${endpointClusterName}/unknown(${toHex(eventId)})`;
  }
  return `${isUrgentStr}${endpointClusterName}/${name}(${toHex(eventId)})`;
}
function resolveCommandName({ endpointId, clusterId, commandId }) {
  const endpointClusterName = resolveEndpointClusterName(void 0, endpointId, clusterId);
  if (endpointId === void 0 || clusterId === void 0 || commandId === void 0) {
    return `${endpointClusterName}/${toHex(commandId)}`;
  }
  const cluster = import_model.Matter.clusters(clusterId);
  const name = resolveElementName(cluster, import_model.CommandModel.Tag, commandId);
  if (name === void 0) {
    return `${endpointClusterName}/unknown(${toHex(commandId)})`;
  }
  return `${endpointClusterName}/${name}(${toHex(commandId)})`;
}
//# sourceMappingURL=ClusterHelper.js.map
