/**
 * @license
 * Copyright 2022-2026 Matter.js Authors
 * SPDX-License-Identifier: Apache-2.0
 */
import { camelize } from "#general";
import { ClusterModel, ValueModel } from "#model";
import { Internal } from "./Internal.js";
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 ValueModel) || model.effectiveMetatype !== "object") {
    return createIndirectResolver();
  }
  if (supervisor.membersOf(model).find((model2) => camelize(model2.name, false) === name)) {
    return createDirectResolver();
  }
  return createIndirectResolver();
  function createDirectResolver() {
    return (val) => val?.[name];
  }
  function createIndirectResolver() {
    const parentSchema = model.parent;
    if (!(parentSchema instanceof ValueModel) && !(parentSchema instanceof ClusterModel)) {
      return;
    }
    const parentReader = NameResolver(supervisor, parentSchema, name);
    if (!parentReader) {
      return;
    }
    return (val) => {
      const parent = val?.[Internal.reference]?.parent?.owner;
      if (parent) {
        return parentReader(parent);
      }
    };
  }
}
export {
  NameResolver
};
//# sourceMappingURL=NameResolver.js.map
