"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.EventApiImpl = void 0;
const tslib_1 = require("tslib");
const ApiBase_1 = require("./ApiBase");
const Emitter_1 = tslib_1.__importDefault(require("../../Utilities/Emitter"));
const EventInternalApi_1 = require("../Internal/EventInternalApi");
class EventApiImpl extends ApiBase_1.ApiBase {
    emitter;
    internalApi;
    constructor(_adaptable) {
        super(_adaptable);
        this.emitter = new Emitter_1.default();
        this.internalApi = new EventInternalApi_1.EventInternalApi(_adaptable);
    }
    destroy() {
        super.destroy();
        this.emitSync('AdaptableDestroy');
        this.emitter.destroy();
    }
    on = (eventName, callback) => {
        let result;
        if (eventName === 'AdaptableReady') {
            this.emitter.onIncludeFiredOnce(eventName).then(callback);
            return () => { };
        }
        else {
            result = this.emitter.on(eventName, callback);
        }
        return result;
    };
    off = (eventName, callback) => this.emitter.off(eventName, callback);
    emit = (eventName, data) => this.emitter.emit(eventName, data);
    emitSync = (eventName, data) => this.emitter.emitSync(eventName, data);
}
exports.EventApiImpl = EventApiImpl;
