import ContextModel from "./ContextModel.js";
import Model from "../Data/Model.js";
import { default as EditorCollection } from "./EditorCollection.js";
import ErrorModelCollection from "./ErrorModelCollection.js";
export default class RootModel extends Model {
    constructor(options) {
        super(options);
        this.m_errors = new ErrorModelCollection();
        this.m_context = new ContextModel({
            root: this,
            parent: this,
            data: options.context,
        });
        this.m_editorCollection =
            new EditorCollection(options.editors);
        this.errors.load(options.errors);
    }
    get context() {
        return this.m_context;
    }
    get editors() {
        return this.m_editorCollection;
    }
    get initialized() {
        return this.state.get("initialized");
    }
    get initializers() {
        return this.state.get("initializers");
    }
    get errors() {
        return this.m_errors;
    }
    get postbackHandler() {
        return this.m_postbackHandlerFn || (() => { });
    }
    set postbackHandler(callback) {
        this.m_postbackHandlerFn = callback;
    }
    toJSON() {
        return {
            context: this.context.toJSON(),
            editors: this.editors.toJSON(),
            errors: this.errors.toJSON(),
            initialized: this.initialized,
            intializers: this.initializers
        };
    }
}
