/// class ProspectDirector.Web.UI.Queries.ConstraintsEditorToolBar
/// using ProspectDirector.Web.UI.Controls.ToolBar

ProspectDirector.Web.UI.Queries.ConstraintsEditorToolBar = ProspectDirector.Web.UI.Controls.ToolBar.extend({

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

    _selectedConstraint: null,

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

    init: function (options) {
        this._super(options);
        this.load(this.get_options().selection);
    },

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

    get_selectedConstraint: function () {
        return this._selectedConstraint;
    },

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

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

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

    load: function (data) {

        var role = data ? data.get_role() : null,
            buttons = [];

        this._selectedConstraint = data;

        buttons = this._getButtons(role);

        this.clear();

        this.get_items().add({
            type: "group",
            items: buttons
        });

        this.render();

    },

    //================================
    // PRIVATE METHODS
    //================================

    _getButtons: function (role) {

        var buttons = new ProspectDirector.Web.List();
        var commands = new ProspectDirector.Web.UI.Queries.ConstraintCommands({
            editor: this.get_editor(),
            selectedConstraint: this.get_selectedConstraint(),
            featureSet: this.get_featureSet()
        });

        buttons.add({
            toolTip: "Add Group",
            icon: "ADD.PNG",
            command: commands.addCondition
        });

        buttons.add({
            toolTip: "Add Filter",
            icon: "FUNNEL_ADD.PNG",
            command: commands.addFilter
        });

        buttons.add({
            toolTip: "Edit",
            icon: "PENCIL.PNG",
            command: commands.editFilter,
            disabled: role !== "filter"
        });

        buttons.add({
            toolTip: "Duplicate",
            icon: "COPY.PNG",
            command: commands.duplicateFilter,
            disabled: role !== "filter"
        });

        buttons.add({
            toolTip: "Remove",
            icon: "DELETE.PNG",
            command: commands.remove,
            disabled: role == null
        });

        buttons.add({
            toolTip: "Remove All",
            icon: "ERASER.PNG",
            command: commands.clear
        });

        return buttons.toArray();

    }

});
