{$layout}

<div class="left-right-box-container">
	{$template "/left_menu_top"}

	<div class="right-box without-tabbar">
		<second-menu>
			<menu-item :href="'/servers/certs?userType=' + userType + '&keyword=' + keyword + '&userId=' + searchingUserId" :active="type == ''">所有证书({{countAll}})</menu-item>
			<menu-item :href="'/servers/certs?userType=' + userType + '&type=ca&keyword=' + keyword + '&userId=' + searchingUserId" :active="type == 'ca'">CA证书({{countCA}})</menu-item>
			<menu-item :href="'/servers/certs?userType=' + userType + '&type=available&keyword=' + keyword + '&userId=' + searchingUserId" :active="type == 'available'">有效证书({{countAvailable}})</menu-item>
			<menu-item :href="'/servers/certs?userType=' + userType + '&type=expired&keyword=' + keyword + '&userId=' + searchingUserId" :active="type == 'expired'">过期证书<span :class="{red: countExpired > 0}">({{countExpired}})</span></menu-item>
			<menu-item :href="'/servers/certs?userType=' + userType + '&type=7days&keyword=' + keyword + '&userId=' + searchingUserId" :active="type == '7days'">7天内过期<span :class="{red: count7Days > 0}">({{count7Days}})</span></menu-item>
			<menu-item :href="'/servers/certs?userType=' + userType + '&type=30days&keyword=' + keyword + '&userId=' + searchingUserId" :active="type == '30days'">30天内过期({{count30Days}})</menu-item>
			<span class="item disabled">|</span>
			<a href="" class="item" @click.prevent="uploadCert">[上传证书]</a>
					<a href="" class="item" @click.prevent="uploadBatch">[批量上传]</a>
		</second-menu>

			<form class="ui form">
					<input type="hidden" name="type" :value="type"/>
					<input type="hidden" name="userType" :value="userType"/>
					<div class="ui fields inline">
							<div class="ui field">
									<input type="text" name="keyword" placeholder="域名、说明等关键词" style="width:12em" v-model="keyword"/>
							</div>
							<div class="ui field">
									<user-selector :v-user-id="searchingUserId"></user-selector>
							</div>
							<div class="ui field">
									<button type="submit" class="ui button">搜索</button>
									&nbsp;
									<a :href="Tea.url('.', { 'userType':userType, 'type':type })" v-if="keyword.length > 0 || searchingUserId > 0">[清除条件]</a>
							</div>
					</div>
			</form>

			<div v-if="searchingUserId == 0">
					<div class="ui menu text basic tiny" style="margin-bottom:0">
							<a :href="'/servers/certs?userType=&type=' + type + '&keyword=' + keyword + '&userId=' + searchingUserId" class="item" :class="{active: userType == ''}">管理员证书</a>
							<a :href="'/servers/certs?userType=user&type=' + type + '&keyword=' + keyword + '&userId=' + searchingUserId" class="item" :class="{active: userType == 'user'}">用户证书</a>
					</div>
					<div class="ui divider" style="margin-top:0"></div>
			</div>

			<b-empty v-if="certs.length == 0">
				<span v-if="searchingUserId > 0">当前用户下</span>暂时还没有相关的证书。
			</b-empty>



		<table class="ui table selectable celled" v-if="certs.length > 0">
			<thead>
				<tr>
					<th>证书说明</th>
					<th>顶级发行组织</th>
					<th>域名</th>
					<th>生效日期</th>
					<th>过期日期</th>
					<th class="center">引用网站</th>
									<th>所属用户</th>
					<th class="center">状态</th>
					<th class="three op">操作</th>
				</tr>
			</thead>
			<tr v-for="(cert, index) in certs">
							<td><keyword :v-word="keyword">{{cert.name}}</keyword>
					<div v-if="cert.isCA" style="margin-top:0.5em">
						<micro-basic-label class="olive">CA</micro-basic-label>
					</div>
					<div v-if="cert.isACME" style="margin-top: 0.5em">
						<micro-basic-label class="olive" title="通过ACME协议免费申请">ACME</micro-basic-label>
					</div>
				</td>
				<td>
					<span v-if="cert.commonNames != null && cert.commonNames.length > 0">{{cert.commonNames[cert.commonNames.length-1]}}</span>
				</td>
				<td>
					<div v-for="dnsName in cert.dnsNames" style="margin-bottom:0.4em">
											<span class="ui label tiny basic"><keyword :v-word="keyword">{{dnsName}}</keyword></span>
					</div>
				</td>
				<td>{{certInfos[index].beginDay}}</td>
				<td>{{certInfos[index].endDay}}</td>
				<td class="center">{{certInfos[index].countServers}}</td>
							<td>
									<span v-if="certInfos[index].user != null && certInfos[index].user.id > 0"><user-link :v-user="certInfos[index].user"></user-link></span>
									<span v-else class="disabled">管理员</span>
							</td>
				<td nowrap="" class="center">
					<span class="ui label red tiny basic" v-if="!certInfos[index].isOn">未启用</span>
					<span class="ui label red tiny basic" v-else-if="certInfos[index].isExpired">已过期</span>
					<span class="ui label green tiny basic" v-else>有效中</span>
				</td>
				<td>
					<a href="" @click.prevent="viewCert(cert.id)">详情</a> &nbsp;
					<a href="" @click.prevent="updateCert(cert.id)">修改</a> &nbsp;
					<a href="" @click.prevent="deleteCert(cert.id)">删除</a>
				</td>
			</tr>
		</table>

		<div class="page" v-html="filterPageContent(page)"></div>
	</div>
</div>