// Copyright (c) 2022, JINGROW
// For license information, please see license.txt
/* eslint-disable */

jingrow.query_reports['MariaDB Process List'] = {
	onload: function (report) {
		report.page.add_button(__('Kill Processes'), () => {
			const dialog = new jingrow.ui.Dialog({
				title: __('Kill Processes'),
				fields: [
					{
						fieldtype: 'Int',
						default: 120,
						label: __('Kill Processes Running Longer Than (Seconds)'),
						fieldname: 'kill_threshold',
					},
				],
			});

			dialog.set_primary_action(__('Kill Processes'), (args) => {
				jingrow
					.call(
						'jcloud.jcloud.report.mariadb_process_list.mariadb_process_list.kill',
						{
							database_server:
								jingrow.query_report.get_filter_value('database_server'),
							kill_threshold: args.kill_threshold,
						},
					)
					.then((r) => {
						dialog.hide();
						jingrow.query_report.refresh();
					});
			});
			dialog.show();
		});
	},
};
