/// class ProspectDirector.Web.UI.FeatureSets.Layouts.Layout

/**
@class Layout
@namespace Web.UI.FeatureSets.Layout
@constructor
**/
ProspectDirector.Web.UI.FeatureSets.Layouts.Layout = Class.extend({

    //================================
    // FIELDS
    //================================

    _options: null,
    _featureSet: null,
    _assemblers: null,
    _DOM: null,

    //================================
    // CONSTRUCTOR
    //================================

    init: function (options) {
        this._options = options;
        this._featureSet = options.featureSet;
        this._assemblers = new ProspectDirector.Web.List();
        this._init_assemblers();

    },

    //================================
    // PROPERTIES
    //================================

    get_options: function () {
        return this._options;
    },

    get_parent: function () {
        return this.get_options().parent;
    },

    get_eventBus: function () {
        return this.get_options().eventBus;
    },

    get_featureSet: function () {
        return this._featureSet;
    },

    get_assemblers: function () {
        return this._assemblers;
    },

    //================================
    // INITIALIZERS
    //================================

    _init_assemblers: function () {

        var that = this,
            assemblerType = null;

        this.get_featureSet().get_groups().each(function (index, group) {

            assemblerType = ProspectDirector.RUNTIME.type(group.get_assembler());

            if (assemblerType) {

                that.get_assemblers().add(new assemblerType({
                    containerId: that.get_options().containerId,
                    featureSet: that.get_featureSet(),
                    groupId: group.get_id(),
                    eventBus: that.get_eventBus()
                }));

            }

        });

    },

    //================================
    // PUBLIC METHODS
    //================================

    DOM: function () {

        if (!this._DOM) {
            this._DOM = new ProspectDirector.Web.UI.FeatureSets.Layouts.LayoutDOM({
                containerID: this.get_options().containerId
            });
        }

        return this._DOM;

    },

    resize: function (e) {
        this.DOM().resize();
    },

    render: function () {

    },

    activate: function () {

    },

    destroy: function () {
        this.DOM().clear();
    },

    reload: function (featureSet) {
        this._featureSet = featureSet;
        this.get_assemblers().clear();
        this._init_assemblers();
    },

    getAssemblerByGroupId: function (groupId) {

        var result = null;

        this.get_assemblers().each(function (index, assembler) {
            if (assembler.get_groupId() === groupId) {
                result = assembler;
                return false;
            }
        });

        return result;

    },

    getSelectedGroupId: function () {
        return this._groupId;
    }

}); 