/// class PD.Manage.Modules.MailQueueResendAllCommand

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

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

    setDefaults: function () {
        this.props("id", "mail-queue-item/resend-all");
        this.props("enabled", true);
        this.props("icon", PD.Path.to16x16("mail_forward.png"));
        this.props("label", "Resend All");
        this.props("tooltip", "Resend all messages in the queue.");
    },

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

        Jade.UI.MessageDialog.open({
            dialogStyle: Jade.UI.MessageDialogStyle.Warning,
            dialogButtons: Jade.UI.MessageDialogButtonStyle.OKCancel,
            allowClose: true,
            title: "Resend Queued Messages",
            message: "Resend all the queued messages in the queue?",
            select: (e) => {
                e.close();
                if (e.button === Jade.UI.MessageDialogButton.ok) {
                    this._executeResend();
                }
            }
        });

    },

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

    _executeResend: function () {

        var service = new PD.Manage.Services.MailQueueService();

        service.retryAll(() => {
            PD.context
                .get_default()
                .get_events()
                .publish("mail-queue-item/resend-all");
        });

    }

});