<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 "./createPopup.js"
import TInputText from "@/components/ui/TInputText.vue";
import TSelect from "@/components/ui/TSelect.vue";
import TOption from "@/components/ui/TOption.vue";
import PostForm from "@/components/form/PostForm.vue";
import SubmitButton from "@/components/form/SubmitButton.vue";
import NSRouteRangesBox from "@/components/ns/NSRouteRangesBox.vue";
import {ref} from "vue";
import TMessage from "@/components/ui/TMessage.vue";
import DefinitionTable from "@/components/common/DefinitionTable.vue";

const routeRangesBox = ref()
const ctx = ctxRef(new Context(), {
	refs: {routeRangesBox}
})

</script>

<template>
	<PopupLayout>
		<header>创建线路</header>
		<PostForm action="$" @success="ctx.success">
			<input type="hidden" name="clusterId" :value="ctx.clusterId"/>
			<input type="hidden" name="domainId" :value="ctx.domainId"/>
			<input type="hidden" name="userId" :value="ctx.userId"/>

			<DefinitionTable>
				<tbody>
				<tr>
					<td class="title">线路名称 *</td>
					<td>
						<TInputText name="name" maxlength="100" autofocus class="w-full"/>
					</td>
				</tr>
				<tr>
					<td>范围类型</td>
					<td>
						<TSelect v-model="ctx.rangeTypeCode" @change="ctx.changeRangeType">
							<TOption v-for="rangeType in ctx.rangeTypes" :value="rangeType.code">{{ rangeType.name }}</TOption>
						</TSelect>
					</td>
				</tr>
				<tr>
					<td></td>
					<td>
						<NSRouteRangesBox ref="routeRangesBox"></NSRouteRangesBox>
					</td>
				</tr>
				</tbody>
			</DefinitionTable>

			<SubmitButton v-if="ctx.quotaCanCreate"></SubmitButton>
			<TMessage error="" v-if="!ctx.quotaCanCreate">已添加线路个数已超出最大限额（{{ ctx.quotaMaxCustomRoutes }}个线路），请升级套餐后重试。</TMessage>
		</PostForm>
	</PopupLayout>
</template>

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