<script setup>

import {ref} from "vue"
import PriorCheckbox from "@/components/common/PriorCheckbox.vue";
import ScriptConfigBox from "@/components/server/ScriptConfigBox.vue";
import DefinitionTable from "@/components/common/DefinitionTable.vue";

const props = defineProps(["v-group", "v-auditing-status", "v-is-location"])

const emits = defineEmits(["change"])

const {group, script} = (function () {
	let group = props.vGroup
	if (group == null) {
		group = {
			isPrior: false,
			isOn: true,
			scripts: []
		}
	}
	if (group.scripts == null) {
		group.scripts = []
	}

	let script = null
	if (group.scripts.length > 0) {
		script = group.scripts[group.scripts.length - 1]
	}

	return {
		group: ref(group),
		script: ref(script)
	}
})()

const changeScript = function (script) {
	group.value.scripts = [script] // 目前只支持单个脚本
	change()
}

const change = function () {
	emits("change", group.value)
}


</script>

<template>
	<div>
		<DefinitionTable v-if="vIsLocation">
			<PriorCheckbox :v-config="group" v-if="vIsLocation"></PriorCheckbox>
		</DefinitionTable>
		<div :style="{opacity: (!vIsLocation || group.isPrior) ? 1 : 0.5}">
			<ScriptConfigBox :v-script-config="script" :v-auditing-status="vAuditingStatus" comment="在接收到客户端请求之后立即调用。预置req、resp变量。" @change="changeScript" :v-is-location="vIsLocation"></ScriptConfigBox>
		</div>
	</div>
</template>

<style scoped>
</style>
