{% extends "admin/index.html" %}
{% load i18n %}

{% block content %}
	{# Following 'div' is copied from upstream 'admin/index.html' (DRY -- but how, django?). #}
	{# Pseudo-Blocks via comments mark local changes/addons to ease occasional manual syncing with upstream. #}
	{# It *should* be in-sync with version of lowest upstream we support (as per debian/control). #}
	{# FUTURE: django 3.1 supports overwriting app_list.html, but this would still only be a tiny improvement. #}

	{% include "mini_buildd/includes/popup.html" %}

	<div id="content-main">
		{# BLOCK 1: ADDON: Daemon Run Options && Setup #}
		{% comment %}
		.. attention:: Needs CSS fixup
		{% endcomment %}
		<section>
			<header class="mbd-grid-lr">
				<h2>Setup</h2>
				<nav>
					<ul>
						<strong>Presets:</strong>
						<li>
							<img class="mbd-icon" src="{% static 'debian.svg' %}" alt="Debian">
							{% mbd_api_popup mbd.api.Setup.preset_debian name="Debian" %}
						</li>
						<li>
							<img class="mbd-icon" src="{% static 'ubuntu.svg' %}" alt="Ubuntu">
							{% mbd_api_popup mbd.api.Setup.preset_ubuntu name="Ubuntu" %}
						</li>
					</ul>
				</nav>
			</header>

			{% mbd_get mbd.api.Setup.preset_saved_or_bootstrap as custom %}
			{% mbd_api_popup custom.setup name=custom.desc %}
		</section>
		{# END BLOCK 1 #}

		{% if app_list %}
			{% for app in app_list %}
				<div class="app-{{ app.app_label }} module">
					<table>
						<caption>
							<a href="{{ app.app_url }}" class="section" title="{% blocktrans with name=app.name %}Models in the {{ name }} application{% endblocktrans %}">{{ app.name }}</a>
						</caption>

						{% for model in app.models %}
							{# BLOCK 2: ADDON: Extra Sub Header && Setup #}
							{% if model.mbd %}
								{% if model.mbd.header %}
									<tr><td colspan="4"><h2><a href="/doc/admin.html#{{ model.mbd.header|lower }}" title="Jump to administrator manual">{{ model.mbd.header }}</a></h2></td></tr>
								{% endif %}
							{% endif %}
							{# END BLOCK 2 #}

							<tr class="model-{{ model.object_name|lower }}">
								{% if model.admin_url %}
									<th scope="row"><a href="{{ model.admin_url }}">{{ model.name }}</a></th>
								{% else %}
									<th scope="row">{{ model.name }}</th>
								{% endif %}

								{# BLOCK 3: ADDON: Extra info && wizards after model name #}
								{% if model.mbd %}
									<td>
										{% mbd_model_stats model.mbd.class_path as stats %}
										(<span title="Total instances"><b>{{ stats.total }}</b></span>
										{% if stats.active %}<span title="Active instances" class="{% mbd_cssmap 'model_status' 'Active' %}">&nbsp;<b>{{ stats.active }}</b></span>{% endif %}
										{% if stats.prepared %}<span title="Prepared instances" class="{% mbd_cssmap 'model_status' 'Prepared' %}">&nbsp;<b>{{ stats.prepared }}</b></span>{% endif %}
										{% if stats.removed %}<span title="Removed instances" class="{% mbd_cssmap 'model_status' 'Removed' %}">&nbsp;<b>{{ stats.removed }}</b></span>{% endif %})
									</td>
								{% endif %}
								{# END BLOCK 2 #}

								{% if model.add_url %}
									<td><a href="{{ model.add_url }}" class="addlink">{% trans 'Add' %}</a></td>
								{% else %}
									<td>&nbsp;</td>
								{% endif %}

								{% if model.admin_url %}
									{% if model.view_only %}
										<td><a href="{{ model.admin_url }}" class="viewlink">{% trans 'View' %}</a></td>
									{% else %}
										<td><a href="{{ model.admin_url }}" class="changelink">{% trans 'Change' %}</a></td>
									{% endif %}
								{% else %}
									<td>&nbsp;</td>
								{% endif %}
							</tr>
						{% endfor %}
					</table>
				</div>
			{% endfor %}
		{% else %}
			<p>{% trans "You don't have permission to view or edit anything." %}</p>
		{% endif %}
	</div>
{% endblock content %}
