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 {
      const target = componentTypeOrTarget;

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

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

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

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


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

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

      for (const propertyKey in bindings) {
        const binding = bindings[propertyKey];
        const 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=00b0b480fd84e952b8a167004fdf4d7e3aef870a.js.map