export class FormulaEventUtils {
    static onFormulaErrorWithUserFeedback(eventManager, errorHandler) {
        eventManager.on("formula_error", (event => {
            errorHandler(event);
        }));
    }
    static onFormulaPerformanceMonitoring(eventManager, threshold = 1e3) {
        eventManager.on("formula_calculate_end", (event => {
            event.duration && event.duration;
        }));
    }
    static setupFormulaEventListeners(eventManager, listeners) {
        listeners.onFormulaAdded && eventManager.on("formula_added", (event => {
            listeners.onFormulaAdded(event.cell, event.formula);
        })), listeners.onFormulaRemoved && eventManager.on("formula_removed", (event => {
            listeners.onFormulaRemoved(event.cell, event.formula);
        })), listeners.onFormulaError && eventManager.on("formula_error", listeners.onFormulaError), 
        listeners.onFormulaCalculateStart && eventManager.on("formula_calculate_start", (event => {
            listeners.onFormulaCalculateStart(event.formulaCount);
        })), listeners.onFormulaCalculateEnd && eventManager.on("formula_calculate_end", (event => {
            listeners.onFormulaCalculateEnd(event.formulaCount, event.duration);
        })), listeners.onFormulaDependencyChanged && eventManager.on("formula_dependency_changed", (() => {
            listeners.onFormulaDependencyChanged();
        }));
    }
    static createFormulaProgressTracker(eventManager, onProgress) {
        let startTime, totalFormulas;
        const startListener = event => {
            startTime = Date.now(), totalFormulas = event.formulaCount || 0, onProgress && onProgress(0, totalFormulas);
        }, endListener = event => {
            event.duration || Date.now();
            onProgress && onProgress(totalFormulas, totalFormulas);
        };
        return {
            start: () => {
                eventManager.on("formula_calculate_start", startListener), eventManager.on("formula_calculate_end", endListener);
            },
            end: () => {
                eventManager.off("formula_calculate_start", startListener), eventManager.off("formula_calculate_end", endListener);
            }
        };
    }
    static createFormulaErrorCollector(eventManager) {
        const errors = [], errorListener = event => {
            errors.push(event);
        };
        return {
            getErrors: () => [ ...errors ],
            clear: () => {
                errors.length = 0;
            },
            start: () => {
                eventManager.on("formula_error", errorListener);
            },
            end: () => {
                eventManager.off("formula_error", errorListener);
            }
        };
    }
}
//# sourceMappingURL=formula-event-utils.js.map