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

import { getOriginalRowHeight } from "./utils";

export class TableAPIExtensions {
    constructor(table, configManager, eventManager, callbacks) {
        this.currentMouseX = 0, this.currentMouseY = 0, this.isDragging = !1, this.dragStartIsPluginUnderline = !1, 
        this.table = table, this.configManager = configManager, this.eventManager = eventManager, 
        this.callbacks = callbacks, this.initMouseTracking();
    }
    initMouseTracking() {
        this.mouseEventListener = event => {
            try {
                const table = this.table;
                if (table && table.internalProps && table.internalProps.canvas) {
                    const rect = table.internalProps.canvas.getBoundingClientRect();
                    this.currentMouseX = event.clientX - rect.left, this.currentMouseY = event.clientY - rect.top;
                }
            } catch (error) {}
            "mouseup" === event.type && (this.isDragging = !1, this.dragStartIsPluginUnderline = !1);
        };
        try {
            const table = this.table;
            if (table && table.internalProps && table.internalProps.canvas) {
                const canvas = table.internalProps.canvas;
                canvas.addEventListener("mousemove", this.mouseEventListener), canvas.addEventListener("mousedown", this.mouseEventListener), 
                canvas.addEventListener("mouseup", this.mouseEventListener);
            }
        } catch (error) {}
    }
    extendTableAPI() {
        this.extendUpdateCellContent(), this.extendUpdateResizeRow(), this.extendDealHeightMode(), 
        this.extendUpdatePagination(), this.extendToggleHierarchyState(), this.extendUpdateFilterRules(), 
        this.extendUpdateChartSizeForResizeColWidth(), this.extendUpdateChartSizeForResizeRowHeight(), 
        this.extendGetRowY(), this.extendUpdateRowHeight(), this.extendGetResizeColAt();
    }
    extendUpdateCellContent() {
        const table = this.table;
        this.originalUpdateCellContent = table.scenegraph.updateCellContent.bind(table.scenegraph), 
        table.scenegraph.updateCellContent = (col, row, forceFastUpdate = !1) => {
            var _a, _b, _c, _d;
            if (this.eventManager.isRowExpanded(row)) {
                const bodyRowIndex = row - this.table.columnHeaderLevelCount, originalHeight = getOriginalRowHeight(this.table, bodyRowIndex), currentHeight = this.table.getRowHeight(row);
                if (originalHeight > 0 && currentHeight !== originalHeight) {
                    this.table._setRowHeight(row, originalHeight, !1);
                    const oldCellGroup = this.table.scenegraph.getCell(col, row), originalY = null === (_a = null == oldCellGroup ? void 0 : oldCellGroup.attribute) || void 0 === _a ? void 0 : _a.y, result = null === (_b = this.originalUpdateCellContent) || void 0 === _b ? void 0 : _b.call(this, col, row, forceFastUpdate);
                    if (this.table._setRowHeight(row, currentHeight, !1), void 0 !== originalY) {
                        const newCellGroup = this.table.scenegraph.getCell(col, row);
                        newCellGroup && newCellGroup.attribute.y !== originalY && newCellGroup.setAttribute("y", originalY);
                    }
                    const cellGroup = this.table.scenegraph.getCell(col, row);
                    return cellGroup && (row !== this.table.rowCount - 1 && this.callbacks.addUnderlineToCell(cellGroup, originalHeight), 
                    this.eventManager.handleAfterUpdateCellContentWidth({
                        col: col,
                        row: row,
                        cellHeight: (null === (_c = cellGroup.attribute) || void 0 === _c ? void 0 : _c.height) || 0,
                        cellGroup: cellGroup,
                        padding: [ 0, 0, 0, 0 ],
                        textBaseline: "middle"
                    })), result;
                }
            }
            return null === (_d = this.originalUpdateCellContent) || void 0 === _d ? void 0 : _d.call(this, col, row, forceFastUpdate);
        };
    }
    extendUpdateResizeRow() {
        const table = this.table;
        this.originalUpdateResizeRow = table.stateManager.updateResizeRow.bind(table.stateManager), 
        table.stateManager.updateResizeRow = (xInTable, yInTable) => {
            const state = table.stateManager;
            xInTable = Math.ceil(xInTable), yInTable = Math.ceil(yInTable);
            let detaY = state.rowResize.isBottomFrozen ? state.rowResize.y - yInTable : yInTable - state.rowResize.y;
            if (Math.abs(detaY) < 1) return;
            const resizeRowIndex = state.rowResize.row, isExpandedRow = this.eventManager.isRowExpanded(resizeRowIndex), originalLimitMinHeight = state.table.internalProps.limitMinHeight;
            let currentRowMinHeight = originalLimitMinHeight;
            if (isExpandedRow) {
                const bodyRowIndex = resizeRowIndex - this.table.columnHeaderLevelCount, originalHeight = getOriginalRowHeight(this.table, bodyRowIndex), detailHeight = this.table.getRowHeight(resizeRowIndex) - originalHeight;
                currentRowMinHeight = this.dragStartIsPluginUnderline ? originalLimitMinHeight + detailHeight : originalHeight + originalLimitMinHeight;
            }
            let afterSize = state.table.getRowHeight(state.rowResize.row) + detaY;
            if (afterSize < currentRowMinHeight && (afterSize = currentRowMinHeight, detaY = afterSize - state.table.getRowHeight(state.rowResize.row)), 
            "adaptive" === state.table.heightMode && state.rowResize.row < state.table.rowCount - 1) {
                let bottomRowHeight = state.table.getRowHeight(state.rowResize.row + 1);
                bottomRowHeight -= detaY;
                let nextRowMinHeight = originalLimitMinHeight;
                const nextRowIndex = state.rowResize.row + 1;
                if (this.eventManager.isRowExpanded(nextRowIndex)) {
                    const nextBodyRowIndex = nextRowIndex - this.table.columnHeaderLevelCount, nextOriginalHeight = getOriginalRowHeight(this.table, nextBodyRowIndex);
                    nextRowMinHeight = originalLimitMinHeight + (this.table.getRowHeight(nextRowIndex) - nextOriginalHeight);
                }
                bottomRowHeight - detaY < nextRowMinHeight && (detaY = bottomRowHeight - nextRowMinHeight);
            }
            detaY = Math.ceil(detaY), state.rowResize.row < state.table.columnHeaderLevelCount || state.rowResize.row >= state.table.rowCount - state.table.bottomFrozenRowCount ? this.updateResizeColForRow(detaY, state) : "all" === state.table.internalProps.rowResizeType ? this.updateResizeColForAll(detaY, state) : this.updateResizeColForRow(detaY, state), 
            state.rowResize.y = yInTable, state.table.scenegraph.component.updateResizeRow(state.rowResize.row, xInTable, state.rowResize.isBottomFrozen), 
            state.table.scenegraph.updateNextFrame();
        };
    }
    updateResizeColForRow(detaY, state) {
        "adaptive" === state.table.heightMode && state.rowResize.row < state.table.rowCount - 1 ? (state.table.scenegraph.updateRowHeight(state.rowResize.row, detaY), 
        state.table.scenegraph.updateRowHeight(state.rowResize.row + 1, -detaY), state.table.internalProps._heightResizedRowMap.add(state.rowResize.row), 
        state.table.internalProps._heightResizedRowMap.add(state.rowResize.row + 1)) : (state.table.scenegraph.updateRowHeight(state.rowResize.row, detaY), 
        state.table.internalProps._heightResizedRowMap.add(state.rowResize.row));
    }
    updateResizeColForAll(detaY, state) {
        for (let row = state.table.frozenRowCount; row < state.table.rowCount - state.table.bottomFrozenRowCount; row++) state.table.scenegraph.updateRowHeight(row, detaY), 
        state.table.internalProps._heightResizedRowMap.add(row);
    }
    extendDealHeightMode() {
        const scenegraph = this.table.scenegraph;
        this.originalDealHeightMode = scenegraph.dealHeightMode.bind(scenegraph), scenegraph.dealHeightMode = () => {
            if ("adaptive" !== this.table.heightMode) return this.originalDealHeightMode();
            const expandedRowIndices = this.eventManager.getExpandedRows(), table = this.table, tableAny = table;
            table._clearRowRangeHeightsMap();
            let startRow, totalDrawHeight;
            if ("all" === (tableAny.heightAdaptiveMode || "only-body")) startRow = 0, totalDrawHeight = table.tableNoFrameHeight; else {
                const columnHeaderHeight = table.getRowsHeight(0, table.columnHeaderLevelCount - 1), bottomHeaderHeight = table.isPivotChart() ? table.getBottomFrozenRowsHeight() : 0;
                startRow = table.columnHeaderLevelCount, totalDrawHeight = table.tableNoFrameHeight - columnHeaderHeight - bottomHeaderHeight;
            }
            const endRow = table.isPivotChart() ? table.rowCount - table.bottomFrozenRowCount : table.rowCount;
            if (0 === expandedRowIndices.length) {
                let normalRowsBaseHeight = 0;
                for (let row = startRow; row < endRow; row++) normalRowsBaseHeight += table.getRowHeight(row);
                if (normalRowsBaseHeight > 0) {
                    const scaleFactor = totalDrawHeight / normalRowsBaseHeight;
                    for (let row = startRow; row < endRow; row++) {
                        const baseHeight = table.getRowHeight(row), newHeight = Math.max(Math.round(baseHeight * scaleFactor), 20);
                        scenegraph.setRowHeight(row, newHeight);
                    }
                }
                return;
            }
            const expandedRowsInfo = new Map;
            let totalExpandedExtraHeight = 0;
            for (const rowIndex of expandedRowIndices) if (rowIndex >= table.columnHeaderLevelCount && rowIndex < endRow) {
                const bodyRowIndex = rowIndex - table.columnHeaderLevelCount, originalHeight = getOriginalRowHeight(table, bodyRowIndex), currentRowHeight = table.getRowHeight(rowIndex), detailHeight = currentRowHeight - originalHeight;
                expandedRowsInfo.set(rowIndex, {
                    baseHeight: originalHeight > 0 ? originalHeight : currentRowHeight,
                    detailHeight: detailHeight
                }), totalExpandedExtraHeight += detailHeight;
            }
            let normalRowsBaseHeight = 0;
            for (let row = startRow; row < endRow; row++) if (expandedRowsInfo.has(row)) {
                const info = expandedRowsInfo.get(row);
                info && (normalRowsBaseHeight += info.baseHeight);
            } else normalRowsBaseHeight += table.getRowHeight(row);
            const scaleFactor = (totalDrawHeight - totalExpandedExtraHeight) / normalRowsBaseHeight;
            for (let row = startRow; row < endRow; row++) {
                let newHeight;
                if (expandedRowsInfo.has(row)) {
                    const info = expandedRowsInfo.get(row);
                    if (info) {
                        const scaledBaseHeight = Math.round(info.baseHeight * scaleFactor);
                        newHeight = scaledBaseHeight + info.detailHeight, expandedRowsInfo.set(row, {
                            baseHeight: scaledBaseHeight,
                            detailHeight: info.detailHeight
                        });
                    } else newHeight = Math.round(table.getRowHeight(row) * scaleFactor);
                } else {
                    const baseHeight = table.getRowHeight(row);
                    newHeight = Math.round(baseHeight * scaleFactor);
                }
                scenegraph.setRowHeight(row, newHeight);
            }
            const allRows = [];
            for (let row = startRow; row < endRow; row++) allRows.push(row);
            if (allRows.length > 0) {
                const currentTotalHeight = allRows.reduce(((sum, row) => sum + table.getRowHeight(row)), 0);
                if (Math.abs(currentTotalHeight - totalDrawHeight) > 1) {
                    const lastRowIndex = allRows[allRows.length - 1], adjustment = totalDrawHeight - allRows.slice(0, -1).reduce(((sum, row) => sum + table.getRowHeight(row)), 0);
                    if (expandedRowsInfo.has(lastRowIndex)) {
                        const info = expandedRowsInfo.get(lastRowIndex);
                        if (info) {
                            const minHeight = info.detailHeight, finalHeight = Math.max(adjustment, minHeight);
                            scenegraph.setRowHeight(lastRowIndex, finalHeight), expandedRowsInfo.set(lastRowIndex, {
                                baseHeight: finalHeight - info.detailHeight,
                                detailHeight: info.detailHeight
                            });
                        }
                    } else scenegraph.setRowHeight(lastRowIndex, adjustment);
                }
            }
            this.callbacks.updateOriginalHeightsAfterAdaptive(expandedRowsInfo), this.callbacks.updateSubTablePositions();
        };
    }
    extendUpdatePagination() {
        const table = this.table;
        this.originalUpdatePagination = table.updatePagination.bind(table), table.updatePagination = pagination => {
            [ ...this.eventManager.getExpandedRows() ].forEach((rowIndex => {
                this.callbacks.collapseRowToNoRealRecordIndex(rowIndex);
            }));
            const result = this.originalUpdatePagination(pagination);
            return this.waitForRenderComplete((() => {
                this.callbacks.restoreExpandedStatesAfter();
            })), result;
        };
    }
    extendToggleHierarchyState() {
        const table = this.table;
        this.originalToggleHierarchyState = table.toggleHierarchyState.bind(table), table.toggleHierarchyState = (col, row, recalculateColWidths = !0) => {
            if (this.table.isHeader(col, row)) {
                [ ...this.eventManager.getExpandedRows() ].forEach((rowIndex => {
                    this.callbacks.collapseRowToNoRealRecordIndex(rowIndex);
                }));
                const result = this.originalToggleHierarchyState(col, row, recalculateColWidths);
                return this.waitForRenderComplete((() => {
                    this.callbacks.restoreExpandedStatesAfter();
                })), result;
            }
            return this.originalToggleHierarchyState(col, row, recalculateColWidths);
        };
    }
    extendUpdateFilterRules() {
        const table = this.table;
        this.originalUpdateFilterRules = table.updateFilterRules.bind(table), table.updateFilterRules = filterRules => {
            [ ...this.eventManager.getExpandedRows() ].forEach((rowIndex => {
                this.callbacks.collapseRow(rowIndex);
            }));
            return this.originalUpdateFilterRules(filterRules);
        };
    }
    extendUpdateChartSizeForResizeColWidth() {
        const table = this.table;
        this.originalUpdateChartSizeForResizeColWidth = table.scenegraph.updateChartSizeForResizeColWidth.bind(table.scenegraph), 
        table.scenegraph.updateChartSizeForResizeColWidth = col => {
            const originalGetRowHeight = table.getRowHeight.bind(table);
            table.getRowHeight = row => {
                if (this.eventManager.isRowExpanded(row)) {
                    const bodyRowIndex = row - this.table.columnHeaderLevelCount, originalHeight = getOriginalRowHeight(this.table, bodyRowIndex);
                    return originalHeight > 0 ? originalHeight : originalGetRowHeight(row);
                }
                return originalGetRowHeight(row);
            };
            const result = this.originalUpdateChartSizeForResizeColWidth(col);
            return table.getRowHeight = originalGetRowHeight, result;
        };
    }
    extendUpdateChartSizeForResizeRowHeight() {
        const table = this.table;
        this.originalUpdateChartSizeForResizeRowHeight = table.scenegraph.updateChartSizeForResizeRowHeight.bind(table.scenegraph), 
        table.scenegraph.updateChartSizeForResizeRowHeight = col => {
            const originalGetRowHeight = table.getRowHeight.bind(table);
            table.getRowHeight = row => {
                if (this.eventManager.isRowExpanded(row)) {
                    const bodyRowIndex = row - this.table.columnHeaderLevelCount, originalHeight = getOriginalRowHeight(this.table, bodyRowIndex);
                    return originalHeight > 0 ? originalHeight : originalGetRowHeight(row);
                }
                return originalGetRowHeight(row);
            };
            const result = this.originalUpdateChartSizeForResizeRowHeight(col);
            return table.getRowHeight = originalGetRowHeight, result;
        };
    }
    extendGetRowY() {
        var _a;
        const scenegraph = this.table.scenegraph;
        if (scenegraph.component) {
            const originalShowResizeRow = scenegraph.component.showResizeRow.bind(scenegraph.component);
            originalShowResizeRow && (scenegraph.component.showResizeRow = (row, x, isRightFrozen) => this.protectedShowResizeRow(originalShowResizeRow, row, x, isRightFrozen));
            const originalUpdateResizeRow = null === (_a = scenegraph.component.updateResizeRow) || void 0 === _a ? void 0 : _a.bind(scenegraph.component);
            originalUpdateResizeRow && (scenegraph.component.updateResizeRow = (row, x, isBottomFrozen) => this.protectedUpdateResizeRow(originalUpdateResizeRow, row, x, isBottomFrozen));
        }
    }
    extendUpdateRowHeight() {
        const scenegraph = this.table.scenegraph;
        this.originalUpdateRowHeight = scenegraph.updateRowHeight.bind(scenegraph), scenegraph.updateRowHeight = (row, detaY, skipTableHeightMap) => {
            if (!this.eventManager.isRowExpanded(row) || !this.isDragging || this.dragStartIsPluginUnderline) return this.originalUpdateRowHeight(row, detaY, skipTableHeightMap);
            detaY = Math.round(detaY), this.callbacks.updateRowHeightForExpand(row, detaY), 
            scenegraph.updateContainerHeight(row, detaY);
        };
    }
    extendGetResizeColAt() {
        const scenegraph = this.table.scenegraph;
        this.originalGetResizeColAt = scenegraph.getResizeColAt.bind(scenegraph), scenegraph.getResizeColAt = (abstractX, abstractY, cellGroup) => {
            if (!cellGroup) {
                const cell = this.table.getCellAtRelativePosition(abstractX, abstractY);
                if (cell && cell.row >= 0) {
                    if (this.eventManager.isRowExpanded(cell.row)) return {
                        col: -1,
                        row: -1
                    };
                }
            }
            return this.originalGetResizeColAt(abstractX, abstractY, cellGroup);
        };
    }
    isMouseInPluginUnderlineArea(row) {
        var _a, _b, _c, _d;
        try {
            const scrollTop = (null === (_b = null === (_a = this.table.stateManager) || void 0 === _a ? void 0 : _a.scroll) || void 0 === _b ? void 0 : _b.verticalBarPos) || 0, rowY = this.table.getRowsHeight(0, row - 1), rowHeight = this.table.getRowHeight(row), viewportRowBottomY = rowY + rowHeight - scrollTop + ((null === (_d = null === (_c = this.table.theme) || void 0 === _c ? void 0 : _c.frameStyle) || void 0 === _d ? void 0 : _d.shadowBlur) || 0), isNearRowBottom = this.currentMouseY >= viewportRowBottomY - (this.table.internalProps.limitMinHeight - 1) && this.currentMouseY <= viewportRowBottomY + (this.table.internalProps.limitMinHeight - 1), isExpandedRow = this.eventManager.isRowExpanded(row);
            return !(isNearRowBottom && isExpandedRow);
        } catch (error) {
            return !1;
        }
    }
    protectedShowResizeRow(originalMethod, row, x, isRightFrozen) {
        if (this.isDragging || (this.isDragging = !0, this.dragStartIsPluginUnderline = this.isMouseInPluginUnderlineArea(row)), 
        this.dragStartIsPluginUnderline) {
            const originalGetRowsHeight = this.table.getRowsHeight.bind(this.table);
            this.table.getRowsHeight = (startRow, endRow) => this.getRowsHeightWithOriginalHeight(startRow, endRow);
            const originalGetRowHeight = this.table.getRowHeight.bind(this.table);
            this.table.getRowHeight = targetRow => {
                if (targetRow === row && this.eventManager.isRowExpanded(targetRow)) {
                    const bodyRowIndex = targetRow - this.table.columnHeaderLevelCount, originalHeight = getOriginalRowHeight(this.table, bodyRowIndex);
                    return originalHeight > 0 ? originalHeight : originalGetRowHeight(targetRow);
                }
                return originalGetRowHeight(targetRow);
            };
            try {
                return originalMethod(row, x, isRightFrozen);
            } finally {
                this.table.getRowsHeight = originalGetRowsHeight, this.table.getRowHeight = originalGetRowHeight;
            }
        } else {
            const originalGetRowHeight = this.table.getRowHeight.bind(this.table);
            this.table.getRowHeight = targetRow => {
                if (targetRow === row && this.eventManager.isRowExpanded(targetRow)) {
                    const bodyRowIndex = targetRow - this.table.columnHeaderLevelCount, originalHeight = getOriginalRowHeight(this.table, bodyRowIndex);
                    return originalGetRowHeight(targetRow) - originalHeight;
                }
                return originalGetRowHeight(targetRow);
            };
            try {
                return originalMethod(row, x, isRightFrozen);
            } finally {
                this.table.getRowHeight = originalGetRowHeight;
            }
        }
    }
    protectedUpdateResizeRow(originalMethod, row, x, isBottomFrozen) {
        if (this.dragStartIsPluginUnderline) {
            const originalGetRowsHeight = this.table.getRowsHeight.bind(this.table);
            this.table.getRowsHeight = (startRow, endRow) => this.getRowsHeightWithOriginalHeight(startRow, endRow);
            const originalGetRowHeight = this.table.getRowHeight.bind(this.table);
            this.table.getRowHeight = targetRow => {
                if (targetRow === row && this.eventManager.isRowExpanded(targetRow)) {
                    const bodyRowIndex = targetRow - this.table.columnHeaderLevelCount, originalHeight = getOriginalRowHeight(this.table, bodyRowIndex);
                    return originalHeight > 0 ? originalHeight : originalGetRowHeight(targetRow);
                }
                return originalGetRowHeight(targetRow);
            };
            try {
                return originalMethod(row, x, isBottomFrozen);
            } finally {
                this.table.getRowsHeight = originalGetRowsHeight, this.table.getRowHeight = originalGetRowHeight;
            }
        } else {
            const originalGetRowHeight = this.table.getRowHeight.bind(this.table);
            this.table.getRowHeight = targetRow => {
                if (targetRow === row && this.eventManager.isRowExpanded(targetRow)) {
                    const bodyRowIndex = targetRow - this.table.columnHeaderLevelCount, originalHeight = getOriginalRowHeight(this.table, bodyRowIndex);
                    return originalGetRowHeight(targetRow) - originalHeight;
                }
                return originalGetRowHeight(targetRow);
            };
            try {
                return originalMethod(row, x, isBottomFrozen);
            } finally {
                this.table.getRowHeight = originalGetRowHeight;
            }
        }
    }
    getRowsHeightWithOriginalHeight(startRow, endRow) {
        let totalHeight = 0;
        for (let row = startRow; row <= endRow; row++) {
            if (this.eventManager.isRowExpanded(row) && row === endRow) {
                const bodyRowIndex = row - this.table.columnHeaderLevelCount, originalHeight = getOriginalRowHeight(this.table, bodyRowIndex);
                totalHeight += originalHeight > 0 ? originalHeight : this.table.getRowHeight(row);
            } else totalHeight += this.table.getRowHeight(row);
        }
        return totalHeight;
    }
    waitForRenderComplete(callback) {
        const onAfterRender = () => {
            this.table.off(TABLE_EVENT_TYPE.AFTER_RENDER, onAfterRender), callback();
        };
        this.table.on(TABLE_EVENT_TYPE.AFTER_RENDER, onAfterRender);
    }
    cleanup() {
        if (this.mouseEventListener) {
            try {
                const table = this.table;
                if (table && table.internalProps && table.internalProps.canvas) {
                    const canvas = table.internalProps.canvas;
                    canvas.removeEventListener("mousemove", this.mouseEventListener), canvas.removeEventListener("mousedown", this.mouseEventListener), 
                    canvas.removeEventListener("mouseup", this.mouseEventListener);
                }
            } catch (error) {}
            this.mouseEventListener = void 0;
        }
        if (this.originalUpdateCellContent && this.table) {
            const table = this.table;
            table.scenegraph && table.scenegraph.updateCellContent && (table.scenegraph.updateCellContent = this.originalUpdateCellContent), 
            this.originalUpdateCellContent = void 0;
        }
        if (this.originalUpdateResizeRow && this.table) {
            const table = this.table;
            table.stateManager && table.stateManager.updateResizeRow && (table.stateManager.updateResizeRow = this.originalUpdateResizeRow), 
            this.originalUpdateResizeRow = void 0;
        }
        if (this.originalDealHeightMode && this.table) {
            const table = this.table;
            table.scenegraph && table.scenegraph.dealHeightMode && (table.scenegraph.dealHeightMode = this.originalDealHeightMode), 
            this.originalDealHeightMode = void 0;
        }
        if (this.originalUpdatePagination && this.table) {
            const table = this.table;
            table.updatePagination && (table.updatePagination = this.originalUpdatePagination), 
            this.originalUpdatePagination = void 0;
        }
        if (this.originalToggleHierarchyState && this.table) {
            const table = this.table;
            table.toggleHierarchyState && (table.toggleHierarchyState = this.originalToggleHierarchyState), 
            this.originalToggleHierarchyState = void 0;
        }
        if (this.originalUpdateFilterRules && this.table) {
            const table = this.table;
            table.updateFilterRules && (table.updateFilterRules = this.originalUpdateFilterRules), 
            this.originalUpdateFilterRules = void 0;
        }
        if (this.originalUpdateChartSizeForResizeColWidth && this.table) {
            const table = this.table;
            table.scenegraph && table.scenegraph.updateChartSizeForResizeColWidth && (table.scenegraph.updateChartSizeForResizeColWidth = this.originalUpdateChartSizeForResizeColWidth), 
            this.originalUpdateChartSizeForResizeColWidth = void 0;
        }
        if (this.originalUpdateChartSizeForResizeRowHeight && this.table) {
            const table = this.table;
            table.scenegraph && table.scenegraph.updateChartSizeForResizeRowHeight && (table.scenegraph.updateChartSizeForResizeRowHeight = this.originalUpdateChartSizeForResizeRowHeight), 
            this.originalUpdateChartSizeForResizeRowHeight = void 0;
        }
        if (this.originalUpdateRowHeight && this.table) {
            const table = this.table;
            table.scenegraph && table.scenegraph.updateRowHeight && (table.scenegraph.updateRowHeight = this.originalUpdateRowHeight), 
            this.originalUpdateRowHeight = void 0;
        }
        if (this.originalGetResizeColAt && this.table) {
            const scenegraph = this.table.scenegraph;
            scenegraph && scenegraph.getResizeColAt && (scenegraph.getResizeColAt = this.originalGetResizeColAt), 
            this.originalGetResizeColAt = void 0;
        }
        this.isDragging = !1, this.dragStartIsPluginUnderline = !1, this.currentMouseX = 0, 
        this.currentMouseY = 0, this.callbacks = null, this.table = null, this.configManager = null, 
        this.eventManager = null;
    }
}
//# sourceMappingURL=table-api-extensions.js.map