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

  var _reporterNs, _cclegacy, __checkObsolete__, __checkObsoleteInNamespace__, isValid, Prefab, warn, instantiate, Utils, WindowManager, BusyLoadingManager, _crd, BUSY_TYPE;

  function _reportPossibleCrUseOfUtils(extras) {
    _reporterNs.report("Utils", "../utils/Utils", _context.meta, extras);
  }

  function _reportPossibleCrUseOfWindowManager(extras) {
    _reporterNs.report("WindowManager", "./WindowManager", _context.meta, extras);
  }

  _export({
    default: void 0,
    BUSY_TYPE: void 0
  });

  return {
    setters: [function (_unresolved_) {
      _reporterNs = _unresolved_;
    }, function (_cc) {
      _cclegacy = _cc.cclegacy;
      __checkObsolete__ = _cc.__checkObsolete__;
      __checkObsoleteInNamespace__ = _cc.__checkObsoleteInNamespace__;
      isValid = _cc.isValid;
      Prefab = _cc.Prefab;
      warn = _cc.warn;
      instantiate = _cc.instantiate;
    }, function (_unresolved_2) {
      Utils = _unresolved_2.default;
    }, function (_unresolved_3) {
      WindowManager = _unresolved_3.default;
    }],
    execute: function () {
      _crd = true;

      _cclegacy._RF.push({}, "e9a7f+4IppDWb7xHmmkKSYE", "BusyLoadingManager", undefined);

      __checkObsolete__(['isValid', 'Prefab', 'warn', 'Node', 'instantiate']);

      (function (BUSY_TYPE) {
        BUSY_TYPE[BUSY_TYPE["NET"] = 0] = "NET";
        BUSY_TYPE[BUSY_TYPE["RES"] = 1] = "RES";
      })(BUSY_TYPE || _export("BUSY_TYPE", BUSY_TYPE = {}));

      _export("default", BusyLoadingManager = class BusyLoadingManager {
        //延迟显示
        constructor() {
          this.busyMap = new Map();
          this.loadingUI = void 0;
          this.timerID = null;
          this.delay = 300;
        }

        static get ins() {
          if (BusyLoadingManager.instance == null) {
            BusyLoadingManager.instance = new BusyLoadingManager();
          }

          return BusyLoadingManager.instance;
        }

        async init() {
          let res = await (_crd && Utils === void 0 ? (_reportPossibleCrUseOfUtils({
            error: Error()
          }), Utils) : Utils).loadRes('common/BusyLoading', "prefabs", Prefab);
          this.loadingUI = instantiate(res);
          this.loadingUI.name = "BusyLoading"; // this.loadingUI.zIndex = 999
        }

        addBusy(type) {
          let count = this.busyMap.get(type);
          if (count) this.busyMap.set(type, count + 1);else this.busyMap.set(type, 1);
          this.checkBusy();
        }

        removeBusy(type) {
          let count = this.busyMap.get(type);
          if (count) this.busyMap.set(type, count - 1);else warn('remove busy error', type);
          this.checkBusy();
        }

        async checkBusy() {
          if (this.loadingUI == null || !isValid(this.loadingUI)) {
            await this.init();
          }

          var count = this.getBusyCount();

          if (count > 0) {
            let self = this;

            let onTimerEnd = () => {
              let curCnt = this.getBusyCount();

              if (curCnt > 0) {
                // self.loadingUI.opacity = 255;
                self.updateTips();
              } else {
                warn('timeout end waitcnt is 0');
              }

              this.timerID = null;
            };

            if (this.timerID) {
              clearTimeout(this.timerID);
              this.timerID = setTimeout(onTimerEnd, this.delay);
            } else {
              if (this.loadingUI.parent) {
                this.updateTips();
              } else {
                // this.loadingUI.opacity = 0;
                (_crd && WindowManager === void 0 ? (_reportPossibleCrUseOfWindowManager({
                  error: Error()
                }), WindowManager) : WindowManager).ins.container.addChild(this.loadingUI);
                this.timerID = setTimeout(onTimerEnd, this.delay);
              }
            }
          } else {
            if (this.timerID) {
              clearTimeout(this.timerID);
              this.timerID = 0;
            }

            if (this.loadingUI.parent) {
              this.loadingUI.removeFromParent();
            }
          }
        }

        updateTips() {}

        getBusyCount() {
          let c = 0;
          this.busyMap.forEach((v, k) => {
            c += v;
          });
          return c;
        }

      });

      BusyLoadingManager.instance = null;

      _cclegacy._RF.pop();

      _crd = false;
    }
  };
});
//# sourceMappingURL=98282ff97f79626559dd676b871a3ae807788e09.js.map