import { TABLE_EVENT_TYPE } from "@visactor/vtable";

import { AutoFillManager } from "./auto-fill-manager";

export * from "./formula-integration";

export * from "./types";

export * from "./rules";

export class AutoFillPlugin {
    constructor(options) {
        this.id = "auto-fill", this.name = "Auto Fill", this.runTime = [ TABLE_EVENT_TYPE.MOUSEDOWN_FILL_HANDLE, TABLE_EVENT_TYPE.DRAG_FILL_HANDLE_END, TABLE_EVENT_TYPE.DBLCLICK_FILL_HANDLE ], 
        this.autoFillManager = new AutoFillManager(options);
    }
    run(...args) {
        var _a, _b;
        if (args[1] === TABLE_EVENT_TYPE.MOUSEDOWN_FILL_HANDLE) {
            const [, , table] = args;
            this.table = table, this.autoFillManager.setTable(this.table), this.autoFillManager.handleStartDrag(null === (_a = this.table) || void 0 === _a ? void 0 : _a.getSelectedCellRanges()[0]);
        } else if (args[1] === TABLE_EVENT_TYPE.DRAG_FILL_HANDLE_END) {
            const [{direction: direction}] = args;
            this.autoFillManager.handleEndDrag(null === (_b = this.table) || void 0 === _b ? void 0 : _b.getSelectedCellRanges()[0], direction);
        } else args[1] === TABLE_EVENT_TYPE.DBLCLICK_FILL_HANDLE && this.autoFillManager.handleDbClick();
    }
}