/// class PD.Manage.Modules.MailQueueDeleteCommand

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

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

    setDefaults: function () {

        this.props("id", "mail-queue-item/delete");
        this.props("enabled", false);
        this.props("icon", PD.Path.to16x16("delete.png"));
        this.props("label", "Delete");
        this.props("tooltip", "Delete the selected messages.");

        this.state("mailQueueItems", null);

    },

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

    isEnabled: function () {
        return _.isArray(this.state("mailQueueItems"))
            && this.state("mailQueueItems").length === 1;
    },

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

        var service = new PD.Manage.Services.MailQueueService(),
            mailQueueItem = _.first(this.state("mailQueueItems"));

        PD.Web.UI.MessageDialog.warn({
            title: "Delete Queued Message",
            message: "Delete the selected mail message?",
            ok: function (e) {

                e.close();

                service.deleteItem(mailQueueItem.id, function () {
                    PD.context.get_default().get_events().publish("mail-queue-item/delete", {
                        id: mailQueueItem.id
                    });
                });

            }
        });

    }

});