/// class PD.Manage.Modules.GroupDeleteCommand

PD.Manage.Modules.GroupDeleteCommand =
PD.Commands.Command.extend({

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

    setDefaults: function () {
        this.props("id", "group/delete");
        this.props("enabled", true);
        this.props("icon", PD.Path.to16x16("delete.png"));
        this.props("label", "Delete");
        this.props("tooltip", "Delete the selected Group.");
        this.state("groups", null);
    },

    setState: function (state) {
        this._super(state);
        this.props("enabled", this._isEnabled());
    },

    execute: function (e) {
        this._super(e);

        var service = new PD.Manage.Services.GroupService(),
            group = _.first(this.state("groups"));

        this._showConfirmationDialog(group, (e) => {

            service.deleteGroup(group.id, (e) => {
                PD.context
                    .get_default()
                    .get_events()
                    .publish("group/delete", {
                        id: group.id
                    });
            });

        });

    },

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

    _isEnabled: function () {
        return _.isArray(this.state("groups"))
            && this.state("groups") != null;
    },

    _showConfirmationDialog: function (group, callback) {

        Jade.UI.MessageDialog.open({
            dialogStyle: Jade.UI.MessageDialogStyle.Warning,
            dialogButtons: Jade.UI.MessageDialogButtonStyle.OKCancel,
            allowClose: true,
            title: "Delete Group",
            message: "Delete the selected group?",
            select: (e) => {
                e.close();
                if (e.button === Jade.UI.MessageDialogButton.ok) {
                    callback();
                }
            }
        });

    }

});