{% extends "mini_buildd/includes/api/base.html" %}
{% block results %}
	<header class="mbd-grid-lcr">
		<h2>Source: {{ view.mbd_call.args.source.value }}</h2>
		<span></span>
		<nav>
			<ul>
				<li><a href="https://tracker.debian.org/pkg/{{ view.mbd_call.args.source.value }}"><img class="mbd-icon" src="{% static 'debian.svg' %}" alt="Debian PTS" title="Show source package in the Debian Package Tracker"></a></li>
				<li>{% mbd_api_popup "subscribe" value_source=view.mbd_call.args.source.value %}</li>
			</ul>
		</nav>
	</header>

	{% mbd_token as table_id %}
	<table id="{{ table_id }}">
		{% mbd_datatable table_id no_search='[-1, -2, -3]' %}
		<thead>
			<tr>
				<th>Distribution</th>
				<th>Version</th>
				<th>Migration</th>
				<th>Menu</th>
				<th>Rollbacks</th>
			</tr>
		</thead>

		<tbody>
			{% for distribution, values in view.mbd_call.result.items %}
				<tr>
					<td class="mbd-distribution-{{ distribution }}" {% if values.migrates_to %}title="Migrates to: {{ values.migrates_to }}"{% endif %}>{{ distribution }}</td>
					<td><a href="/static/repositories/{{ values.dsc_path }}" title="DSC URL (in component '{{ values.component }}')">{{ values.version }}</a></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_popup "migrate" title="migrate to "|add:values.migrates_to value_source=values.source value_distribution=values.distribution value_version=values.version %}
										{% endif %}
									</li>
								{% endif %}
							</ul>
						</nav>
					</td>
					<td>
						<nav>
							<ul>
								<li><a href="{% url 'repositories-dir' values.dsc_path %}"><img class="mbd-icon" src="{% static 'icons/mimetypes/text-x-generic.svg' %}" alt="DSC" title="View .dsc file"></a></li>
								{% if values.version %}
									{% mbd_get view.mbd_call.args.source.value|add:"/"|add:values.version|add:"/" as path %}
									<li><a href="{% url 'events' path %}"><img class="mbd-icon" src="{% static 'icons/actions/active-notes.svg' %}" alt="Events" title="Events for this version"></a></li>
								{% endif %}
								<li>
									<details>
										<summary>More</summary>
										{% if values.version %}
											<section>
												{% mbd_api_popup "remove" title="...from "|add:values.distribution value_source=values.source value_distribution=values.distribution value_version=values.version %}
											</section>
											<section>
												{% mbd_api_popup "port" title="Port this source package version to other distribution(s)" value_source=values.source value_from_distribution=values.distribution value_version=values.version %}
											</section>
										{% endif %}
										{% if values.version and values.uploadable %}
											<section>
												{% mbd_api_popup "port" name="rebuild" title="...in "|add:values.distribution value_source=values.source value_from_distribution=values.distribution value_to_distributions=values.distribution value_version=values.version %}
											</section>
										{% endif %}
									</details>
								</li>
							</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 info='false' paging='false' searching='false' %}

								<thead>
									<tr>
										<th>Distribution</th>
										<th>Version</th>
										<th>Menu</th>
									</tr>
								</thead>
								<tbody>
									{% for rollback in values.rollbacks|dictsort:"distribution" %}
										<tr>
											<td>{{ rollback.distribution }}</td>
											<td>{{ rollback.version }}</td>
											<td>
												<nav>
													<ul>
														<li>
															{% mbd_api_popup "remove" title="Remove "|add:rollback.version|add:" from "|add:rollback.distribution value_source=rollback.source value_distribution=rollback.distribution value_version=rollback.version %}
														</li>
														{% if not values.version %}
															<li>
																{% mbd_api_popup "migrate" name="restore" title="Restore rollback "|add:rollback.version|add:" from "|add:rollback.distribution value_source=rollback.source value_distribution=rollback.distribution value_version=rollback.version %}
															</li>
														{% endif %}
														<li>
															<a title="Get dsc of {{ rollback.version }} from {{ rollback.distribution }}" href="{% url 'repositories-dir' rollback.dsc_path %}">
																<img class="mbd-icon" src="{% static 'icons/mimetypes/text-x-generic.svg' %}" alt="DSC" title="View DSC">
															</a>
														</li>
														<li>
															<a href="{% url 'events' view.mbd_call.args.source.value|add:"/"|add:rollback.version|add:"/" %}" title="Log">
																<img class="mbd-icon" src="{% static 'icons/actions/active-notes.svg' %}" alt="Events" title="Events for this version">
															</a>
														</li>
													</ul>
												</nav>
											</td>
										</tr>
									{% endfor %}
								</tbody>
							</table>
						</details>
					</td>
				</tr>
			{% endfor %}
		</tbody>
	</table>
{% endblock %}
