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

  var _reporterNs, _cclegacy, __checkObsolete__, __checkObsoleteInNamespace__, _decorator, director, instantiate, Prefab, Vec3, Singleton, bundleMgr, GameConst, Utils, Logger, _dec, _class, _crd, ccclass, property, UIManager, uiMgr;

  function _reportPossibleCrUseOfSingleton(extras) {
    _reporterNs.report("Singleton", "./Singleton", _context.meta, extras);
  }

  function _reportPossibleCrUseOfbundleMgr(extras) {
    _reporterNs.report("bundleMgr", "./BundleManager", _context.meta, extras);
  }

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

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

  function _reportPossibleCrUseOfLogger(extras) {
    _reporterNs.report("Logger", "../extend/Logger", _context.meta, extras);
  }

  return {
    setters: [function (_unresolved_) {
      _reporterNs = _unresolved_;
    }, function (_cc) {
      _cclegacy = _cc.cclegacy;
      __checkObsolete__ = _cc.__checkObsolete__;
      __checkObsoleteInNamespace__ = _cc.__checkObsoleteInNamespace__;
      _decorator = _cc._decorator;
      director = _cc.director;
      instantiate = _cc.instantiate;
      Prefab = _cc.Prefab;
      Vec3 = _cc.Vec3;
    }, function (_unresolved_2) {
      Singleton = _unresolved_2.Singleton;
    }, function (_unresolved_3) {
      bundleMgr = _unresolved_3.bundleMgr;
    }, function (_unresolved_4) {
      GameConst = _unresolved_4.GameConst;
    }, function (_unresolved_5) {
      Utils = _unresolved_5.default;
    }, function (_unresolved_6) {
      Logger = _unresolved_6.Logger;
    }],
    execute: function () {
      _crd = true;

      _cclegacy._RF.push({}, "0147cbbDu9Ocrbvs5hFJwAG", "UIManager", undefined);

      __checkObsolete__(['_decorator', 'assetManager', 'Component', 'director', 'instantiate', 'Node', 'Prefab', 'Vec3']);

      ({
        ccclass,
        property
      } = _decorator);

      _export("UIManager", UIManager = (_dec = ccclass("UIManager"), _dec(_class = class UIManager extends (_crd && Singleton === void 0 ? (_reportPossibleCrUseOfSingleton({
        error: Error()
      }), Singleton) : Singleton) {
        constructor(...args) {
          super(...args);
          //tabbar pages主页面节点放在这个容器中
          this.pageUIs = 'pageUIs';
          //pop dialog出来的节点放在这个容器中
          this.popUIs = 'popUIs';
          //页面缓存
          this.panels = new Map();
        }

        /**
        * 展示场景
        * @param sceneName 场景名字
        * @param delay 延迟的时间
        */
        showScene(sceneName, delay = 0.1) {
          if (delay) {
            setTimeout(() => {
              director.loadScene(sceneName);
            }, delay * 1000);
          } else {
            director.loadScene(sceneName);
          }
        }
        /**
         * 展示一个resources资源包里的节点
         * @param path Prefab的路径名称
         * @param args 给组建传递的参数
         * @param cb 展示完成的回调函数
         * @returns 
         */


        async show(path, args, cb) {
          let prefabNames = path.split('/').pop();

          if (!args) {
            args = [];
          }

          const scriptName = prefabNames.replace(/^\w/, c => c.toUpperCase());
          let panel = await this.asyncLoad(path);
          if (!panel) return; //动态添加页面的路径path信息，在关闭和销毁的时候用到

          panel['_uiPath'] = path;
          let isMain = Object.values((_crd && GameConst === void 0 ? (_reportPossibleCrUseOfGameConst({
            error: Error()
          }), GameConst) : GameConst).mainUIs).includes(path);
          const name = isMain ? this.pageUIs : this.popUIs;
          const parent = (_crd && Utils === void 0 ? (_reportPossibleCrUseOfUtils({
            error: Error()
          }), Utils) : Utils).findName(this.getCurentSceneRoot(), name);
          panel.parent = parent;

          if (isMain) {
            parent.children.forEach(e => {
              e.setPosition(new Vec3(e.name == scriptName ? 0 : 50000, 0));
            });
          } else {
            panel.setSiblingIndex(parent.children.length);
          }

          const comp = panel.getComponent(scriptName);

          if (comp && comp['show']) {
            comp['show'].apply(comp, args);
          }

          if (typeof cb === 'function') {
            cb == null || cb(panel);
          }

          ;
        }
        /**
         * 根据堆栈页面顺序返回到某一个页面
         * @param path 返回某一个界面
         * @param args 返回的附带参数
         * @param cb 回调
         * @returns 
         */


        pop(path, args, cb) {
          let canvas = this.getCurentSceneRoot();
          let popUIs = (_crd && Utils === void 0 ? (_reportPossibleCrUseOfUtils({
            error: Error()
          }), Utils) : Utils).findName(canvas, this.popUIs);
          let isMain = Object.values((_crd && GameConst === void 0 ? (_reportPossibleCrUseOfGameConst({
            error: Error()
          }), GameConst) : GameConst).mainUIs).includes(path);
          let comp = null;

          if ((_crd && Utils === void 0 ? (_reportPossibleCrUseOfUtils({
            error: Error()
          }), Utils) : Utils).isNull(path)) {
            if (popUIs.children.length > 0) {
              //关闭存在的popUIs最后一个节点
              let node = popUIs.children.slice(-2)[0];
              node.parent = null;
              comp = node.getComponent(node.name);
            } else {
              //返回主页面的上一层节点
              comp = this.getPageComponent((_crd && GameConst === void 0 ? (_reportPossibleCrUseOfGameConst({
                error: Error()
              }), GameConst) : GameConst).mainUIs.page1);
              comp.tabBarIndex = comp.preIndexs.slice(-2)[0];
            }
          } else {
            let scriptName = path.split('/').pop().replace(/^\w/, c => c.toUpperCase());

            if (!args) {
              args = [];
            }

            if (isMain) {
              comp = this.getPageComponent((_crd && GameConst === void 0 ? (_reportPossibleCrUseOfGameConst({
                error: Error()
              }), GameConst) : GameConst).mainUIs.page1);
              comp.tabBarIndex = comp.sceneNames.indexOf(path);
              popUIs.removeAllChildren();
            } else {
              let panel = this.panels.get(path);
              let targetIndex = popUIs.children.findIndex(n => n.name === scriptName);

              if (targetIndex !== -1) {
                popUIs.children.slice(targetIndex + 1).forEach(n => {
                  n.parent = null;
                });
                popUIs.children.splice(targetIndex + 1);
              }

              panel.setSiblingIndex(panel.parent.children.length);
              comp = panel.getComponent(scriptName);
            }
          }

          if (comp && comp['pop']) {
            comp['pop'].apply(comp, args);
          }

          if (typeof cb === 'function') {
            cb == null || cb();
          }

          ;
        }
        /**
         * 直接关闭固定的名字中的一个页面
         * @param path Prefab的路径名称
         * @param cb 展示完成的回调函数
         * @returns 
         */


        hide(path, cb) {
          if (!this.panels.has(path)) return;
          let panel = this.panels.get(path);
          const scriptName = path.split('/').pop().replace(/^\w/, c => c.toUpperCase());
          let isMain = Object.values((_crd && GameConst === void 0 ? (_reportPossibleCrUseOfGameConst({
            error: Error()
          }), GameConst) : GameConst).mainUIs).includes(path);

          if (isMain) {
            let container = (_crd && Utils === void 0 ? (_reportPossibleCrUseOfUtils({
              error: Error()
            }), Utils) : Utils).findName(this.getCurentSceneRoot(), this.pageUIs);
            container.children.forEach(e => {
              e.setPosition(new Vec3(e.name == scriptName ? 5000 : 0, 0));
            });
          } else {
            panel.parent = null;
            const comp = panel.getComponent(scriptName);

            if (comp && comp['hide']) {
              comp['hide'].apply(comp);
            }

            if (typeof cb === 'function') {
              cb == null || cb();
            }

            ;
          }
        }
        /**
         * 得到一个prefabs预制体页面
         * @param path 主要路径节点
         * @returns 返回一个节点
         */


        async asyncLoad(path) {
          return new Promise((resolve, reject) => {
            if (this.panels.has(path)) {
              let page = this.panels.get(path);
              return resolve && resolve(page);
            } else {
              (_crd && bundleMgr === void 0 ? (_reportPossibleCrUseOfbundleMgr({
                error: Error()
              }), bundleMgr) : bundleMgr).loadAsset((_crd && GameConst === void 0 ? (_reportPossibleCrUseOfGameConst({
                error: Error()
              }), GameConst) : GameConst).bundleName.resources, path, Prefab, (err, prefab) => {
                if (err) {
                  (_crd && Logger === void 0 ? (_reportPossibleCrUseOfLogger({
                    error: Error()
                  }), Logger) : Logger).error("加载动画资源失败：", err);
                  reject && reject();
                } else {
                  let page = instantiate(prefab);
                  this.panels.set(path, page);
                  return resolve && resolve(page);
                }
              });
            }
          });
        }
        /**
         * 从缓存页面中获取一个脚本
         * @param path 缓存的路径
         * @param scriptName 不传默认获取path名字最后一个字符串作为脚本的名字
         * @returns 
         */


        getPageComponent(path, scriptName) {
          if (!this.panels.has(path)) {
            return null;
          } else {
            let name = scriptName ? scriptName : path.split('/').pop();
            let node = this.panels.get(path);
            return node.getComponent(name);
          }
        }
        /**
         *从缓存页面中获取一个页面
         * @param path 缓存的路径
         */


        getPageNode(path) {
          if ((_crd && Utils === void 0 ? (_reportPossibleCrUseOfUtils({
            error: Error()
          }), Utils) : Utils).isNull(path)) return null;
          if (!this.panels.has(path)) return null;
          return this.panels.get(path);
        }
        /**
         * 在界面中显示的节点是否存在
         */


        hasPageNode(path) {
          if ((_crd && Utils === void 0 ? (_reportPossibleCrUseOfUtils({
            error: Error()
          }), Utils) : Utils).isNull(path)) return false;
          let name = path.split('/').pop();
          let canvas = this.getCurentSceneRoot();
          let pages = (_crd && Utils === void 0 ? (_reportPossibleCrUseOfUtils({
            error: Error()
          }), Utils) : Utils).findName(canvas, this.pageUIs);
          let popUIs = (_crd && Utils === void 0 ? (_reportPossibleCrUseOfUtils({
            error: Error()
          }), Utils) : Utils).findName(canvas, this.popUIs);
          let nodes = pages.children.concat(popUIs.children);
          return nodes.some(e => e.name == name);
        }
        /**
         * 得到当前场景的节点的根节点
         * @returns 根结点
         */


        getCurentSceneRoot() {
          return director.getScene().getChildByName('Canvas');
        }

      }) || _class)); //全局单例


      _export("uiMgr", uiMgr = UIManager.ins());

      _cclegacy._RF.pop();

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