import { VTableSheetEventType, WORKSHEET_EVENT_TYPES } from "../ts-types/spreadsheet-events";

import { BaseEventManager } from "./base-event-manager";

export class WorkSheetEventManager extends BaseEventManager {
    constructor(worksheet) {
        super(worksheet.getEventBus()), this.worksheet = worksheet;
    }
    getEventTypes() {
        return Array.from(WORKSHEET_EVENT_TYPES);
    }
    on(type, callback) {
        this.eventBus.on(type, callback);
    }
    off(type, callback) {
        callback ? this.eventBus.off(type, callback) : this.eventBus.off(type);
    }
    emit(type, event) {
        this.eventBus.emit(type, event);
    }
    emitFormulaCalculateStart(formulaCount) {
        const event = {
            sheetKey: this.worksheet.sheetKey,
            formulaCount: formulaCount
        };
        this.emit(VTableSheetEventType.FORMULA_CALCULATE_START, event);
    }
    emitFormulaCalculateEnd(formulaCount, duration) {
        const event = {
            sheetKey: this.worksheet.sheetKey,
            formulaCount: formulaCount,
            duration: duration
        };
        this.emit(VTableSheetEventType.FORMULA_CALCULATE_END, event);
    }
    emitFormulaError(cell, formula, error) {
        const event = {
            sheetKey: this.worksheet.sheetKey,
            cell: cell,
            formula: formula,
            error: error
        };
        this.emit(VTableSheetEventType.FORMULA_ERROR, event);
    }
    emitFormulaDependencyChanged() {
        const event = {
            sheetKey: this.worksheet.sheetKey
        };
        this.emit(VTableSheetEventType.FORMULA_DEPENDENCY_CHANGED, event);
    }
    emitFormulaAdded(cell, formula) {
        const event = {
            sheetKey: this.worksheet.sheetKey,
            cell: cell,
            formula: formula
        };
        this.emit(VTableSheetEventType.FORMULA_ADDED, event);
    }
    emitFormulaRemoved(cell, formula) {
        const event = {
            sheetKey: this.worksheet.sheetKey,
            cell: cell,
            formula: formula
        };
        this.emit(VTableSheetEventType.FORMULA_REMOVED, event);
    }
    emitDataLoaded(rowCount, colCount) {
        const event = {
            sheetKey: this.worksheet.sheetKey,
            rowCount: rowCount,
            colCount: colCount
        };
        this.emit(VTableSheetEventType.DATA_LOADED, event);
    }
}
//# sourceMappingURL=worksheet-event-manager.js.map