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

jingrow.ui.form.on('Virtual Machine Replacement', {
	refresh(frm) {
		[
			[__('Start'), 'execute', frm.pg.status === 'Pending'],
			[__('Force Continue'), 'force_continue', frm.pg.status === 'Failure'],
			[__('Force Continue'), 'force_continue', frm.pg.status === 'Failure'],
			[__('Force Fail'), 'force_fail', frm.pg.status === 'Running'],
		].forEach(([label, method, condition]) => {
			if (condition) {
				frm.add_custom_button(
					label,
					() => {
						jingrow.confirm(
							`Are you sure you want to ${label.toLowerCase()}?`,
							() => frm.call(method).then(() => frm.refresh()),
						);
					},
					__('Actions'),
				);
			}
		});
	},
});
