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 asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }

  function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }

  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;
        }

        init() {
          var _this = this;

          return _asyncToGenerator(function* () {
            var res = yield (_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) {
          var count = this.busyMap.get(type);
          if (count) this.busyMap.set(type, count + 1);else this.busyMap.set(type, 1);
          this.checkBusy();
        }

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

        checkBusy() {
          var _this2 = this;

          return _asyncToGenerator(function* () {
            if (_this2.loadingUI == null || !isValid(_this2.loadingUI)) {
              yield _this2.init();
            }

            var count = _this2.getBusyCount();

            if (count > 0) {
              var self = _this2;

              var onTimerEnd = () => {
                var curCnt = _this2.getBusyCount();

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

                _this2.timerID = null;
              };

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

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

        updateTips() {}

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

      });

      BusyLoadingManager.instance = null;

      _cclegacy._RF.pop();

      _crd = false;
    }
  };
});
//# sourceMappingURL=5dc16f6d76b28de6bfc1d03f97db16df2acfad51.js.map