"use strict";

Object.defineProperty(exports, "__esModule", {
    value: !0
}), exports.RowSeriesPlugin = void 0;

const vtable_1 = require("@visactor/vtable");

class RowSeriesPlugin {
    constructor(pluginOptions) {
        var _a;
        this.id = "row-series", this.name = "Row Series", this.runTime = [ vtable_1.TABLE_EVENT_TYPE.BEFORE_INIT, vtable_1.TABLE_EVENT_TYPE.BEFORE_KEYDOWN ], 
        this.id = null !== (_a = pluginOptions.id) && void 0 !== _a ? _a : this.id, this.pluginOptions = Object.assign({
            rowCount: 100
        }, pluginOptions);
    }
    run(...args) {
        var _a, _b;
        if (args[1] === vtable_1.TABLE_EVENT_TYPE.BEFORE_INIT) {
            const eventArgs = args[0], table = args[2];
            this.table = table;
            const options = eventArgs.options, records = null !== (_a = options.records) && void 0 !== _a ? _a : [];
            for (let i = records.length; i < this.pluginOptions.rowCount; i++) records.push(this.pluginOptions.fillRowRecord ? this.pluginOptions.fillRowRecord(i) : {});
            options.records = records, this.pluginOptions.rowSeriesNumber ? (options.rowSeriesNumber = this.pluginOptions.rowSeriesNumber, 
            this.pluginOptions.rowSeriesNumber.width || (options.rowSeriesNumber.width = "auto")) : options.rowSeriesNumber || (options.rowSeriesNumber = {
                width: "auto"
            });
        } else if (args[1] === vtable_1.TABLE_EVENT_TYPE.BEFORE_KEYDOWN) {
            const e = args[0].event;
            (null === (_b = this.pluginOptions.autoExtendRowTriggerKeys) || void 0 === _b ? void 0 : _b.includes(e.key)) && this.table.stateManager.select.cellPos.row === this.table.rowCount - 1 && this.table.addRecord(this.pluginOptions.fillRowRecord ? this.pluginOptions.fillRowRecord(this.table.rowCount - this.table.columnHeaderLevelCount) : {});
        }
    }
}

exports.RowSeriesPlugin = RowSeriesPlugin;