/// class PD.Web.UI.Controls.Button
/// using PD.Web.UI.Controls.Item

PD.Web.UI.Controls.Button =
PD.Web.UI.Controls.Item.extend({

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

    _command: null,

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

    onPreInit: function (e) {
        this._super(e);
        this._assignCommand(e);
    },

    onClick: function (e) {

        switch (true) {
            case PD.Type.isFunction(this._command):
                this._command(e);
                break;
            case PD.Type.isObject(this._command):
                this._command.execute(e);
                break;
        }

    },

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

    getSettings: function () {

        var result = {
            type: "button",
            id: this.data("id"),
            enable: this.data("enable"),
            imageUrl: this.data("icon"),
            overflow: this.data("overflow"),
            text: this.data("text"),
            attributes: {
                "data-id": this.data("id"),
                "title": this.data("tooltip"),
                "class": (this.data("text") === "" ? "-pd-no-text" : "")
            }
        }

        return result;

    },

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

    _setDefaultValues: function (e) {
        this.data().add("icon", e.icon || null);
        this.data().add("id", e.data || uuid.v4());
        this.data().add("enable", e.enable != null ? e.enable : true);
        this.data().add("overflow", e.overflow || "auto");
        this.data().add("text", e.text || "");
        this.data().add("type", "button");
    },

    _assignCommand: function (e) {

        var paramIsFunction = PD.Type.isFunction(e),
            paramIsObjectWithCommand = PD.Type.isObject(e) && PD.Type.isFunction(e.command),
            paramIsCommandObject = PD.Type.isObject(e) && PD.Type.isFunction(e.execute);

        switch (true) {
            case paramIsFunction || paramIsCommandObject:
                this._command = e;
                break;
            case paramIsObjectWithCommand:
                this._command = e.command;
                break;
        }

    }

});