{% import 'main/macros.tpl.html' as macro %}
{{ macro.input_csrf() }}
<div class="container">
	<div id="flow-layout" class="{{ block_layout_active }}" aria-labelledby="block-layout">
		<div class="row">
			{% for server in servers_offline %}
			<div class="col-sm-4 col-md-3">
				<noscript><a href="{{ server.url_view|raw }}"></noscript>
				<div class="card text-white bg-danger mb-3" onclick="window.location.href='{{ server.url_view|raw }}'">
					<div class="card-header">{{ server.label }}<span class="sr-only"> ({{ label_offline }})</span></div>
					<div class="card-body">
						<p class="card-text">
							{{ label_last_online }}: {{ server.last_online_nice }}<br>
							{{ label_last_check }}: {{ server.last_checked_nice }}
						</p>
					</div>
				</div>
				<noscript></a></noscript>
			</div>
			{% endfor %}
			{% for server in servers_online %}
			<div class="col-sm-4 col-md-3">
				<noscript><a href="{{ server.url_view|raw }}"></noscript>
				<div class="card text-white bg-success mb-3" onclick="window.location.href='{{ server.url_view|raw }}'">
					<div class="card-header">{{ server.label }}<span class="sr-only"> ({{ label_online }})</span></div>
					<div class="card-body">
						<p class="card-text">
							{{ label_last_online }}: {{ server.last_online_nice }}<br>
							{{ label_last_offline }}: {{ server.last_offline_nice }} {{ server.last_offline_duration_nice }}<br>
							{{ label_rtime }}: {{ server.rtime }}
						</p>
					</div>
				</div>
				<noscript></a></noscript>
			</div>
			{% endfor %}
			{% if not servers_offline and not servers_online %}
				{{ label_none }}
				<div class="w-100"></div>
				<button class="btn btn-primary" onclick="window.location.href='{{ url_save|raw }}'">{{ label_add_server }}</button>
			{% endif %}
		</div>
	</div>
	<div id="list-layout" class="{{ list_layout_active }}" aria-labelledby="block-layout" style="display:none;">
		<div class="row table-responsive">
			{% if servers_offline or servers_online %}
			<table class="table table-bordered table-hover">
				{% if servers_offline %}
				<thead>
					<tr>
						<th scope="col">#</th>
						<th scope="col">{{ label_last_online }}</th>
						<th scope="col">{{ label_last_check }}</th>
						<th scope="col">{{ label_rtime }}</th>
					</tr>
				</thead>
				<tbody>
					{% for server in servers_offline %}
						<tr class="bg-danger text-white" onclick="window.location.href='{{ server.url_view|raw }}'">
							<th class="full">{{ server.label }}<span class="sr-only"> ({{ label_offline }})</span></th>
							<td>{{ server.last_online_nice }}</td>
							<td>{{ server.last_checked_nice }}</td>
							<td></td>
						</tr>
					{% endfor %}
				</tbody>
				{% endif %}
				{% if servers_online %}
				<thead>
					<tr>
						<th scope="col">#</th>
						<th scope="col">{{ label_last_online }}</th>
						<th scope="col">{{ label_last_offline }}</th>
						<th scope="col">{{ label_rtime }}</th>
					</tr>
				</thead>
				<tbody>
					{% for server in servers_online %}
						<tr class="bg-success text-white" onclick="window.location.href='{{ server.url_view|raw }}'">
							<th class="full">{{ server.label }}<span class="sr-only"> ({{ label_online }})</span></th>
							<td>{{ server.last_online_nice }}</td>
							<td>{{ server.last_offline_nice }} {{ server.last_offline_duration_nice }}</td>
							<td>{{ server.rtime }}s</td>
						</tr>
					{% endfor %}
				</tbody>
				{% endif %}
			</table>
			{% else %}
				{{ label_none }}
				<div class="w-100"></div>
				<button class="btn btn-primary" onclick="window.location.href='{{ url_save|raw }}'">{{ label_add_server }}</button>
			{% endif %}
		</div>
	</div>
</div>

{% if auto_refresh %}
<script>
setInterval(function() {
	$.ajax({
		url:"?",
		success: function(html, status) {
			$("#page-container").html(html);
		}
	});
}, {{ auto_refresh_seconds }} * 1000);
</script>
{% endif %}