/// class PD.Web.UI.Controls.GridConfiguration

PD.Web.UI.Controls.GridConfiguration =
Class.extend({

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

    _grid: null,
    _configuration: null,
    
    //===================================
    // CONSTRUCTORS
    //==================================

    init: function (options) {
        this._options = $.extend({}, options);
        this._configuration = {};
    },

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

    get_instance: function () {
        return this._configuration;
    },

    get_columns: function () {
        return this._configuration.columns;
    },

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

    get_grid: function () {
        return this._grid;
    },

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

    execute: function (grid, onReadyCallback) {

        var that = this;

        this._grid = grid;

        this.getConfiguration(function (configuration) {
            that._configuration = configuration;
            that.ready(configuration);
            grid.get_options()["columns"] = configuration.columns;
            if (PD.Type.isFunction(onReadyCallback)) {
                $.proxy(onReadyCallback, grid)(that);
            }

        });

    },

    toJSON: function () {
        return this._configuration;
    },

    //===================================
    // OVERRIDABLE METHODS
    //==================================

    getConfiguration: function (onComplete) {
        onComplete({
            columns: this.get_grid().getOption("columns", [])
        });
    },

    ready: function (configuration) {
       
        var columns = new PD.BCL.List(configuration.columns),
            transformedColumns = new PD.BCL.List();

        columns.each(function (index, column) {
            if (PD.Type.isObject(column.properties)) {
                transformedColumns.add(column.properties().getAll());
            }
        });

        configuration.columns = transformedColumns.toArray();

    }

});