<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 TCheckboxBinary from "@/components/ui/TCheckboxBinary.vue";
import MoreOptionsIndicator from "@/components/common/MoreOptionsIndicator.vue";
import PostForm from "@/components/form/PostForm.vue";
import TTextarea from "@/components/ui/TTextarea.vue";
import SubmitButton from "@/components/form/SubmitButton.vue";
import DefinitionTable from "@/components/common/DefinitionTable.vue";

const ctx = ctxRef(new Context())

</script>

<template>
	<PopupLayout>
		<PostForm action="$" @success="ctx.success">
			<DefinitionTable>
				<tbody>
				<tr>
					<td class="title">策略名称 *</td>
					<td>
						<TInputText name="name" maxlength="100" autofocus class="w-full"/>
						<p class="comment">给策略起一个容易识别的名字。</p>
					</td>
				</tr>
				<tr>
					<td>启用预置的规则</td>
					<td>
						<div class="grid grid-cols-2 gap-2">
							<div v-for="group in ctx.groups">
								<TCheckboxBinary name="groupCodes" :value="group.code" v-model="group.isOn">
									<span>{{ group.name }}</span>
								</TCheckboxBinary>
							</div>
						</div>
						<p class="comment">可以启用一些我们预置的规则组。</p>
					</td>
				</tr>
				<tr>
					<td colspan="2">
						<MoreOptionsIndicator></MoreOptionsIndicator>
					</td>
				</tr>
				</tbody>
				<tbody v-show="ctx.moreOptionsVisible">
				<tr>
					<td>描述</td>
					<td>
						<TTextarea name="description" rows="3" class="w-full"></TTextarea>
					</td>
				</tr>
				<tr>
					<td>启用当前分组</td>
					<td>
						<TCheckboxBinary name="isOn" value="1" checked="checked"/>
					</td>
				</tr>
				</tbody>
			</DefinitionTable>
			<SubmitButton></SubmitButton>
		</PostForm>
	</PopupLayout>
</template>

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