export var Events;
(function (Events) {
    Events["ErrorsLoad"] = "fb:errors:load";
    Events["FeatureValueChanged"] = "fb:feature:value:changed";
    Events["GridLabelResize"] = "fb:group:{0}:grid:label:resize";
    Events["GridDescriptionResize"] = "fb:group:{0}:grid:description:resize";
    Events["GridInputSelected"] = "fb:group:{0}:grid:input:selected";
    Events["GridFilter"] = "fb:group:{0}:grid:filter";
    Events["CategoriesExpandAll"] = "fb:group:{0}:grid:categories:expand-all";
    Events["CategoriesCollapseAll"] = "fb:group:{0}:grid:categories:collapse-all";
    Events["NavigationSelect"] = "fb:navigation:select";
    Events["FeaturesLoaded"] = "fb:features:loaded";
})(Events || (Events = {}));
export class EventsHub {
    constructor(options = {}) {
        this.m_scope = options.scope;
    }
    get contexts() {
        return Jade.Application.instance.contexts;
    }
    get global() {
        return this.contexts.global.events;
    }
    get current() {
        return this.contexts.current.events;
    }
    get local() {
        return this.contexts.current.events;
    }
    get scope() {
        return this.m_scope;
    }
    errorsLoadSubscribe(callback) {
        return this.current.subscribe(Events.ErrorsLoad, callback);
    }
    featuresLoadedSubscribe(callback) {
        return this.current.subscribe(Events.FeaturesLoaded, callback);
    }
    gridInputSelectedSubscribe(callback) {
        return this.current.subscribe(Events.GridInputSelected, callback);
    }
    gridDescriptionResizeSubscribe(callback) {
        return this.subscribeLocal(Events.GridDescriptionResize, callback);
    }
    gridLabelResizeSubscribe(callback) {
        return this.subscribeLocal(Events.GridLabelResize, callback);
    }
    gridFilterSubscribe(callback) {
        return this.subscribeLocal(Events.GridFilter, callback);
    }
    navigationSelectSubscribe(callback) {
        return this.subscribeLocal(Events.NavigationSelect, callback);
    }
    errorsLoadPublish() {
        this.current.publish(Events.ErrorsLoad);
    }
    featuresLoadedPublish() {
        this.current.publish(Events.FeaturesLoaded);
    }
    gridInputSelectedPublish(e) {
        this.current.publish(Events.FeaturesLoaded, e);
    }
    gridDescriptionResizePublish(e) {
        this.current.publish(Events.GridDescriptionResize, e);
    }
    gridLabelResizePublish(e) {
        this.current.publish(Events.GridLabelResize, e);
    }
    gridFilterPublish(e) {
        this.publishLocal(Events.GridFilter, e);
    }
    navigationSelectPublish(e) {
        this.publishLocal(Events.NavigationSelect, e);
    }
    static get(scope = "global") {
        let result = this.m_scopes[scope];
        if (result == undefined) {
            result = new EventsHub({ scope: scope });
            this.m_scopes[scope] = result;
        }
        return result;
    }
    subscribeLocal(eventName, callback) {
        return this.local.subscribe(eventName.replaceAll("{0}", this.scope), callback);
    }
    publishLocal(eventName, args) {
        this.local.publish(eventName.replaceAll("{0}", this.scope), args);
    }
}
EventsHub.m_scopes = {};
