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

  var _reporterNs, _cclegacy, __checkObsolete__, __checkObsoleteInNamespace__, js, Button, warn, EventHandler, isValid, find, Sprite, Label, ProgressBar, EditBox, Slider, GameEvent, ComponentEx, initAutoBindings, BaseUI, _crd;

  function _reportPossibleCrUseOfGameEvent(extras) {
    _reporterNs.report("GameEvent", "../event/GameEvent", _context.meta, extras);
  }

  function _reportPossibleCrUseOfComponentEx(extras) {
    _reporterNs.report("ComponentEx", "./ComponentEx", _context.meta, extras);
  }

  function _reportPossibleCrUseOfinitAutoBindings(extras) {
    _reporterNs.report("initAutoBindings", "db://assets/manager/autoBind", _context.meta, extras);
  }

  _export("BaseUI", void 0);

  return {
    setters: [function (_unresolved_) {
      _reporterNs = _unresolved_;
    }, function (_cc) {
      _cclegacy = _cc.cclegacy;
      __checkObsolete__ = _cc.__checkObsolete__;
      __checkObsoleteInNamespace__ = _cc.__checkObsoleteInNamespace__;
      js = _cc.js;
      Button = _cc.Button;
      warn = _cc.warn;
      EventHandler = _cc.EventHandler;
      isValid = _cc.isValid;
      find = _cc.find;
      Sprite = _cc.Sprite;
      Label = _cc.Label;
      ProgressBar = _cc.ProgressBar;
      EditBox = _cc.EditBox;
      Slider = _cc.Slider;
    }, function (_unresolved_2) {
      GameEvent = _unresolved_2.default;
    }, function (_unresolved_3) {
      ComponentEx = _unresolved_3.ComponentEx;
    }, function (_unresolved_4) {
      initAutoBindings = _unresolved_4.initAutoBindings;
    }],
    execute: function () {
      _crd = true;

      _cclegacy._RF.push({}, "b891aP/QgZEfKkbmoh6LplP", "BaseUI", undefined);

      __checkObsolete__(['_decorator', 'Component', 'Node', 'js', 'Button', 'warn', 'EventHandler', 'isValid', 'find', 'Skeleton', 'SpriteFrame', 'Sprite', 'Label', 'ProgressBar', 'EditBox', 'Slider']);

      _export("BaseUI", BaseUI = class BaseUI extends (_crd && ComponentEx === void 0 ? (_reportPossibleCrUseOfComponentEx({
        error: Error()
      }), ComponentEx) : ComponentEx) {
        constructor(...args) {
          super(...args);
          this.events = [];
        }

        onBtnClicked(event, customEventData) {
          var btnName = event.target.name;

          switch (btnName) {
            case "btn_close":
              this.close();
              break;
          }
        }

        close() {}

        onLoad() {
          this.events = [];

          this._addClickEvent(this.node);

          (_crd && initAutoBindings === void 0 ? (_reportPossibleCrUseOfinitAutoBindings({
            error: Error()
          }), initAutoBindings) : initAutoBindings)(this);
        }

        onDestroy() {
          for (var i = 0; i < this.events.length; ++i) (_crd && GameEvent === void 0 ? (_reportPossibleCrUseOfGameEvent({
            error: Error()
          }), GameEvent) : GameEvent).Instance().unregister(this, this.events[i]);
        }

        register(type, callFunc) {
          this.events.push(type);
          (_crd && GameEvent === void 0 ? (_reportPossibleCrUseOfGameEvent({
            error: Error()
          }), GameEvent) : GameEvent).Instance().register(this, type, callFunc);
        }

        unregister(type) {
          (_crd && GameEvent === void 0 ? (_reportPossibleCrUseOfGameEvent({
            error: Error()
          }), GameEvent) : GameEvent).Instance().unregister(this, type);
        }

        dispatch(type, ...data) {
          (_crd && GameEvent === void 0 ? (_reportPossibleCrUseOfGameEvent({
            error: Error()
          }), GameEvent) : GameEvent).Instance().dispatch(type, ...data);
        }

        shutAnim() {
          if (this.node) {
            this.node.active = false;
            this.node.parent = null;
            this.node.destroy();
          }
        }

        _isSkipNode(node) {
          if (this.node == node) {
            return false;
          }

          let b = node.getComponent(BaseUI);
          if (b) console.log("跳过", b.name);
          return b != null;
        }

        _addClickEvent(node) {
          if (this._isSkipNode(node)) return;

          for (var i = 0; i < node.children.length; ++i) {
            var tmp = node.children[i];
            if (this._isSkipNode(tmp)) continue;

            if (tmp.getComponent(Button)) {
              BaseUI.addClickEvent(tmp, this.node, js.getClassName(this), "onBtnClicked", tmp);
            }

            this._addClickEvent(tmp);
          }
        }

        static addClickEvent(node, target, component, handler, customEventData) {
          var eventHandler = new EventHandler();
          eventHandler.target = target;
          eventHandler.component = component;
          eventHandler.handler = handler;
          if (customEventData) eventHandler.customEventData = customEventData;
          var clickEvents = node.getComponent(Button).clickEvents;

          if (clickEvents.length > 0) {
            warn("按钮已经存在绑定，跳过自动绑定", node.name);
            return;
          }

          clickEvents.push(eventHandler);
        } // public SetSpriteUrl(name: string, url: string) {
        //     if (!window['wx'] && !window['tt'] && !window['qq']) return;
        //     if (url && url != "") {
        //         var tmp = this.GetGameObject(name);
        //         if (tmp) {
        //             loader.load({ url, type: 'jpg' }, (err, tex) => {
        //                 if (!err) {
        //                     if (!isValid(tmp)) return;
        //                     tmp.getComponent(Sprite).spriteFrame = new SpriteFrame(tex);
        //                 }
        //             });
        //         }
        //     }
        //     else {
        //         if (this.GetSprite(name))
        //             this.GetSprite(name).spriteFrame = null;
        //     }
        // }


        GetGameObject(name, refind = false) {
          if (!isValid(this.node)) return null;

          if (!refind) {
            if (this.m_objects && this.m_objects.has(name)) return this.m_objects[name];
            if (name == this.node.name) return this.node;
          }

          if (name.indexOf("/") != -1) {
            var tmp = find(name, this.node);
            if (tmp) this.m_objects[name] = tmp;
            return tmp;
          } else {
            var tmp = this._findInChildren(this.node, name);

            if (tmp) this.m_objects[name] = tmp;
            return tmp;
          }
        } // public GetSkeleton(name: string): Skeleton {
        //     if (this.m_objects && this.m_objects.has(name)) return this.m_objects[name].getComponent(Skeleton);
        //     var tmp = this.GetGameObject(name);
        //     if (tmp) return tmp.getComponent(Skeleton);
        //     return null;
        // }


        GetSprite(name) {
          if (this.m_objects && this.m_objects.has(name)) return this.m_objects[name].getComponent(Sprite);
          var tmp = this.GetGameObject(name);
          if (tmp) return tmp.getComponent(Sprite);
          return null;
        }

        GetText(name) {
          if (this.m_objects && this.m_objects.has(name)) return this.m_objects[name].getComponent(Label);
          var tmp = this.GetGameObject(name);
          if (tmp) return tmp.getComponent(Label);
          return null;
        }

        GetProgressBar(name) {
          if (this.m_objects && this.m_objects.has(name)) return this.m_objects[name].getComponent(ProgressBar);
          var tmp = this.GetGameObject(name);
          if (tmp) return tmp.getComponent(ProgressBar);
          return null;
        }

        GetButton(name) {
          if (this.m_objects && this.m_objects.has(name)) return this.m_objects[name].getComponent(Button);
          var tmp = this.GetGameObject(name);
          if (tmp) return tmp.getComponent(Button);
          return null;
        }

        GetInputField(name) {
          if (this.m_objects && this.m_objects.has(name)) return this.m_objects[name].getComponent(EditBox);
          var tmp = this.GetGameObject(name);
          if (tmp) return tmp.getComponent(EditBox);
          return null;
        }

        GetSlider(name) {
          if (this.m_objects && this.m_objects.has(name)) return this.m_objects[name].getComponent(Slider);
          var tmp = this.GetGameObject(name);
          if (tmp) return tmp.getComponent(Slider);
          return null;
        }

        SetText(TextID, content) {
          if (this.GetText(TextID)) this.GetText(TextID).string = content;
        }

        SetInputText(TextID, content) {
          if (this.GetInputField(TextID)) this.GetInputField(TextID).string = content;
        }

        SetProgressBar(TextID, p) {
          if (this.GetProgressBar(TextID)) this.GetProgressBar(TextID).progress = p;
        }

      });

      _cclegacy._RF.pop();

      _crd = false;
    }
  };
});
//# sourceMappingURL=616119eb23703163aee20de24b334afb08e82056.js.map