// Copyright (c) 2016, JINGROW
// For license information, please see license.txt

jingrow.ui.form.on("Email Queue", {
	refresh: function (frm) {
		if (["Not Sent", "Partially Sent"].includes(frm.pg.status)) {
			let button = frm.add_custom_button("Send Now", function () {
				jingrow.call({
					method: "jingrow.email.pagetype.email_queue.email_queue.send_now",
					args: {
						name: frm.pg.name,
					},
					btn: button,
					callback: function () {
						frm.reload_pg();
						if (cint(jingrow.sys_defaults.suspend_email_queue)) {
							jingrow.show_alert(
								__(
									"Email queue is currently suspended. Resume to automatically send emails."
								)
							);
						}
					},
				});
			});
		} else if (frm.pg.status == "Error") {
			frm.add_custom_button("Retry Sending", function () {
				frm.call({
					method: "retry_sending",
					pg: frm.pg,
					args: {
						name: frm.pg.name,
					},
					callback: function () {
						frm.reload_pg();
					},
				});
			});
		}
	},
});
