<script setup>
import PopupLayout from "@/layouts/PopupLayout.vue";
import ctxRef from "@/utils/ctx_ref.js";
import Context from "./createIPPopup.js"
import SubmitButton from "@/components/form/SubmitButton.vue";
import TInputText from "@/components/ui/TInputText.vue";
import PostForm from "@/components/form/PostForm.vue";
import DatetimeInput from "@/components/common/DatetimeInput.vue";
import MoreOptionsIndicator from "@/components/common/MoreOptionsIndicator.vue";
import DefinitionTable from "@/components/common/DefinitionTable.vue";

const ctx = ctxRef(new Context())

</script>

<template>
	<PopupLayout>
		<header v-if="ctx.type == 'white'">添加IP到白名单</header>
		<header v-if="ctx.type == 'black'">添加IP到黑名单</header>
		<header v-if="ctx.type == 'grey'">添加IP到灰名单</header>

		<PostForm action="$" @success="ctx.success">
			<input type="hidden" name="listId" :value="ctx.listId"/>
			<DefinitionTable>
				<tbody>
				<tr>
					<td>IP或IP段 *</td>
					<td>
						<TInputText type="text" name="value" maxlength="64" placeholder="x.x.x.x" autofocus class="w-full"/>
						<p class="comment">支持IPv4和IPv6；支持三种格式：单个IP（比如192.168.1.100）、IP范围（比如192.168.1.1-192.168.1.255）、CIDR（比如192.168.1.1/24）。</p>
					</td>
				</tr>
				<tr>
					<td class="title">过期时间</td>
					<td>
						<DatetimeInput :v-name="'expiredAt'"></DatetimeInput>
						<p class="comment">在加入名单某一段时间后会失效，留空表示永久有效。</p>
					</td>
				</tr>
				<tr>
					<td colspan="2">
						<MoreOptionsIndicator></MoreOptionsIndicator>
					</td>
				</tr>
				</tbody>
				<tbody v-show="ctx.moreOptionsVisible">
				<tr>
					<td>备注</td>
					<td>
						<TInputText type="text" name="reason" maxlength="100" class="w-full"/>
					</td>
				</tr>
				</tbody>
			</DefinitionTable>
			<p class="comment">添加后将会在5分钟后生效。</p>
			<SubmitButton></SubmitButton>
		</PostForm>
	</PopupLayout>
</template>

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