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

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

    //===================================
    // EVENT HANDLERS
    //===================================

    _onDataBound: function () {
        this.get_grid().clearMessage();
        this._noRecordsCheck();
        this._noColumnsCheck();
    },

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

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

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

    start: function () {
    
        this.get_kendo().bind(
            "dataBound",
            $.proxy(this._onDataBound, this));

    },

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

    _noColumnsCheck: function () {

        var columnsArray = this.get_configuration().get_instance().columns; 
        var columnCount = columnsArray == null ? 1 : columnsArray.length;

        if (columnCount === 1) {
            this.get_grid().addMessage("Click to add columns", this._showColumnDesignDialog);
        };

    },

    _noRecordsCheck: function () {

        var recordCount = this.get_dataSource().get_instance().total();
        var message = this.get_grid().getOption("messaging.noRecordsMessage") || "No records found";

        this.get_grid().clearMessage();

        if (recordCount === 0) {
            this.get_grid().addMessage(message);
        };

    },

    _showColumnDesignDialog: function () {

        PDJS.Shared.Views.ColumnsDialog.open({
            viewStateId: this.get_grid().get_viewStateId(),
            componentType: PDJS.Shared.Views.ViewComponentType.Design,
            callbacks: {
                ok: () => {
                    this.get_grid().build();
                }
            }
        });

    }

});