{% extends "mini_buildd/includes/api/base.html" %}
{% block results %}
	{% mbd_get view.mbd_call.args.source.value as source %}  {# Shortcut #}
	{% include "mini_buildd/includes/api/source_header.html" %}

	{% mbd_hash "mbd-api-show-"|add:source as table_id %}
	<table id="{{ table_id }}" style="width: 100%;">
		{% mbd_datatable table_id columns='[null, null, {"searchable": false}, {"searchable": false}, {"searchable": false}]' %}
		<thead>
			<tr>
				<th>Distribution</th>
				<th>Version</th>
				<th>Migration</th>
				<th>Menu</th>
				<th>Rollbacks</th>
			</tr>
		</thead>

		<tbody>
			{% for repository, results in view.mbd_call.result.items %}
				{% for diststr, values in results.items %}
					<tr>
						<td class="mbd-distribution-{{ diststr }}" {% if values.migrates_to %}title="Migrates to: {{ values.migrates_to }}"{% endif %}><span class="mbd-table-distribution">{{ diststr }}</span></td>
						<td><code class="mbd-table-version">{{ values.version }}</code></td>
						<td>
							<nav>
								<ul>
									{% if values.migrates_to %}
										<li>
											{% if values.is_migrated %}
												<b class="mbd-success" title="Migrated to {{ values.migrates_to }}">Migrated</b>
											{% elif values.version %}
												{% mbd_api "migrate" value_source=source value_distribution=diststr value_version=values.version %}
											{% endif %}
										</li>
									{% endif %}
								</ul>
							</nav>
						</td>
						<td>
							<nav>
								<ul>
									{% if values.event_path %}
										<li>
											<a class="mbd-icon" href="{% url 'events-dir' values.event_path %}" title="INSTALLED event"><img class="mbd-icon" src="{% static 'icons/installed.svg' %}" alt="EVENT"></a>
										</li>
									{% endif %}
									{% if values.changes_path %}
										<li>
											<a class="mbd-icon" href="{% url 'events-dir' values.changes_path %}" title="Changes"><img class="mbd-icon" src="{% static 'icons/changes.svg' %}" alt="CHANGES"></a>
										</li>
									{% endif %}
									{% if values.version %}
										<li>
											<a class="mbd-icon" title="Dsc" href="{% url 'repositories-dir' values.dsc_path %}">
												<img class="mbd-icon" src="{% static 'icons/dsc.svg' %}" alt="DSC">
											</a>
										</li>
										<li>
											<a class="mbd-icon" title="Browse pool" href="{% url 'repositories-dir' values.dsc_path|mbd_parent %}">
												<img class="mbd-icon" src="{% static 'icons/pool-dir.svg' %}" alt="folder">
											</a>
										</li>
										{% mbd_get view.mbd_call.args.source.value|add:"/"|add:values.version|add:"/" as path %}
										<li>{% mbd_api "remove" value_source=source value_distribution=diststr value_version=values.version %}</li>
										{% if values.uploadable %}
											<li>{% mbd_api "port" name="rebuild" value_source=source value_from_distribution=diststr value_to_distributions=diststr value_version=values.version %}</li>
										{% endif %}
										<li class="mbd-api-port"><details><summary>port</summary>{% mbd_api "port" value_source=source value_from_distribution=diststr value_version=values.version %}</details></li>
									{% endif %}
								</ul>
							</nav>
						</td>
						<td>
							<details>
								<summary>{{ values.rollbacks|length }} Rollbacks</summary>
								{% mbd_token as rollback_table_id %}
								<table id="{{ rollback_table_id }}">
									{% mbd_datatable rollback_table_id %}

									<thead>
										<tr>
											<th>Distribution</th>
											<th>Version</th>
											<th>Menu</th>
										</tr>
									</thead>
									<tbody>
										{% for rollback_diststr, rollback in values.rollbacks.items %}
											<tr>
												<td>{{ rollback_diststr }}</td>
												<td><span class="mbd-table-version">{{ rollback.version }}</span></td>
												<td>
													<nav>
														<ul>
															<li>
																{% mbd_api "debdiff" value_repository=repository value_source=source value_versiona=rollback.version value_versionb=values.version %}
															</li>
															<li>
																{% mbd_api "remove" value_source=source value_distribution=rollback_diststr value_version=rollback.version %}
															</li>
															{% if not values.version %}
																<li>
																	{% mbd_api "migrate" name="restore" value_source=source value_distribution=rollback_diststr value_version=rollback.version %}
																</li>
															{% endif %}
															<li>
																<a class="mbd-icon" title="Dsc" href="{% url 'repositories-dir' rollback.dsc_path %}">
																	<img class="mbd-icon" src="{% static 'icons/dsc.svg' %}" alt="DSC">
																</a>
															</li>
														</ul>
													</nav>
												</td>
											</tr>
										{% endfor %}
									</tbody>
								</table>
							</details>
						</td>
					</tr>
				{% endfor %}
			{% endfor %}
		</tbody>
	</table>
{% endblock %}
