"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 ExpandedPath_exports = {};
__export(ExpandedPath_exports, {
  ExpandedPath: () => ExpandedPath
});
module.exports = __toCommonJS(ExpandedPath_exports);
var import_general = require("#general");
var import_model = require("#model");
/**
 * @license
 * Copyright 2022-2026 Matter.js Authors
 * SPDX-License-Identifier: Apache-2.0
 */
function ExpandedPath({ path, matter, base, kind }) {
  if (matter === void 0) {
    matter = import_model.Matter;
  }
  if (base && "path" in base) {
    base = base.path;
  }
  const endpointIdent = path.endpointId ?? "*";
  base = base ? base.at(endpointIdent, "endpoint") : (0, import_model.DataModelPath)(endpointIdent, "endpoint");
  let cluster;
  base = base.at(identityOf(matter, import_model.ClusterModel, path.clusterId), "cluster");
  if ("attributeId" in path) {
    base = base.at("state").at(identityOf(cluster, import_model.AttributeModel, path.attributeId));
    if (path.listIndex) {
      return base.at(path.listIndex, "entry");
    }
    return base;
  }
  if ("commandId" in path) {
    return base.at(identityOf(cluster, import_model.CommandModel, path.commandId));
  }
  if ("eventId" in path) {
    return base.at("events").at(identityOf(cluster, import_model.EventModel, path.eventId));
  }
  return base.at("*", kind ?? "element");
  function identityOf(parent, type, id) {
    if (id === void 0) {
      return "*";
    }
    const instance = parent?.get(type, id);
    if (instance === void 0) {
      if (typeof id === "string") {
        return (0, import_general.camelize)(id);
      }
      return id;
    }
    if (type === import_model.ClusterModel) {
      cluster = instance;
    }
    return (0, import_general.camelize)(instance.name);
  }
}
//# sourceMappingURL=ExpandedPath.js.map
