import initCtx from "@/utils/ctx.js";

export default function () {
	const {utils, Tea} = initCtx(this)

	// 启用
	this.enableGroup = function (groupId) {
		this.$post("/servers/components/waf/updateGroupOn")
			.params({
				groupId: groupId,
				isOn: 1
			})
			.refresh()

	}

	// 停用
	this.disableGroup = function (groupId) {
		this.$post("/servers/components/waf/updateGroupOn")
			.params({
				groupId: groupId,
				isOn: 0
			})
			.refresh()
	}

	// 删除
	this.deleteGroup = function (groupId) {
		utils.confirm("确定要删除此规则分组吗？", function () {
			this.$post("/servers/components/waf/deleteGroup")
				.params({
					firewallPolicyId: this.firewallPolicyId,
					groupId: groupId
				})
				.refresh()
		})
	}

	// 添加分组
	this.createGroup = function (type) {
		utils.popup("/servers/components/waf/createGroupPopup?firewallPolicyId=" + this.firewallPolicyId + "&type=" + type, {
			callback: function () {
				utils.success("保存成功", function () {
					utils.reload()
				})
			}
		})
	}

	this.sortTable = function (groupIds) {
		this.$post("/servers/components/waf/sortGroups")
			.params({
				firewallPolicyId: this.firewallPolicyId,
				type: this.type,
				groupIds: groupIds
			})
			.success(function () {
				utils.successToast("排序保存成功")
			})
	}
}