/// class PD.Manage.Modules.MailQueueResendCommand

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

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

    setDefaults: function () {

        this.props("id", "mail-queue-item/resend");
        this.props("enabled", false);
        this.props("icon", PD.Path.to16x16("mail_forward.png"));
        this.props("label", "Resend");
        this.props("tooltip", "Resend 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: "Resend Queued Message",
            message: "Resend the selected mail message?",
            ok: function (e) {

                e.close();

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

            }
        });

    }

});