/// class PD.Web.UI.Controls.GridHeaderModule
/// using PD.Web.UI.Controls.GridModule

PD.Web.UI.Controls.GridHeaderModule =
PD.Web.UI.Controls.GridModule.extend({

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

    _widgetArea: null,

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

    get_header: function () {
        return this.get_kendo().element.find(".k-grid-toolbar");
    },

    //===================================
    // PROTECTED METHODS
    //===================================

    getOptionSettings: function () {

        var result = {},
            showToolbar = this.getOption("showToolbar", false),
            settings = this.getOption("toolbar", []);

        if (showToolbar === true) {
            result = {
                toolbar: settings
            };
        }

        return result;

    },

    start: function () {
        this._initHeader();
        this._initWidgetArea();
        this.addGridMethod("addHeaderWidget", $.proxy(this._addWidget, this));
    },

    ready: function () {
        this._widgetArea.autoAdjustDockSizes();
    },

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

    _initHeader: function () {

        this.get_header().css({
            height: 32,
            position: "relative"
        });

    },

    _initWidgetArea: function () {
        this._widgetArea = new PD.Web.UI.Controls.GridWidgetArea({
            insertAt: ".k-grid-toolbar"
        });
        this.get_grid().get_children().add(this._widgetArea);
    },

    _addWidget: function (widget) {
        this._widgetArea.addWidget(widget);
    }

});