<%@ page contentType="text/html; charset=UTF-8"%>
<%@ include file="/WEB-INF/jspf/taglibs.jsp"%>

<c:set var="uiid" value="${u:uiid()}"/>
<c:set var="d" value="${frd.device}"/>

<div id="${uiid}" class="inv-card">
	<div class="inv-card-header">
		<h3>${d.name}</h3>
		<span class="inv-status-${d.status}">
			<c:choose>
				<c:when test="${d.status eq 'planned'}">${l.l('Планируется')}</c:when>
				<c:when test="${d.status eq 'active'}">${l.l('Активен')}</c:when>
				<c:when test="${d.status eq 'maintenance'}">${l.l('На обслуживании')}</c:when>
				<c:when test="${d.status eq 'decommissioned'}">${l.l('Выведен из эксплуатации')}</c:when>
				<c:otherwise>${d.status}</c:otherwise>
			</c:choose>
		</span>

		<p:check action="/user/plugin/inventory/device:create">
			<c:url var="editUrl" value="/user/plugin/inventory/device.do">
				<c:param name="method" value="create"/>
				<c:param name="id" value="${d.id}"/>
			</c:url>
			<ui:button type="edit" styleClass="ml1"
				onclick="$$.ajax.load('${editUrl}', $('#${uiid}').parent(), {control: this})"/>
		</p:check>

		<c:url var="backUrl" value="/user/plugin/inventory/device.do"/>
		<button type="button" class="btn-white ml1"
			onclick="$$.ajax.load('${backUrl}', $('#${uiid}').parent(), {control: this})">
			&larr; ${l.l('Назад')}
		</button>
	</div>

	<table class="data mt1">
		<tr><td class="label">${l.l('Тип устройства')}</td><td>${d.deviceTypeTitle}</td></tr>
		<tr><td class="label">${l.l('Серийный номер')}</td><td>${d.serialNumber}</td></tr>
		<tr><td class="label">${l.l('MAC-адрес')}</td><td>${d.macAddress}</td></tr>
		<tr><td class="label">${l.l('Инвентарный номер')}</td><td>${d.assetTag}</td></tr>
		<tr><td class="label">${l.l('Версия ПО')}</td><td>${d.swVersion}</td></tr>
		<tr><td class="label">${l.l('IP-адрес')}</td><td>${d.ip}</td></tr>
		<tr><td class="label">${l.l('Логин')}</td><td>${d.login}</td></tr>
		<tr><td class="label">${l.l('SNMP-сообщество')}</td><td>${d.snmpCommunity}</td></tr>
		<c:if test="${not empty d.parentDeviceName}">
			<tr><td class="label">${l.l('Родительское устройство')}</td>
				<td>
					<c:url var="parentUrl" value="/user/plugin/inventory/device.do">
						<c:param name="method" value="show"/>
						<c:param name="id" value="${d.parentDeviceId}"/>
					</c:url>
					<a href="#" onclick="$$.ajax.load('${parentUrl}', $('#${uiid}').parent(), {control: this}); return false;">${d.parentDeviceName}</a>
					<c:if test="${not empty d.slotPosition}"> [${d.slotPosition}]</c:if>
				</td>
			</tr>
		</c:if>
		<c:if test="${not empty d.uplinkPort}">
			<tr><td class="label">${l.l('Uplink-порт')}</td><td>${d.uplinkPort}</td></tr>
		</c:if>
		<c:if test="${not empty d.decommissionReason}">
			<tr><td class="label">${l.l('Причина вывода из эксплуатации')}</td><td>
				<c:choose>
					<c:when test="${d.decommissionReason eq 'end_of_life'}">${l.l('Конец срока службы')}</c:when>
					<c:when test="${d.decommissionReason eq 'failure'}">${l.l('Неисправность')}</c:when>
					<c:when test="${d.decommissionReason eq 'upgrade'}">${l.l('Модернизация')}</c:when>
					<c:when test="${d.decommissionReason eq 'sold'}">${l.l('Продано')}</c:when>
					<c:when test="${d.decommissionReason eq 'scrapped'}">${l.l('Утилизировано')}</c:when>
					<c:otherwise>${d.decommissionReason}</c:otherwise>
				</c:choose>
			</td></tr>
		</c:if>
		<c:if test="${not empty d.zabbixHostId}">
			<tr><td class="label">${l.l('ID хоста Zabbix')}</td><td>${d.zabbixHostId}</td></tr>
		</c:if>
		<tr><td class="label">${l.l('Дата создания')}</td><td>${tu.format(d.createdAt, 'ymdhms')}</td></tr>
		<tr><td class="label">${l.l('Дата изменения')}</td><td>${tu.format(d.updatedAt, 'ymdhms')}</td></tr>
	</table>

	<c:if test="${not empty d.vendorAttrs}">
		<h4 class="mt1">${l.l('Атрибуты вендора')}</h4>
		<pre class="inv-json">${d.vendorAttrs}</pre>
	</c:if>

	<c:if test="${not empty frd.paramList}">
		<h4 class="mt1">${l.l('Параметры')}</h4>
		<c:set var="list" value="${frd.paramList}"/>
		<c:set var="id" value="${d.id}"/>
		<c:set var="tableId" value="${u:uiid()}"/>
		<%@ include file="/WEB-INF/jspf/parameter_list.jsp"%>
	</c:if>
</div>
