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

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

	this.createAccessKey = function () {
		utils.popup("/acl/accesskeys/createPopup", {
			callback: function () {
				utils.success("保存成功", function () {
					utils.reload()
				})
			}
		})
	}

	this.updateAccessKeyIsOn = function (accessKeyId, isOn) {
		let that = this

		let message = ""
		if (isOn) {
			message = "确定要启用此AccessKey吗？"
		} else {
			message = "确定要禁用此AccessKey吗？"
		}
		utils.confirm(message, function () {
			that.$post(".updateIsOn")
				.params({
					accessKeyId: accessKeyId,
					isOn: isOn ? 1 : 0
				})
				.refresh()
		})
	}

	this.deleteAccessKey = function (accessKeyId) {
		let that = this
		utils.confirm("确定要删除此AccessKey吗？", function () {
			that.$post(".delete")
				.params({
					accessKeyId: accessKeyId
				})
				.refresh()
		})
	}
}