<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 "./addPortPopup.js"
import PostForm from "@/components/form/PostForm.vue";
import TSelect from "@/components/ui/TSelect.vue";
import TOption from "@/components/ui/TOption.vue";
import TInputText from "@/components/ui/TInputText.vue";
import SubmitButton from "@/components/form/SubmitButton.vue";
import DefinitionTable from "@/components/common/DefinitionTable.vue";

const ctx = ctxRef(new Context())

</script>

<template>
	<PopupLayout>
		<header v-if="!ctx.isUpdating">添加端口绑定</header>
		<header v-if="ctx.isUpdating">修改端口绑定</header>
		<PostForm action="$" @success="ctx.success">
			<input type="hidden" name="minPort" :value="ctx.minPort"/>
			<input type="hidden" name="maxPort" :value="ctx.maxPort"/>
			<DefinitionTable>
				<tbody>
				<tr>
					<td>网络协议</td>
					<td>
						<TSelect name="protocol">
							<TOption v-for="protocol in ctx.protocols" :value="protocol.code">{{protocol.name}}</TOption>
						</TSelect>
					</td>
				</tr>
				<tr>
					<td class="title">端口 *</td>
					<td>
						<TInputText name="address" autofocus v-model="ctx.address" maxlength="5" style="width:5.2em"/>
						<p class="comment">需要在{{ctx.minPort}}-{{ctx.maxPort}}之间。<span v-if="ctx.serverType == 'tcpProxy'">TCP和TLS端口之间不能重复。</span></p>
					</td>
				</tr>
				</tbody>
			</DefinitionTable>
			<SubmitButton></SubmitButton>
		</PostForm>
	</PopupLayout>
</template>

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