{% extends "mini_buildd/includes/api/base.html" %}
{% block results %}
	{% mbd_get "mbd-setup-results-table" as table_id %}
	<section>
		<h2 class="mbd-inspect-severity{{ view.mbd_call.report.severity }}">Report: {{ view.mbd_call.report }}</h2>
		<ul>
			{% for key, info in view.mbd_call.report.items %}
				<li class="mbd-inspect-severity{{ info.severity }}">
					<strong>{{ key }}: {{ info.quantity }}</strong>
					{% if info.search %}<button class="mbd-button" type="button" title="Search for '{{ info.search }}'" onclick="$('#{{ table_id }}').dataTable().fnFilter('{{ info.search }}');">select</button>{% endif %}
				</li>
			{% endfor %}
		</ul>
	</section>

	<section>
		<h2>Instances</h2>
		<table id="{{ table_id }}" style="width: 100%;">
			{% mbd_datatable table_id columns='[null, null, null, null, null, {"searchable": false, "orderable": false}]' %}
			<thead>
				<tr>
					<th>Instance</th>
					<th>Status</th>
					<th title="Deviations here most likely should be fixed (run ``setup`` with ``update`` option to auto-fix)">Diff from Setup (subject for update)</th>
					<th title="Deviations here are most likely harmless or intended -- for information only (if needed/wanted, please fixup manually)">Diff from Model (informational)</th>
					<th title="What change has been done to this instance in this run (created=new instance, updated=existing instance updated with setup values, pca=full prepare/create/activate)">Actions</th>
					<th>Menu</th>
				</tr>
			</thead>
			<tbody>
				{% for info in view.mbd_call.result.instances %}
					<tr>
						<td><strong>{{ info.identity_str }}</strong></td>
						<td class="mbd-inspect-severity{{ info.status_severity }}"><strong>{{ info.status }}</strong></td>
						{% with msg=info.diff.setup.diff|yesno:'Setup differs,Setup matches' data=info.diff.setup %}
							<td data-search="{{ msg }}" class="{{ data.diff|yesno:'mbd-warning,mbd-success' }}" title="Fields compared: {{ data.fields }}">
								<details>
									<summary>{{ msg }}</summary>
									<pre>{{ data.diff|mbd_jsonpp }}</pre>
								</details>
							</td>
						{% endwith %}
						{% with msg=info.diff.model.diff|yesno:'Model differs,Model matches' data=info.diff.model %}
							<td data-search="{{ msg }}" class="{{ data.diff|yesno:'mbd-notice,mbd-success' }}" title="Fields compared: {{ data.fields }}">
								<details>
									<summary>{{ msg }}</summary>
									<pre>{{ data.diff|mbd_jsonpp }}</pre>
								</details>
							</td>
						{% endwith %}
						<td>{{ info.actions|join:',' }}</td>
						<td>
							<nav>
								<ul>
									<li>{% mbd_api view.mbd_call name="update" value_update=info.identity_hash value_pca="" hide_options=True %}</li>
									<li>{% mbd_api view.mbd_call name="pca" value_update="" value_pca=info.identity_hash hide_options=True %}</li>
									<li>{% mbd_api view.mbd_call name="update+pca" value_update=info.identity_hash value_pca=info.identity_hash hide_options=True %}</li>
									{% if info.change_instance_url %}
										<li><a href="{% url info.change_instance_url info.change_instance_pk %}"><img class="mbd-icon" src="{% static 'icons/configure.svg' %}" alt="Configure instance" title="Configure instance"></a></li>
									{% endif %}
								</ul>
							</nav>
						</td>
					</tr>
				{% endfor %}
			</tbody>
			<tfoot>
				<tr>
					<th colspan="6">
						<nav>
							<ul>
								<li>{% mbd_api view.mbd_call name="update all" value_update="all" value_pca="" hide_options=True %}</li>
								<li>{% mbd_api view.mbd_call name="pca all" value_update="" value_pca="all" hide_options=True %}</li>
								<li>{% mbd_api view.mbd_call name="update+pca all" value_update="all" value_pca="all" hide_options=True %}</li>
							</ul>
						</nav>
					</th>
				</tr>
			</tfoot>
		</table>
	</section>
{% endblock %}
