{% extends "base.html" %}

{% block content %}

<div class="container">

<div class="panel panel-success">
<div class="panel-heading"><h3 class="panel-title">Device Details</h3></div>
<table class="datatable table table-striped table-bordered">
	<tr><td>Name:</td><td>{{ device.name }}</td></tr>
	<tr><td>Address:</td><td>{{ device.address }}</td></tr>
	<tr><td>Real Address:</td><td>{{ device.real_address }}</td></tr>
	<tr><td>Stealth:</td><td>{{ device.stealth }}</td></tr>
	<tr><td>Aircraft Type:</td><td>{{ device.aircraft_type }}</td></tr>
	<tr><td>Software Version:</td><td>{{ device.software_version }}</td></tr>
	<tr><td>Hardware Version:</td><td>{{ device.hardware_version }}</td></tr>
	<tr><td>First seen:</td><td>{{ device.firstseen }}</td></tr>
	<tr><td>Last seen:</td><td>{{ device.lastseen }}</td></tr>
</table>
</div>

<div class="panel panel-success">
<div class="panel-heading"><h3 class="panel-title">Device Info</h3></div>
<table class="datatable table table-striped table-bordered">
	<tr>
		<th>Aircraft</th>
		<th>Registration</th>
		<th>Competition Sign</th>
		<th>Aircraft Type</th>
		<th>Source</th>
	</tr>
	{% for info in device.get_infos() %}
	<tr>
		<td>{{ info.aircraft }}</td>
		<td>{{ info.registration }}</td>
		<td>{{ info.competition }}</td>
		<td>{{ info.aircraft_type }}</td>
		<td>{{ info.address_origin }}</td>
	</tr>
	{% endfor %}
</table>
</div>

<div class="panel panel-success">
<div class="panel-heading"><h3 class="panel-title">Logbook</h3></div>
<table class="datatable table table-striped table-bordered">
	<theader>
		<tr>
			<th>Nr.</th>
			<th>Date</th>
	        <th colspan="2">Airport</th>
	        <th colspan="2">Time UTC</th>
	        <th>Duration</th>
	        <th>AGL</th>
		</tr>
		<tr>
			<th></th>
			<th></th>
	        <th>Takeoff</th>
	        <th>Landing</th>
	        <th>Takeoff</th>
	        <th>Landing</th>
	        <th></th>
	        <th></th>
		</tr>
	</theader>
	<tbody>
		{% set date = none %}
		{% for entry in device.logbook %}
		<tr>
			<td>{{ loop.index }}</td>
			<td>{% if date != entry.takeoff_timestamp.strftime('%Y-%m-%d') %}{{ entry.takeoff_timestamp.strftime('%Y-%m-%d') }}{% endif %}</td>
	        <td>{% if entry.takeoff_airport is not none %}<a href="{{ url_for('main.airport_detail', airport=entry.takeoff_airport.id) }}">{{ entry.takeoff_airport.name }}</a>{% endif %}</td>
	        <td>{% if entry.landing_airport is not none %}<a href="{{ url_for('main.airport_detail', airport=entry.landing_airport.id) }}">{{ entry.landing_airport.name }}</a>{% endif %}</td>
	        <td>{% if entry.takeoff_timestamp is not none %} {{ entry.takeoff_timestamp.strftime('%H:%M') }} {% endif %}</td>
	        <td>{% if entry.landing_timestamp is not none %} {{ entry.landing_timestamp.strftime('%H:%M') }} {% endif %}</td>
	        <td>{% if entry.duration is not none %}{{ entry.duration }}{% endif %}</td>
	        <td>{% if entry.max_altitude is not none %}{{ '%0.1f'|format(entry.max_altitude - entry.takeoff_airport.altitude) }} m{% endif %}</td>
		</tr>
		{% endfor %}
	</tbody>
</table>
</div>

</div>

{% endblock %}
