"use strict";
Object.defineProperty(exports, "__esModule", {
    value: true
});
Object.defineProperty(exports, "PapaCSVReader", {
    enumerable: true,
    get: function() {
        return PapaCSVReader;
    }
});
const _papaparse = /*#__PURE__*/ _interop_require_default(require("papaparse"));
const _Node = require("../Node.js");
const _type = require("./type.js");
function _interop_require_default(obj) {
    return obj && obj.__esModule ? obj : {
        default: obj
    };
}
class PapaCSVReader extends _type.FileReader {
    concatRows;
    colJoiner;
    rowJoiner;
    papaConfig;
    /**
   * Constructs a new instance of the class.
   * @param {boolean} [concatRows=true] - whether to concatenate all rows into one document.If set to False, a Document will be created for each row.True by default.
   * @param {string} [colJoiner=', '] - Separator to use for joining cols per row. Set to ", " by default.
   * @param {string} [rowJoiner='\n'] - Separator to use for joining each row.Only used when `concat_rows=True`.Set to "\n" by default.
   */ constructor(concatRows = true, colJoiner = ", ", rowJoiner = "\n", papaConfig){
        super();
        this.concatRows = concatRows;
        this.colJoiner = colJoiner;
        this.rowJoiner = rowJoiner;
        this.papaConfig = papaConfig;
    }
    /**
   * Loads data from csv files
   * @param {string} file - The path to the file to load.
   * @param {GenericFileSystem} [fs=DEFAULT_FS] - The file system to use for reading the file.
   * @returns {Promise<Document[]>}
   */ async loadDataAsContent(fileContent) {
        const result = _papaparse.default.parse(fileContent.toString("utf-8"), this.papaConfig);
        const textList = result.data.map((row)=>{
            // Compatible with header row mode
            const rowValues = Object.values(row).map((value)=>String(value));
            return rowValues.join(this.colJoiner);
        });
        if (this.concatRows) {
            return [
                new _Node.Document({
                    text: textList.join(this.rowJoiner)
                })
            ];
        } else {
            return textList.map((text)=>new _Node.Document({
                    text
                }));
        }
    }
}
