/**
 * @license
 * Copyright 2022-2026 Matter.js Authors
 * SPDX-License-Identifier: Apache-2.0
 */
import { camelize } from "@matter/general";
import {
  AttributeModel,
  ClusterModel,
  CommandModel,
  DataModelPath,
  EventModel,
  Matter
} from "@matter/model";
function ExpandedPath({ path, matter, base, kind }) {
  if (matter === void 0) {
    matter = Matter;
  }
  if (base && "path" in base) {
    base = base.path;
  }
  const endpointIdent = path.endpointId ?? "*";
  base = base ? base.at(endpointIdent, "endpoint") : new DataModelPath(endpointIdent, "endpoint");
  let cluster;
  base = base.at(identityOf(matter, ClusterModel, path.clusterId), "cluster");
  if ("attributeId" in path) {
    base = base.at("state").at(identityOf(cluster, AttributeModel, path.attributeId));
    if (path.listIndex) {
      return base.at(path.listIndex, "entry");
    }
    return base;
  }
  if ("commandId" in path) {
    return base.at(identityOf(cluster, CommandModel, path.commandId));
  }
  if ("eventId" in path) {
    return base.at("events").at(identityOf(cluster, 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 camelize(id);
      }
      return id;
    }
    if (type === ClusterModel) {
      cluster = instance;
    }
    return instance.propertyName;
  }
}
export {
  ExpandedPath
};
//# sourceMappingURL=ExpandedPath.js.map
