<script setup>
import PopupLayout from "@/layouts/PopupLayout.vue";
import ctxRef from "@/utils/ctx_ref.js"
import Context from "./updateSetPopup.js"
import SubmitButton from "@/components/form/SubmitButton.vue";
import TCheckboxBinary from "@/components/ui/TCheckboxBinary.vue";
import HTTPHeaderReplaceValues from "@/components/server/HTTPHeaderReplaceValues.vue";
import DomainsBox from "@/components/server/DomainsBox.vue";
import HTTPMethodsBox from "@/components/server/HTTPMethodsBox.vue";
import MoreOptionsIndicator from "@/components/common/MoreOptionsIndicator.vue";
import HTTPStatusBox from "@/components/server/HTTPStatusBox.vue";
import TInputText from "@/components/ui/TInputText.vue";
import PostForm from "@/components/form/PostForm.vue";
import CodeLabel from "@/components/common/CodeLabel.vue";
import HTTPHeaderAssistant from "@/components/server/HTTPHeaderAssistant.vue";
import DefinitionTable from "@/components/common/DefinitionTable.vue";

const ctx = ctxRef(new Context())

</script>

<template>
	<PopupLayout>

		<header v-if="ctx.type == 'request'">修改自定义请求报头</header>
		<header v-if="ctx.type == 'response'">修改自定义响应报头</header>

		<PostForm action="$" @success="ctx.success">
			<input type="hidden" name="headerPolicyId" :value="ctx.headerPolicyId"/>
			<input type="hidden" name="headerId" :value="ctx.headerId"/>
			<input type="hidden" name="type" :value="ctx.type"/>
			<DefinitionTable>
				<tbody>
				<tr>
					<td class="title">报头名称<em>（Name）</em> *</td>
					<td>
						<TInputText type="text" name="name" value="" v-model="ctx.headerConfig.name" maxlength="200" placeholder="类似于Server、Content-Type之类" class="w-full" autofocus/>
						<p class="comment"><HTTPHeaderAssistant :v-type="ctx.type" :v-value="ctx.headerConfig.name" @select="ctx.selectHeader" class="my-1"></HTTPHeaderAssistant>请注意报头名称的大小写，如无特殊需求，报头名称的格式通常为<CodeLabel>Xxx</CodeLabel>或者<CodeLabel>Xxx-Yyy</CodeLabel>。</p>
					</td>
				</tr>
				<tr>
					<td>值<em>（Value）</em></td>
					<td>
						<TInputText type="text" name="value" v-model="ctx.headerConfig.value" maxlength="500" class="w-full"/>
						<p class="comment">可以包含请求变量。</p>
					</td>
				</tr>
				<tr>
					<td colspan="2"><MoreOptionsIndicator>更多选项</MoreOptionsIndicator></td>
				</tr>
				</tbody>
				<tbody v-show="ctx.moreOptionsVisible">
				<tr v-show="ctx.type == 'response'">
					<td>支持的状态码</td>
					<td>
						<HTTPStatusBox :v-status-list="ctx.statusList"></HTTPStatusBox>
						<p class="comment">不填表示支持所有的状态码。</p>
					</td>
				</tr>
				<tr>
					<td>支持的请求方法</td>
					<td><HTTPMethodsBox :v-methods="ctx.headerConfig.methods"></HTTPMethodsBox></td>
				</tr>
				<tr>
					<td>支持的域名</td>
					<td><DomainsBox :v-domains="ctx.headerConfig.domains"></DomainsBox></td>
				</tr>
				<tr>
					<td>只附加不替换</td>
					<td>
						<TCheckboxBinary name="shouldAppend" v-model="ctx.headerConfig.shouldAppend"></TCheckboxBinary>
						<p class="comment">选中后表示如果已经存在同名的报头，则只会附加在原有的报头之后，不会覆盖。</p>
					</td>
				</tr>
				<tr v-show="ctx.type == 'response'">
					<td>不在跳转时启用</td>
					<td>
						<TCheckboxBinary name="disableRedirect" v-model="ctx.headerConfig.disableRedirect"></TCheckboxBinary>
						<p class="comment">选中后表示在30X跳转时不启用当前报头。</p>
					</td>
				</tr>
				<tr>
					<td class="color-border">启用内容替换</td>
					<td>
						<TCheckboxBinary name="shouldReplace" v-model="ctx.shouldReplace"></TCheckboxBinary>
						<p class="comment">可以替换原有报头中的内容。</p>
					</td>
				</tr>
				<tr v-show="ctx.shouldReplace">
					<td class="color-border">替换内容</td>
					<td>
						<HTTPHeaderReplaceValues :v-replace-values="ctx.headerConfig.replaceValues"></HTTPHeaderReplaceValues>
					</td>
				</tr>
				</tbody>
			</DefinitionTable>
			<SubmitButton></SubmitButton>
		</PostForm>

	</PopupLayout>
</template>

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