<template>
	<p v-if="isKilled">进程已终止</p>
	<Button
		v-else
		@click="killProcess"
		:loading="this.$resources.killProcess.loading"
		loadingText="正在终止"
		iconLeft="x"
		variant="ghost"
		class="w-full"
		>终止</Button
	>
</template>
<script>
import { toast } from 'vue-sonner';
export default {
	props: {
		row: { type: Object, required: true },
		site: { type: String, required: true },
	},
	data() {
		return {
			isKilled: false,
		};
	},
	resources: {
		killProcess() {
			return {
				url: 'jcloud.api.client.run_pg_method',
				initialData: {},
				makeParams: () => {
					return {
						dt: 'Site',
						dn: this.site,
						method: 'kill_database_process',
						args: {
							id: this.row.ID,
						},
					};
				},
				onSuccess: (data) => {
					this.isKilled = true;
					toast.success('数据库进程已终止');
				},
				auto: false,
			};
		},
	},
	methods: {
		killProcess() {
			this.$resources.killProcess.submit();
		},
	},
};
</script>