/// class PD.Web.UI.Controls.CommandButton
/// using PD.Web.UI.Controls.CommandItem

PD.Web.UI.Controls.CommandButton =
PD.Web.UI.Controls.CommandItem.extend({

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

    onClick: function (e) {
        this.executeCommand();
    },

    onCommandChange: function (e) {

        var image = e.icon,
            content = [
                image == null || this._showIcon() === false ? "" : "<img src='" + image + "' class='k-image'/>",
                this._showLabel() === true ? e.label : "&nbsp;"
            ];

        e.toolbar.enable(e.node, e.enabled);

        if (!Jade.String.isNullOrWhiteSpace(e.tooltip)) {

            Tipped.create(e.node, "<div style='font-size:13px;line-height:20px;'><b>" + e.label + "</b><br/>" + e.tooltip + "</div>", {
                skin: "white",
                showOn: "mouseenter",
                hideOn: "mouseleave",
                hideAfter: 200,
                hideDelay: 0,
                showDelay: 750,
                maxWidth: 300,
                position: "bottommiddle"
            });

        }

        e.node.empty();
        e.node.addClass("k-button-icontext");
        e.node.html(content.join(""));

    },

    //===================================
    // 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._getCssClass()
            }
        }

        return result;

    },

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

    _showIcon: function () {
        return this.data("display").indexOf("icon") !== -1;
    },

    _showLabel: function () {
        return this.data("text") !== ""
            && this.data("display").indexOf("label") !== -1
    },

    _setDefaultValues: function (e) {
        this.data().add("id", e.data || uuid.v4());
        this.data().add("overflow", e.overflow || "auto");
        this.data().add("type", "button");
        this.data().add("display", e.display || "icon label")
    },

    _getCssClass: function () {

        var result = undefined;

        if (!this._showLabel()) {
            result = "-pd-no-text";
        }

        return result;

    }

});