{% extends 'base_refresh.html' %}

{% block content %}
    <h4>{{ _("Machines status") }}</h4>
    {% set ns = namespace(cpt=0) %}
    {% for mac in machines %}
        {% if (ns.cpt % 3) == 0 %}
            <div class="row m-2">
        {% endif %}
                <div class="col-lg-3" style="margin: 1px;">
                {% if mac.active_user() != None %}
                    <div class="card bg-success text-white">
                    {% set text = gettext("IN USE") %}
                {% elif mac.blocked %}
                    <div class="card bg-danger text-white">
                    {% set text = gettext("BLOCKED") %}
                {% elif mac.maintenance_needed %}
                    <div class="card bg-warning text-white">
                    {% set text = gettext("MAINTENANCE") %}
                {% elif not mac.online %}
                    <div class="card bg-secondary text-white">
                    {% set text = gettext("OFFLINE") %}
                {% else %}
                    <div class="card bg-light text-black">
                    {% set text = gettext("FREE") %}
                {% endif %}
                        <div class="card-header"><h5><a class="link-info" href="{{ url_for('view_machine_use_history', machine_id=mac.machine_id) }}">{{ mac.machine_name }}</a></h5></div>
                        <div class="card-body">
                            <p class="card-title">{{ gettext("Machine status") }}: {{ text }}<br/>
                            {% if mac.active_user() != None %}
                                {{ gettext("In use by:") }} {{ mac.active_user().name }}</p>
                            {% endif %}
                            </p>
                        </div>
                        <div card="card-footer">
                            {% if mac.active_board() != None %}
                                <p class="card-text text-center"><small>Board IP: {{ mac.active_board().ip_address }}</small></p>
                            {% endif %}
                        </div>
                    </div>
                </div>
        {% set ns.cpt = ns.cpt + 1 %}
        {% if ns.cpt % 3 == 0 %}
            </div>
        {% endif %}
    {% endfor %}
    {% if ns.cpt % 3 != 0 %}
        </div>
    {% endif %}
{% endblock %}