function isInteger(value) {
    return Math.floor(value) === value;
}

export class CarouselAnimationPlugin {
    constructor(table, options) {
        var _a, _b, _c, _d, _e, _f;
        this.willUpdateRow = !1, this.willUpdateCol = !1, this.table = table, this.rowCount = null !== (_a = null == options ? void 0 : options.rowCount) && void 0 !== _a ? _a : void 0, 
        this.colCount = null !== (_b = null == options ? void 0 : options.colCount) && void 0 !== _b ? _b : void 0, 
        this.animationDuration = null !== (_c = null == options ? void 0 : options.animationDuration) && void 0 !== _c ? _c : 500, 
        this.animationDelay = null !== (_d = null == options ? void 0 : options.animationDelay) && void 0 !== _d ? _d : 1e3, 
        this.animationEasing = null !== (_e = null == options ? void 0 : options.animationEasing) && void 0 !== _e ? _e : "linear", 
        this.replaceScrollAction = null !== (_f = null == options ? void 0 : options.replaceScrollAction) && void 0 !== _f && _f, 
        this.customDistColFunction = options.customDistColFunction, this.customDistRowFunction = options.customDistRowFunction, 
        this.reset(), this.init();
    }
    init() {
        this.replaceScrollAction && (this.table.disableScroll(), this.table.scenegraph.stage.addEventListener("wheel", this.onScrollEnd.bind(this)));
    }
    reset() {
        this.playing = !1, this.row = this.table.frozenRowCount, this.col = this.table.frozenColCount;
    }
    onScrollEnd(e) {
        this.rowCount ? (e.deltaY > 0 ? (this.row += this.rowCount, this.row = Math.min(this.row, this.table.rowCount - this.table.frozenRowCount)) : e.deltaY < 0 && (this.row -= this.rowCount, 
        this.row = Math.max(this.row, this.table.frozenRowCount)), this.table.scrollToRow(this.row, {
            duration: this.animationDuration,
            easing: this.animationEasing
        })) : this.colCount && (e.deltaX > 0 ? (this.col += this.colCount, this.col = Math.min(this.col, this.table.colCount - this.table.frozenColCount)) : e.deltaX < 0 && (this.col -= this.colCount, 
        this.col = Math.max(this.col, this.table.frozenColCount)), this.table.scrollToCol(this.col, {
            duration: this.animationDuration,
            easing: this.animationEasing
        }));
    }
    play() {
        this.playing = !0, this.rowCount && !this.willUpdateRow ? this.updateRow() : this.colCount && !this.willUpdateCol && this.updateCol();
    }
    pause() {
        this.playing = !1;
    }
    updateRow() {
        var _a;
        if (!this.playing || this.table.isReleased) return;
        let animation = !0;
        const customRow = this.customDistRowFunction && this.customDistRowFunction(this.row, this.table);
        customRow ? (this.row = customRow.distRow, animation = null === (_a = customRow.animation) || void 0 === _a || _a) : isInteger(this.row) && this.table.scenegraph.proxy.screenTopRow !== this.row ? (this.row = this.table.frozenRowCount, 
        animation = !1) : isInteger(this.row) || this.table.scenegraph.proxy.screenTopRow === Math.floor(this.row) ? this.row += this.rowCount : (this.row = this.table.frozenRowCount, 
        animation = !1), this.table.scrollToRow(this.row, animation ? {
            duration: this.animationDuration,
            easing: this.animationEasing
        } : void 0), this.willUpdateRow = !0, setTimeout((() => {
            this.willUpdateRow = !1, this.updateRow();
        }), this.animationDuration + this.animationDelay);
    }
    updateCol() {
        var _a;
        if (!this.playing || this.table.isReleased) return;
        let animation = !0;
        const customCol = this.customDistColFunction && this.customDistColFunction(this.col, this.table);
        customCol ? (this.col = customCol.distCol, animation = null === (_a = customCol.animation) || void 0 === _a || _a) : isInteger(this.col) && this.table.scenegraph.proxy.screenLeftCol !== this.col ? (this.col = this.table.frozenColCount, 
        animation = !1) : isInteger(this.col) || this.table.scenegraph.proxy.screenLeftCol === Math.floor(this.col) ? this.col += this.colCount : (this.col = this.table.frozenColCount, 
        animation = !1), this.table.scrollToCol(this.col, animation ? {
            duration: this.animationDuration,
            easing: this.animationEasing
        } : void 0), this.willUpdateCol = !0, setTimeout((() => {
            this.willUpdateCol = !1, this.updateCol();
        }), this.animationDuration + this.animationDelay);
    }
}
//# sourceMappingURL=carousel-animation.js.map