{$layout}
{$template "menu"}

<div class="ui message error" v-if="!serversIsEnabled">
    当前账号下的网站不可用，请检查账号状态以及是否有逾期未支付的账单。
</div>

<div class="ui message warning" v-if="serversIsEnabled && countUnpaidBills > 0">
    <a href="/finance/bills?paidFlag=0">有逾期未支付的账单，可能会影响你的CDN服务正常运行，请尽快完成支付。</a>
</div>

<div class="margin"></div>
<form class="ui form" action="/servers">
    <div class="ui fields inline">
        <div class="ui field">
            <input type="text" name="keyword" v-model="keyword" placeholder="域名"/>
        </div>
        <div class="ui field" v-if="groups.length > 0">
            <select class="ui dropdown" name="groupId" v-model="groupId">
                <option value="0">[分组]</option>
                <option v-for="group in groups" :value="group.id">{{group.name}}</option>
            </select>
        </div>
        <div class="ui field">
            <button type="submit" class="ui button">搜索</button>
            &nbsp;
            <a href="/servers" v-if="keyword.length > 0 || groupId > 0">[清除条件]</a>
        </div>
    </div>
</form>

<p class="comment" v-if="servers.length == 0">暂时还没有任何域名。</p>

<div v-if="checkedServerIds.length > 0">
    <div class="ui divider"></div>
    <button class="ui button basic" @click.prevent="resetCheckedServers">取消所选</button> &nbsp; &nbsp;
    <button class="ui button basic" @click.prevent="deleteServers">删除所选{{checkedServerIds.length}}网站</button>
</div>

<table class="ui table selectable" v-if="servers.length > 0">
    <thead>
        <tr>
            <th style="width: 1em" class="server-checkbox-td"><checkbox ref="allCheckedCheckboxes" @input="changeAllChecked"></checkbox></th>
            <th>域名</th>
            <th class="three wide">CNAME</th>
            <th class="three wide">状态</th>
            <th class="two wide">HTTP</th>
            <th class="two wide">HTTPS</th>
            <th class="three op">操作</th>
        </tr>
    </thead>
    <tr v-for="server in servers">
        <td class="server-checkbox-td"><checkbox ref="serverCheckboxes" :v-value="server.id" @input="changeServerChecked"></checkbox></td>
        <td class="server-td">
            <a :href="'/servers/server?serverId=' + server.id">
                <span v-if="server.serverNames.length > 0">
                    <span v-if="server.serverNames[0].subNames == null || server.serverNames[0].subNames.length == 0"><keyword :v-word="keyword">{{server.serverNames[0].name}}</keyword></span>
                        <span v-else>{{server.serverNames[0].subNames[0]}}</span>
                        <span v-if="server.countServerNames > 1">等{{server.countServerNames}}个域名 <popup-icon :href="'/servers/serverNamesPopup?serverId=' + server.id" height="20em"></popup-icon></span>
			        </span>
                <span v-else class="disabled">-</span>
            </a>

            <!-- name -->
            <span class="server-name-box">
                <span class="grey small">&nbsp; <i class="icon tag small"></i>{{server.name}}
                    &nbsp; <a href="" @click.prevent="updateServerName(server.id)">[修改]</a>
                </span>
            </span>

            <div v-if="server.userPlan != null && server.userPlan.id > 0">
                <span style="margin-top: 1em" class="small" :class="{grey: !server.userPlan.isExpired, red: server.userPlan.isExpired}">套餐：{{server.userPlan.name}} / {{server.userPlan.dayTo}} <span v-if="server.userPlan.isExpired">已过期</span></span>
            </div>
            <div v-if="server.trafficLimitStatus != null">
                <server-traffic-limit-status-viewer v-model="server.trafficLimitStatus"></server-traffic-limit-status-viewer>
            </div>
            <div v-if="server.groups.length > 0">
                <span style="margin-top: 1em" class="small grey" v-for="serverGroup in server.groups">[{{serverGroup.name}}] &nbsp; </span>
            </div>
        </td>
        <td>{{server.cname}}</td>
        <td>
            <span v-if="!server.isOn" class="grey">停用中</span>
            <span v-else-if="server.status.isOk" class="green">正常</span>
            <span v-else-if="server.status.message.length == 0">检查中</span>
            <span v-else class="red">{{server.status.message}}
                <tip-icon :content="server.status.todo"></tip-icon>
            </span>
        </td>
        <td>
            <span v-if="server.httpIsOn" class="green">Y</span>
        </td>
        <td>
            <span v-if="server.httpsIsOn" class="green">Y</span>
        </td>
        <td>
            <a :href="'/servers/server?serverId=' + server.id">管理</a> &nbsp;
            <a href="" v-if="server.isOn" @click.prevent="updateServerOff(server.id)">停用</a><a href="" v-if="!server.isOn" @click.prevent="updateServerOn(server.id)"><span class="red">启用</span></a> &nbsp;
            <a href="" @click.prevent="deleteServer(server.id)">删除</a>
        </td>
    </tr>
</table>

<div class="page" v-html="page"></div>