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

  var _reporterNs, _cclegacy, __checkObsolete__, __checkObsoleteInNamespace__, Prefab, instantiate, GameConst, Utils, WindowManager, _crd;

  function _reportPossibleCrUseOfGameConst(extras) {
    _reporterNs.report("GameConst", "../common/GameConst", _context.meta, extras);
  }

  function _reportPossibleCrUseOfBasePanel(extras) {
    _reporterNs.report("BasePanel", "../component/BasePanel", _context.meta, extras);
  }

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

  _export("default", void 0);

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

      _cclegacy._RF.push({}, "6aa1d5C1T5F5L0hm2GSlczf", "WindowManager", undefined);

      __checkObsolete__(['Prefab', 'instantiate', 'Node', 'Vec3']);

      _export("default", WindowManager = class WindowManager {
        constructor() {
          this._windowContainer = void 0;
          this._windows = [];
          this._showlist = {};
          this._prefabMap = {};
        }

        static get ins() {
          if (!WindowManager.instance) {
            WindowManager.instance = new WindowManager();
          }

          return WindowManager.instance;
        }

        register(container) {
          this.clearAll();
          this._windowContainer = container;
        }

        open(name, showData, pos, parent) {
          if (showData === void 0) {
            showData = null;
          }

          if (pos === void 0) {
            pos = null;
          }

          if (parent === void 0) {
            parent = null;
          }

          if (this._showlist[name]) return;
          return new Promise((resolve, reject) => {
            if (this._showlist[name]) {
              // console.error(name)
              reject(null);
              return;
            }

            this._showlist[name] = true;
            var path = 'gameui/' + name; // BusyLoadingManager.ins.addBusy(BUSY_TYPE.RES)

            (_crd && Utils === void 0 ? (_reportPossibleCrUseOfUtils({
              error: Error()
            }), Utils) : Utils).loadRes(path, "prefabs", Prefab, (err, res) => {
              if (err) {
                console.log('加载错误', path);
                this._showlist[name] = false;
                reject(null);
                return;
              }

              if (this._showlist[name] == false) {
                reject(null);
                return;
              }

              console.log('open win ', name);
              var win = instantiate(res);
              win.name = name;
              win.parent = parent || this._windowContainer;
              this.addWin(win); // this.sortWins()

              if (pos != null) {
                win.position = pos;
              }

              this._prefabMap[path] = res;
              var basePanel = win.getComponent(name);

              if (basePanel) {
                basePanel.show(showData); // BusyLoadingManager.ins.removeBusy(BUSY_TYPE.RES)
              }

              resolve(basePanel);
            });
          });
        }

        addWin(win) {
          var winPanel = win.getComponent(win.name);
          var layer = winPanel.layer;
          var index = 0;

          for (var i = this._windows.length - 1; i >= 0; i--) {
            var tempWin = this._windows[i];
            var tempWinPanel = tempWin.getComponent(tempWin.name);

            if (tempWinPanel.layer <= layer) {
              index = i + 1;
              break;
            }
          }

          this._windows.splice(index, 0, win);
        } // private sortWins(): void {
        //     var bol: boolean = false
        //     for (var i = this._windows.length - 1; i >= 0; i--) {
        //         var win: Node = this._windows[i]
        //         // win.zIndex = i
        //         var winComp: BasePanel = win.getComponent(BasePanel);
        //         if (!winComp) {
        //             debugger;
        //         }
        //         if (bol) {
        //             win.active = false
        //         } else {
        //             win.active = true
        //             bol = winComp.winType == GameConst.WIN_TYPE.FULLSCREEN
        //         }
        //     }
        // }


        removeWin(name) {
          if (this._showlist[name]) {
            delete this._showlist[name];
          }

          for (var i = this._windows.length - 1; i >= 0; i--) {
            var win = this._windows[i];

            if (win.name == name) {
              var winComp = win.getComponent(win.name);

              if (winComp.winType != (_crd && GameConst === void 0 ? (_reportPossibleCrUseOfGameConst({
                error: Error()
              }), GameConst) : GameConst).WIN_TYPE.PERMANENT) {
                win.destroy();
                win = null;

                if (winComp.destroyAfterClose) {//to fix
                  // if (this._prefabMap[name])
                  //     loader.release(this._prefabMap[name])
                }

                this._windows.splice(i, 1);

                break;
              }
            }
          } // this.sortWins()

        }

        removeAll(exclude) {
          if (exclude === void 0) {
            exclude = null;
          }

          for (var i = this._windows.length - 1; i >= 0; i--) {
            var win = this._windows[i];
            if (exclude && exclude.indexOf(win.name)) continue;
            this.removeWin(win.name);
          }
        }

        isOpen(name) {
          // return this._showlist[name] == true;
          return this.getWin(name) != null;
        }

        isShow(name) {
          return this._showlist[name] == true;
        }

        getWinCount() {
          return (_crd && Utils === void 0 ? (_reportPossibleCrUseOfUtils({
            error: Error()
          }), Utils) : Utils).count(this._showlist);
        }

        getWin(name) {
          for (var i = this._windows.length - 1; i >= 0; i--) {
            var win = this._windows[i];
            if (win.name == name) return win;
          }

          return null;
        }

        get container() {
          return this._windowContainer;
        } //大杀器 切场景调用


        clearAll() {
          this._windows = [];
          this._showlist = {};
        }

      });

      WindowManager.instance = void 0;
      window['WindowManager'] = WindowManager;

      _cclegacy._RF.pop();

      _crd = false;
    }
  };
});
//# sourceMappingURL=36cd7db038cc04d84cd2fa8755ee27c88f6caaae.js.map