<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 "./updateTaskPopup.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 DomainsBox from "@/components/server/DomainsBox.vue";
import TCheckboxBinary from "@/components/ui/TCheckboxBinary.vue";
import SubmitButton from "@/components/form/SubmitButton.vue";
import DefinitionTable from "@/components/common/DefinitionTable.vue";

const ctx = ctxRef(new Context())

</script>

<template>
	<PopupLayout>
		<header>修改申请任务</header>
		<PostForm action="$" @success="ctx.success">
			<input type="hidden" name="taskId" :value="ctx.task.id"/>
			<input type="hidden" name="acmeUserId" :value="ctx.task.acmeUser.id"/>
			<input type="hidden" name="authType" :value="ctx.task.authType"/>

			<DefinitionTable>
				<tbody>
				<tr v-if="ctx.task.authType == 'dns'">
					<td class="title">选择DNS服务商 *</td>
					<td>
						<div v-if="ctx.providers.length > 0">
							<TSelect name="dnsProviderId" v-model="ctx.task.dnsProvider.id">
								<TOption value="0">[请选择]</TOption>
								<TOption v-for="provider in ctx.providers" :value="provider.id">{{provider.name}}（{{provider.typeName}}）</TOption>
							</TSelect>
						</div>
						<p class="comment">用于自动创建域名解析记录。</p>
					</td>
				</tr>
				<tr v-if="ctx.task.authType == 'dns'">
					<td>顶级域名 *</td>
					<td>
						<TInputText maxlength="100" name="dnsDomain" v-model="ctx.task.dnsDomain" class="w-full"/>
						<p class="comment">用于在DNS服务商账号中操作解析记录的域名，比如 example.com，不要输入二级或别的多级域名。</p>
					</td>
				</tr>
				<tr>
					<td>证书域名列表 *</td>
					<td>
						<DomainsBox name="domainsJSON" :v-domains="ctx.task.domains" :v-support-wildcard="ctx.task.authType == 'dns'"></DomainsBox>
						<p class="comment">需要申请的证书中包含的域名列表<span v-if="ctx.task.authType == 'dns'">，所有域名必须是同一个顶级域名</span><span v-if="ctx.task.authType == 'http'">使用HTTP认证方式时，域名中不能含有通配符</span>。</p>
					</td>
				</tr>
				<tr>
					<td>自动续期</td>
					<td>
						<TCheckboxBinary name="autoRenew" v-model="ctx.task.autoRenew"></TCheckboxBinary>
						<p class="comment">选中后，表示在免费证书临近到期之前尝试自动续期。</p>
					</td>
				</tr>
				</tbody>
			</DefinitionTable>

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

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