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, TextAsset, CsvParser, Singleton, bundleMgr, GameConst, Logger, _dec, _class, _crd, ccclass, property, CsvManager, csvMgr;

  function _reportPossibleCrUseOfCsvParser(extras) {
    _reporterNs.report("CsvParser", "./CsvParser", _context.meta, extras);
  }

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

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

  function _reportPossibleCrUseOfGameConst(extras) {
    _reporterNs.report("GameConst", "../common/GameConst", _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;
      TextAsset = _cc.TextAsset;
    }, function (_unresolved_2) {
      CsvParser = _unresolved_2.CsvParser;
    }, function (_unresolved_3) {
      Singleton = _unresolved_3.Singleton;
    }, function (_unresolved_4) {
      bundleMgr = _unresolved_4.bundleMgr;
    }, function (_unresolved_5) {
      GameConst = _unresolved_5.GameConst;
    }, function (_unresolved_6) {
      Logger = _unresolved_6.Logger;
    }],
    execute: function () {
      _crd = true;

      _cclegacy._RF.push({}, "d5fb9D+44ZAy5iHguyBG4yt", "CsvManager", undefined);

      __checkObsolete__(['_decorator', 'error', 'TextAsset']);

      ({
        ccclass,
        property
      } = _decorator); //wws

      CsvManager = (_dec = ccclass('CsvManager'), _dec(_class = class CsvManager extends (_crd && Singleton === void 0 ? (_reportPossibleCrUseOfSingleton({
        error: Error()
      }), Singleton) : Singleton) {
        constructor(...args) {
          super(...args);
          // 表格所在的目录
          this._directory = 'csv';
          // 表格解析器单例
          this._parser = new (_crd && CsvParser === void 0 ? (_reportPossibleCrUseOfCsvParser({
            error: Error()
          }), CsvParser) : CsvParser)();
        }

        /*调用事例 加载所有CSV表
        await csvMgr.loadAll(
            (finished, total) => {
                Logger.log(`加载进度: ${finished}/${total}`);
            },
            (isAllFinished, tableName, data) => {
                Logger.log(`CSV加载完成`+ tableName);
            }
        );
        //获取表数据(异步)
        let levels = csvMgr.getTable("levels")
        Logger.log("物品表数据:", JSON.stringify(levels));
        //获取表数据 (异步)
        csvMgr.getTable("item").then(table => {
            Logger.log("物品表数据:", table);
        });*/

        /* 加载所有CSV配置表
         * @param onProgress 进度回调 (finished: 已加载数量, total: 总数量)
         * @param onLoaded 单个表加载完成回调 (isAllFinished: 是否全部完成, tableName: 表名, data: 表数据)
         * @returns Promise<void> 当所有表加载完成或出错时resolve/reject
         */
        async loadAll(onProgress, onLoaded) {
          const bundle = await (_crd && bundleMgr === void 0 ? (_reportPossibleCrUseOfbundleMgr({
            error: Error()
          }), bundleMgr) : bundleMgr).getBundle((_crd && GameConst === void 0 ? (_reportPossibleCrUseOfGameConst({
            error: Error()
          }), GameConst) : GameConst).bundleName.resources); //1. 获取目录下所有CSV文件列表（不实际加载资源）

          const fileList = bundle.getDirWithPath(this._directory);

          if (fileList.length === 0) {
            (_crd && Logger === void 0 ? (_reportPossibleCrUseOfLogger({
              error: Error()
            }), Logger) : Logger).warn(`目录 ${this._directory} 下未找到CSV文件`);
            return;
          }

          const total = fileList.length;
          let loadedCount = 0; //2. 逐个加载文件

          for (const file of fileList) {
            const asset = await this._loadSingleTable(file.path); //解析数据并缓存

            const data = this._parser.addTable(asset.name, asset.text); //更新进度和回调


            loadedCount++;
            onProgress == null || onProgress(loadedCount, total);
            const tableName = file.path.split('/').pop();
            onLoaded == null || onLoaded(loadedCount == total, tableName, data);
          }
        }
        /**
         * 加载单个CSV表
         * @param path 表路径
         * @returns Promise<TextAsset> 加载成功的TextAsset
         * @private
         */


        async _loadSingleTable(path) {
          const bundle = await (_crd && bundleMgr === void 0 ? (_reportPossibleCrUseOfbundleMgr({
            error: Error()
          }), bundleMgr) : bundleMgr).getBundle((_crd && GameConst === void 0 ? (_reportPossibleCrUseOfGameConst({
            error: Error()
          }), GameConst) : GameConst).bundleName.resources);
          return new Promise((resolve, reject) => {
            bundle.load(path, TextAsset, (err, asset) => {
              if (err || !asset) {
                reject(err || new Error(`加载资源 ${path} 失败`));
              } else {
                resolve(asset);
              }
            });
          });
        }
        /**
         * 调用事例 csvMgr.getTable('weapon');
         * 异步获取表数据（如果表未加载会自动加载）
         * @param tableName 表名
         * @returns Promise<T[]> 表数据数组
         */


        getTableArr(tableName) {
          return this._parser.getTableArr(tableName);
        }
        /**调用事例 csvMgr.findOne('weapon', w => w.quality === 'epic')
         * 查询单条记录
         * @param tableName 表名
         * @param predicate 查询条件函数
         * @returns 匹配的第一条记录或undefined
         */


        findOne(tableName, predicate) {
          return this.getTableArr(tableName).find(predicate);
        }
        /**
         * 查询多条记录
         * @param tableName 表名
         * @param predicate 查询条件函数
         * @returns 匹配的所有记录数组
         */


        findMany(tableName, predicate) {
          return this.getTableArr(tableName).filter(predicate);
        }

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

      _export("csvMgr", csvMgr = CsvManager.ins());

      _cclegacy._RF.pop();

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