<script setup>
// Copyright 2025 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 ServerSettingLayout from "@/layouts/ServerSettingLayout.vue";
import PostForm from "@/components/form/PostForm.vue";
import DefinitionTable from "@/components/common/DefinitionTable.vue";
import TCheckboxBinary from "@/components/ui/TCheckboxBinary.vue";
import SubmitButton from "@/components/form/SubmitButton.vue";
import ServerFeatureRequired from "@/components/server/ServerFeatureRequired.vue";

const ctx = ctxRef(new Context())

</script>

<template>
	<ServerSettingLayout :ctx="ctx">
		<div v-if="ctx.featureIsOn">
			<PostForm action="$" @success="ctx.success">
				<input type="hidden" name="serverId" :value="ctx.serverId"/>
				<input type="hidden" name="grpcJSON" :value="JSON.stringify(ctx.config)"/>
				<DefinitionTable>
					<tbody>
					<tr>
						<td>启用gRPC</td>
						<td>
							<TCheckboxBinary v-model="ctx.config.isOn"/>
							<p class="comment">选中后，表示启用当前网站的gRPC反向代理功能；在启用之前，请确保源站支持gRPC。不启用gRPC时当前网站会自动恢复为普通网站。</p>
						</td>
					</tr>
					</tbody>
				</DefinitionTable>
				<SubmitButton v-show="!ctx.isShared"></SubmitButton>
			</PostForm>
		</div>
		<div v-if="!ctx.featureIsOn">
			<ServerFeatureRequired></ServerFeatureRequired>
		</div>
	</ServerSettingLayout>
</template>

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