import { default as BaseModel } from "./BaseModel.js";
import FeatureModel from "./FeatureModel.js";
import { GroupEnvironment } from "../Environment/GroupEnvironment.js";
export default class GroupModel extends BaseModel {
    constructor(options) {
        super(options);
        this.m_index = null;
        this.m_features = [];
        this.m_parent = options.parent;
        this.state.unset("parent");
        options.data.features.forEach(feature => {
            this.m_features[this.m_features.length] =
                new FeatureModel({
                    data: feature,
                    parent: this,
                    root: this.root
                });
        });
        this.m_environment = new GroupEnvironment({
            parent: this
        });
    }
    get locals() {
        return this.m_environment;
    }
    get globals() {
        return this.parent.parent.parent.context.globals;
    }
    get isMicro() {
        return this.assembler ==
            "ProspectDirector.Web.UI.FeatureSets.MicroEditorAssembler";
    }
    get assembler() {
        return this.state.get("assembler");
    }
    get features() {
        return this.m_features;
    }
    get id() {
        return this.state.get("id");
    }
    get name() {
        return this.state.get("name");
    }
    get parent() {
        return this.m_parent;
    }
    get index() {
        if (this.m_index === null) {
            this.m_index = this.getIndex();
        }
        return this.m_index;
    }
    get errors() {
        return this.root.errors.getByGroup(this.index);
    }
    getEditors() {
        return this.root.editors.getEditorsByGroup(this);
    }
    toJSON() {
        return {
            features: this.features.map(feature => {
                return feature.toJSON();
            }),
            id: this.id,
            name: this.name,
            assembler: this.assembler
        };
    }
    getIndex() {
        let result = null;
        this.parent.groups.some((group, index) => {
            if (group.id === this.id) {
                result = index;
                return true;
            }
        });
        return result;
    }
}
