{% extends "base.html" %}

{% block content %}

<div class="container">

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

<div class="panel panel-success">
<div class="panel-heading"><h3 class="panel-title">Sender 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 sender.infos %}
	<tr>
		<td>{{ info.aircraft }}</td>
		<td>{{ info.registration }}</td>
		<td>{{ info.competition }}</td>
		<td>{{ info.aircraft_type.name }}</td>
		<td>{{ info.address_origin.name }}</td>
	</tr>
	{% endfor %}
</table>
</div>

<div class="panel panel-success">
	<div class="panel-heading"><h3 class="panel-title">Range View</h3></div>
	<img src="{{ url_for('main.range_view', sender_id=sender.id) }}" class="img-thumbnail">	
</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></th>
            <th></th>
	        <th colspan="2">Airport</th>
	        <th colspan="2">Time UTC</th>
	        <th></th>
	        <th></th>
		</tr>
		<tr>
            <th>#</th>
            <th>Date</th>
	        <th>Takeoff</th>
	        <th>Landing</th>
	        <th>Takeoff</th>
	        <th>Landing</th>
	        <th>Duration</th>
	        <th>AGL</th>
		</tr>
	</theader>
	<tbody>
		{% set ns = namespace(mydate=none) %}
		{% for entry in sender.logbook_entries %}
		<tr>
        	<td>{{ loop.index }}</td>
            <td>{% if ns.mydate != entry.reference_timestamp.strftime('%Y-%m-%d') %}{% set ns.mydate = entry.reference_timestamp.strftime('%Y-%m-%d') %}{{ ns.mydate }}{% endif %}</td>
	        <td>{% if entry.takeoff_airport is not none %}<a href="{{ url_for('main.airport_detail', airport_id=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_id=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 %}
