{% extends 'commands.html' %}
{% import "bootstrap/wtf.html" as wtf %}

{% set sidebar_state = 'disabled' %}
{% set btn_back = true %}

{% block nav_client %} active{% endblock %}
{% block nav_client_cache %} active{% endblock %}
{% block content %}

{% set ip_list = form.ips.data.split(' ') %}
{% set ip_count = ip_list | length %}
<h2 class="mx-5 subhead-heading">
  {{ _('Manage Cache') }}
</h2>

<p>{{ _('Check free cache space in the client\'s bubbles:') }}</p>

{{ macros.cmd_selected_clients(selected_clients) }}

<p>{{ _('Select the images to be deleted:') }}</p>

{% if form.images|length > 0 %}
<form class="form-inline" method="POST" id="cacheForm">
    <table class="table table-hover">
        <thead class="thead-light">
            <tr>
                <th>{{ _('Image') }}</th>
                <th>{{ _('Clients') }}</th>
            </tr>
        </thead>

        <tbody data-target="cache-fieldset" id="cacheTable" class="text-left">
                {{ form.hidden_tag() }}
                {% for image in form.images %}
                    <tr data-toggle="fieldset-entry">
                        <td class="radio-container">
                            {{ image.selected(class_="form-control") }}
                            {{ image.image_name() }}
                            {{ image.clients() }}
                            <b>{{ image.image_name.data  }} ({{ (images_data[image.selected.label.text]['size'] | int / 2**20)|round(3) }} MiB)</b>
                            <div>∘︎ Checksum: {{images_data[image.selected.label.text]['checksum']}}</div>
                        </td>
                        <td>
                          {% for ip in images_data[image.selected.label.text]['clients'] %}<div class="card d-inline-block" style="padding: 5px; margin: 3px;">{{ ip }}</div>{% endfor %}
                        </td>
                    </tr>
                {% endfor %}
        </tbody>
    </table>
    <button class="btn btn-danger" form="cacheForm">
        {{ _('Delete') }}
    </button>
</form>
{% endif %}

{% include 'cache_inspector.html' %}

{% endblock %}
