<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 PostForm from "@/components/form/PostForm.vue";
import TInputText from "@/components/ui/TInputText.vue";
import TSelect from "@/components/ui/TSelect.vue";
import TOption from "@/components/ui/TOption.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">
			<DefinitionTable>
				<tbody>
				<tr>
					<td>账号名称 *</td>
					<td>
						<TInputText name="name" maxlength="50" autofocus :tabindex="1" class="w-full"/>
					</td>
				</tr>
				<tr>
					<td class="title">证书服务商 *</td>
					<td>
						<TSelect name="providerCode" v-model="ctx.providerCode" @change="ctx.changeProvider" :tabindex="2">
							<TOption value="">[选择服务商]</TOption>
							<TOption v-for="provider in ctx.providers" :value="provider.code">{{provider.name}}</TOption>
						</TSelect>
						<p class="comment" v-if="ctx.selectedProvider != null" v-html="ctx.selectedProvider.description"></p>
					</td>
				</tr>
				</tbody>
				<tbody v-show="ctx.selectedProvider != null && ctx.selectedProvider.requireEAB">
				<tr>
					<td>EAB Kid *</td>
					<td>
						<TInputText name="eabKid" maxlength="100" :tabindex="3" class="w-full"/>
						<p class="comment" v-if="ctx.selectedProvider != null" v-html="ctx.selectedProvider.eabDescription"></p>
					</td>
				</tr>
				<tr>
					<td>EAB HMAC Key *</td>
					<td>
						<TInputText name="eabKey" maxlength="300" :tabindex="4" class="w-full"/>
					</td>
				</tr>
				</tbody>
			</DefinitionTable>
			<SubmitButton></SubmitButton>
		</PostForm>
	</PopupLayout>
</template>

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