<script setup>
// Copyright 2024 FlexCDN root@flexcdn.cn. All rights reserved. Official site: https://flexcdn.cn .

import PopupLayout from "@/layouts/PopupLayout.vue";
import ctxRef from "@/utils/ctx_ref.js"
import Context from "./updateObjectsPopup.js"
import SubmitButton from "@/components/form/SubmitButton.vue";
import ADInstanceObjectsBox from "@/components/anti-ddos/ADInstanceObjectsBox.vue";
import PostForm from "@/components/form/PostForm.vue";
import DefinitionTable from "@/components/common/DefinitionTable.vue";

const ctx = ctxRef(new Context())

</script>

<template>
	<PopupLayout>

		<header>设置防护对象</header>

		<PostForm action="$" @success="ctx.success">
			<input type="hidden" name="userInstanceId" :value="ctx.userInstance.id"/>

			<DefinitionTable>
				<tbody>
				<tr>
					<td class="title">高防产品</td>
					<td>
						<div v-if="ctx.userInstance.package.id > 0">{{ctx.userInstance.package.summary}}</div>
						<span v-else class="red">已删除</span>
					</td>
				</tr>
				<tr>
					<td>高防IP</td>
					<td>
						<div v-if="ctx.userInstance.instance.id > 0">
							<div v-for="ip in ctx.userInstance.instance.ipAddresses">{{ip}}</div>
						</div>
						<span v-else class="red">已删除</span>
					</td>
				</tr>
				<tr>
					<td>防护对象</td>
					<td>
						<div v-if="ctx.userInstance.isAvailable && ctx.userInstance.user.id > 0">
							<ADInstanceObjectsBox :v-objects="ctx.userInstance.objects" :v-user-id="ctx.userInstance.user.id"></ADInstanceObjectsBox>
						</div>
						<span v-else class="red">实例已经失效，无法设置防护对象</span>
					</td>
				</tr>
				</tbody>
			</DefinitionTable>

			<SubmitButton v-show="ctx.userInstance.isAvailable && ctx.userInstance.user.id > 0"></SubmitButton>
		</PostForm>
	</PopupLayout>
</template>

<style lang="postcss" scoped>
</style>