{% 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 #}
		<section>
			<div class="mbd-warning">
				{% if mbd.daemon.is_alive %}<section><strong>Daemon running (accepting incoming)</strong>: You may want to <em>stop</em> beforehand (each <kbd>setup</kbd> calls will implicitly run stopped, discarding ongoing events every time)</section>{% endif %}
			</div>

			<header class="mbd-grid-lcr">
				<nav>
					<ul>
						<li><a href="{% url 'manual-static' %}administrator.html#setup" title="Jump to Setup section of Administrator's Manual">Manual</a>
						<li>{% mbd_api mbd.api.Setup.setup_inspect name="Inspect" %}</li>
						<li>{% mbd_api mbd.api.Setup.setup_extend name="Extend" %}</li>
					</ul>
				</nav>
				<nav>
					<ul>
						<li>{% mbd_api "setup" %}</li>
					</ul>
				</nav>
				<nav>
					<ul>
						{% for name, setup in mbd.api.SETUP_BOOTSTRAP.items %}
							<li>
								<img class="mbd-icon" src="{% static name|lower|add:'.svg' %}" alt="{{ name }}">
								{% mbd_api setup name="Bootstrap "|add:name %}
							</li>
						{% endfor %}
					</ul>
				</nav>
			</header>
		</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 %}
