<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 "./updatePopup.js"
import SubmitButton from "@/components/form/SubmitButton.vue";
import TCheckboxBinary from "@/components/ui/TCheckboxBinary.vue";
import MoreOptionsIndicator from "@/components/common/MoreOptionsIndicator.vue";
import NSRouteRangesBox from "@/components/ns/NSRouteRangesBox.vue";
import {ref} from "vue";
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 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="routeId" :value="ctx.route.id"/>
			<DefinitionTable>
				<tbody>
				<tr>
					<td class="title">线路名称 *</td>
					<td>
						<TInputText name="name" maxlength="100" autofocus v-model="ctx.route.name" 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" :v-ranges="ctx.route.ranges"></NSRouteRangesBox>
					</td>
				</tr>
				<tr>
					<td colspan="2"><MoreOptionsIndicator></MoreOptionsIndicator></td>
				</tr>
				</tbody>
				<tbody v-show="ctx.moreOptionsVisible">
				<tr>
					<td>启用当前线路</td>
					<td>
						<TCheckboxBinary name="isOn" value="1" v-model="ctx.route.isOn"></TCheckboxBinary>
					</td>
				</tr>
				</tbody>
			</DefinitionTable>

			<SubmitButton></SubmitButton>
		</PostForm>
	</PopupLayout>
</template>

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