"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 NameResolver_exports = {};
__export(NameResolver_exports, {
  NameResolver: () => NameResolver
});
module.exports = __toCommonJS(NameResolver_exports);
var import_general = require("@matter/general");
var import_model = require("@matter/model");
var import_Internal = require("./Internal.js");
/**
 * @license
 * Copyright 2022-2026 Matter.js Authors
 * SPDX-License-Identifier: Apache-2.0
 */
function NameResolver(supervisor, model, name) {
  if (model === void 0) {
    return;
  }
  if (model === supervisor.schema || model.id !== void 0 && supervisor.schema.tag === model.tag && supervisor.schema.id === model.id) {
    if (!supervisor.memberNames.has(name)) {
      return;
    }
    return createDirectResolver();
  }
  if (!(model instanceof import_model.ValueModel) || model.effectiveMetatype !== "object") {
    return createIndirectResolver();
  }
  if (supervisor.membersOf(model).find((model2) => (0, import_general.camelize)(model2.name, false) === name)) {
    return createDirectResolver();
  }
  return createIndirectResolver();
  function createDirectResolver() {
    return (val) => val?.[name];
  }
  function createIndirectResolver() {
    const parentSchema = model.parent;
    if (!(parentSchema instanceof import_model.ValueModel) && !(parentSchema instanceof import_model.ClusterModel)) {
      return;
    }
    const parentReader = NameResolver(supervisor, parentSchema, name);
    if (!parentReader) {
      return;
    }
    return (val) => {
      const parent = val?.[import_Internal.Internal.reference]?.parent?.owner;
      if (parent) {
        return parentReader(parent);
      }
    };
  }
}
//# sourceMappingURL=NameResolver.js.map
