System.register(["cc"], function (_export, _context) {
  "use strict";

  var _cclegacy, __checkObsolete__, __checkObsoleteInNamespace__, _crd, autoBindMap;

  function auto(componentTypeOrTarget, propertyKey) {
    if (typeof componentTypeOrTarget === 'function') {
      return function (target, propertyKey) {
        if (!autoBindMap.has(target)) {
          autoBindMap.set(target, {});
        }

        autoBindMap.get(target)[propertyKey] = {
          type: componentTypeOrTarget
        };
      };
    } else {
      var _target = componentTypeOrTarget;

      if (!autoBindMap.has(_target)) {
        autoBindMap.set(_target, {});
      }

      autoBindMap.get(_target)[propertyKey] = {};
    }
  }

  function buildNodeNameMap(node, nameMap) {
    nameMap.set(node.name, node);

    for (var child of node.children) {
      buildNodeNameMap(child, nameMap);
    }
  }
  /**
   * 在onLoad中调用这个函数然后才会自动绑定。initAutoBindings(this)。 
   */


  function initAutoBindings(instance) {
    var bindings = autoBindMap.get(Object.getPrototypeOf(instance));

    if (bindings) {
      var nameMap = new Map();
      buildNodeNameMap(instance.node, nameMap);

      for (var _propertyKey in bindings) {
        var binding = bindings[_propertyKey];
        var node = nameMap.get(_propertyKey);

        if (node) {
          if (binding.type) {
            instance[_propertyKey] = node.getComponent(binding.type);
          } else {
            instance[_propertyKey] = node;
          }
        } else {
          console.warn("Node not found for propertyKey: " + _propertyKey);
        }
      }
    }
  }

  _export({
    auto: auto,
    initAutoBindings: initAutoBindings
  });

  return {
    setters: [function (_cc) {
      _cclegacy = _cc.cclegacy;
      __checkObsolete__ = _cc.__checkObsolete__;
      __checkObsoleteInNamespace__ = _cc.__checkObsoleteInNamespace__;
    }],
    execute: function () {
      _crd = true;

      _cclegacy._RF.push({}, "7b234l7Q6FNZoFXVY9hXkeS", "autoBind", undefined);

      __checkObsolete__(['Component']);

      autoBindMap = new WeakMap();
      /**
       * 自动绑定与变量同名的子节点。
       * 装饰器不传参数（组件）则绑定节点，传了组件则绑定节点上的组件。
       * 如果传了组件，则传入的组件一定要和变量类型一致，否则绑定会失败。
       * 记得在组件的onLoad函数调用initAutoBindings(this)
       */

      _cclegacy._RF.pop();

      _crd = false;
    }
  };
});
//# sourceMappingURL=7333064adb9f53bd7e94872d8600ff3741939f14.js.map