jingrow.listview_settings["Local Job"] = {
	hide_name_column: true,

	onload(listview) {
		if (!has_common(jingrow.user_roles, ["Administrator", "System Manager"])) return;

		listview.page.add_inner_button(
			__("Remove Failed Jobs"),
			() => {
				jingrow.confirm(__("Are you sure you want to remove all failed jobs?"), () => {
					jingrow.xcall("jingrow.core.pagetype.local_job.local_job.remove_failed_jobs");
				});
			},
			__("Actions")
		);

		jingrow.xcall("jingrow.utils.scheduler.get_scheduler_status").then(({ status }) => {
			if (status === "active") {
				listview.page.set_indicator(__("Scheduler: Active"), "green");
			} else {
				listview.page.set_indicator(__("Scheduler: Inactive"), "red");
				listview.page.add_inner_button(
					__("Enable Scheduler"),
					() => {
						jingrow.confirm(__("Are you sure you want to re-enable scheduler?"), () => {
							jingrow
								.xcall("jingrow.utils.scheduler.activate_scheduler")
								.then(() => {
									jingrow.show_alert(__("Enabled Scheduler"));
								})
								.catch((e) => {
									jingrow.show_alert({
										message: __("Failed to enable scheduler: {0}", e),
										indicator: "error",
									});
								});
						});
					},
					__("Actions")
				);
			}
		});

		setInterval(() => {
			if (listview.list_view_settings.disable_auto_refresh) {
				return;
			}

			const route = jingrow.get_route() || [];
			if (route[0] != "List" || "Local Job" != route[1]) {
				return;
			}

			listview.refresh();
		}, 15000);
	},
};
