import { ErrorModelCollectionEventType } from "../../Models/ErrorModelCollectionEvent.js";
let Jade = window["Jade"];
export class EditorBase extends Jade.UI.Control {
    constructor(options) {
        super(options);
    }
    get focusCallback() {
        return this.state.get("focus", () => { });
    }
    focus() {
        this.focusCallback();
    }
    onValidationErrors() {
    }
}
export class EditorBaseOf extends EditorBase {
    constructor(options) {
        super(options);
        this.m_source = options.source;
        this.state.unset("source", { silent: true });
        this.m_loadErrorsSubscription =
            this.source.root.errors.subscribe((e) => {
                this.onValidationErrors();
            }, ErrorModelCollectionEventType.load);
        this.m_clearErrorsSubscription =
            this.source.root.errors.subscribe((e) => {
                this.onValidationErrors();
            }, ErrorModelCollectionEventType.clear);
        this.onCreated();
    }
    get source() {
        return this.m_source;
    }
    get feature() {
        return this.source.feature;
    }
    get featureGroup() {
        return this.feature.parent;
    }
    get featureSet() {
        return this.featureGroup.parent;
    }
    get globals() {
        return this.source.root.context.globals;
    }
    get locals() {
        return this.featureGroup.locals;
    }
    onDestroy(e) {
        super.onDestroy(e);
        if (this.m_clearErrorsSubscription) {
            this.m_clearErrorsSubscription.unsubscribe();
        }
        if (this.m_loadErrorsSubscription) {
            this.m_loadErrorsSubscription.unsubscribe();
        }
    }
    onCreated() {
    }
    getPropertyName(name) {
        return _.camelCase(this.source.state.get(name));
    }
}
