<script setup>
// Copyright 2024 FlexCDN root@flexcdn.cn. All rights reserved. Official site: https://flexcdn.cn .

import ctxRef from "@/utils/ctx_ref.js"
import Context from "./index.js"
import Menu from "../@menu.vue"
import Pager from "@/components/common/Pager.vue";
import TColumn from "@/components/ui/TColumn.vue";
import ListTable from "@/components/common/ListTable.vue";
import NotFoundInfo from "@/components/common/NotFoundInfo.vue";
import NavButtons from "@/components/common/NavButtons.vue";
import NavButton from "@/components/common/NavButton.vue";

const ctx = ctxRef(new Context())

</script>

<template>
	<Menu></Menu>

	<NavButtons>
		<NavButton @click.prevent="ctx.createAccount" action-create>创建账号</NavButton>
	</NavButtons>

	<NotFoundInfo v-if="ctx.accounts.length == 0">暂时还没有服务商账号。</NotFoundInfo>

	<div v-if="ctx.accounts.length > 0">
		<ListTable :items="ctx.accounts">
			<TColumn header="名称" class="name-column" frozen>
				<template #body="{data: account}">
					<a href="" @click.prevent="ctx.updateAccount(account.id)">{{ account.name }}
						<i class="icon expand small"></i></a>
				</template>
			</TColumn>
			<TColumn header="服务商" class="name-column">
				<template #body="{data: account}">
					<span v-if="account.provider != null">{{ account.provider.name }}</span>
				</template>
			</TColumn>
			<TColumn header="EAB Kid" class="description-column">
				<template #body="{data: account}">
					<span v-if="account.eabKid.length > 0">{{ account.eabKid }}</span>
					<span v-else class="disabled">-</span>
				</template>
			</TColumn>
			<TColumn header="EBA HMAC Key" class="description-column">
				<template #body="{data: account}">
					<span v-if="account.eabKey.length > 0">{{ account.eabKey }}</span>
					<span v-else class="disabled">-</span>
				</template>
			</TColumn>
			<TColumn header="操作" class="two op" frozen align-frozen="right">
				<template #body="{data: account}">
					<a href="" @click.prevent="ctx.updateAccount(account.id)">修改</a> &nbsp;
					<a href="" @click.prevent="ctx.deleteAccount(account.id)">删除</a>
				</template>
			</TColumn>
		</ListTable>
	</div>

	<Pager :data="ctx.page"></Pager>
</template>

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