<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 PostForm from "@/components/form/PostForm.vue";
import TSelect from "@/components/ui/TSelect.vue";
import TOption from "@/components/ui/TOption.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>
		<header>创建用户</header>
		<PostForm @success="ctx.success" action="$">
			<DefinitionTable>
				<tbody>
				<tr>
					<td class="title">用户邮箱 *</td>
					<td>
						<TInputText name="email" maxlength="100" autofocus class="w-full"/>
						<p class="comment">用于自动注册用户的邮箱。</p>
					</td>
				</tr>
				<tr>
					<td>所属证书服务商 *</td>
					<td>
						<TSelect name="providerCode" v-model="ctx.providerCode" @change="ctx.changeProvider">
							<TOption value="">[选择服务商]</TOption>
							<TOption v-for="provider in ctx.providers" :value="provider.code">{{provider.name}}</TOption>
						</TSelect>
					</td>
				</tr>
				<tr v-if="ctx.selectedProvider != null">
					<td>所属服务商账号 <span v-if="ctx.selectedProvider.requireEAB">*</span><em v-else>（可选）</em></td>
					<td>
						<div class="ui fields inline">
							<div class="ui field" v-if="ctx.accounts.length > 0">
								<TSelect name="accountId" v-model="ctx.accountId">
									<TOption value="0">[选择账号]</TOption>
									<TOption v-for="account in ctx.accounts" :value="account.id">{{account.name}}</TOption>
								</TSelect>
							</div>
							<div class="ui field">
								<a href="" @click.prevent="ctx.addAccount">[添加]</a>
							</div>
						</div>
					</td>
				</tr>
				<tr>
					<td>备注</td>
					<td>
						<TTextarea name="description" rows="3" maxlength="100" class="w-full"></TTextarea>
					</td>
				</tr>
				</tbody>
			</DefinitionTable>
			<SubmitButton></SubmitButton>
		</PostForm>
	</PopupLayout>
</template>

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