{$layout}
{$template "menu"}

<div class="margin"></div>

<form method="post" class="ui form" data-tea-action="$" data-tea-success="success">
	<table class="ui table selectable definition">
		<tr>
			<td class="title">服务名称 *</td>
			<td>
				<input type="text" name="name" maxlength="60" ref="focus"/>
			</td>
		</tr>
		<tr>
			<td>部署的集群 *</td>
			<td>
				<select class="ui dropdown auto-width" name="clusterId">
					<option v-for="cluster in clusters" :value="cluster.id">{{cluster.name}}</option>
				</select>
                <p class="comment">当前服务将会部署到所选集群的节点上。</p>
			</td>
		</tr>
		<tr>
			<td>服务类型 *</td>
			<td>
				<select class="ui dropdown auto-width" name="serverType" v-model="serverType" @change="changeServerType()">
					<option v-for="s in serverTypes" :value="s.code">{{s.name}}</option>
				</select>
                <p class="comment" v-for="s in serverTypes" v-if="s.code == serverType">{{s.description}}</p>
			</td>
		</tr>
		<tr>
			<td>绑定端口 *</td>
			<td>
				<network-addresses-box :v-server-type="serverType" :v-addresses="defaultAddresses"></network-addresses-box>
			</td>
		</tr>

		<!-- 域名 -->
		<tr v-if="serverType == 'httpProxy' || serverType == 'httpWeb'">
			<td>绑定域名</td>
			<td>
				<server-name-box></server-name-box>
                <p class="comment">绑定后，才能通过域名可以访问不同的服务。</p>
			</td>
		</tr>

        <!-- 证书 -->
        <tbody v-if="tlsProtocolName.length > 0">
            <tr>
                <td>{{tlsProtocolName.toUpperCase()}}证书</td>
                <td>
                    <ssl-certs-box :v-protocol="tlsProtocolName.toLowerCase()"></ssl-certs-box>
                </td>
            </tr>
        </tbody>

		<!-- 源服务器地址 -->
		<tr v-if="serverType == 'httpProxy' || serverType == 'tcpProxy' || serverType == 'udpProxy'">
			<td>源站地址</td>
			<td>
				<input type="hidden" name="origins" :value="JSON.stringify(origins)"/>
				<div v-if="origins.length > 0">
					<div v-for="(origin, index) in origins" class="ui label small">
                        {{origin.addr.protocol}}://{{origin.addr.host}}:{{origin.addr.portRange}}
						<a href="" title="删除" @click.prevent="removeOrigin(index)"><i class="icon remove"></i></a>
					</div>
					<div class="ui divider"></div>
				</div>
				<a href="" @click.prevent="addOrigin">[添加源站地址]</a>
			</td>
		</tr>

		<!-- Web Server -->
		<tr v-if="serverType == 'httpWeb'">
			<td>Web目录</td>
			<td>
				<input type="text" name="webRoot"/>
			</td>
		</tr>

		<tr>
			<td>选择分组</td>
			<td>
				<server-group-selector></server-group-selector>
			</td>
		</tr>

        <tr>
            <td>默认开启配置</td>
            <td>
                <checkbox checked="checked" name="accessLogIsOn">访问日志</checkbox>
                &nbsp; &nbsp;
                <checkbox checked="checked" name="websocketIsOn">Websocket</checkbox>
            </td>
        </tr>

		<tr>
			<td colspan="2"><more-options-indicator></more-options-indicator></td>
		</tr>
		<tbody v-show="moreOptionsVisible">
			<tr>
				<td>描述</td>
				<td>
					<textarea name="description" rows="3"></textarea>
				</td>
			</tr>
		</tbody>
	</table>
	<submit-btn></submit-btn>
</form>