{% extends "layout.html" %}

{% block body %}
    <h3>Admin</h3>
    <div class="panel panel-default">
        <div class="panel-heading">Users</div>
        <div class="panel-body">
            We have {{ users|length }} users so far:
            <ul>
                {% for user in users %}
                    <li>{{user.email}}</li>
                {% endfor %}
        </div>
    </div>

    <div class="panel panel-default">
        <div class="panel-heading">Consumables</div>
        <div class="panel-body">
            <a href="{{ url_for('create_consumable') }}" id="create_consumable" class="btn btn-primary " role="button">
                <span class="glyphicon glyphicon-plus" aria-hidden="true"></span> create
            </a>
        </div>
        <table class="table table-striped table-bordered">
            <tbody>
                <tr>
                    <th>
                        Name
                    </th>
                    <th>
                        Unit
                    </th>
                    <th>
                        Used by
                    </th>
                    <th>
                        Actions
                    </th>
                </tr>
                {% for consumable in consumables %}
                    <tr>
                        <td id="name_{{loop.index}}">{{ consumable.name }}</td>
                        <td id="unit_{{loop.index}}">{{ consumable.unit }}</td>
                        <td id="count_{{loop.index}}">{{ consumable.vehicles | length }} vehicles</td>
                        <td>
                            {% if not consumable.in_use %}
                                <a href="{{ url_for('delete_consumable', cid=consumable.id) }}" id="delete_consumable{{loop.index}}" class="btn btn-primary btn-warning " role="button">
                                    <span class="glyphicon glyphicon-trash" aria-hidden="true"></span> delete
                                </a>
                            {% endif %}
                            <a href="{{ url_for('edit_consumable', cid=consumable.id) }}" id="edit_consumable{{loop.index}}" class="btn btn-primary " role="button">
                                <span class="glyphicon glyphicon-pencil" aria-hidden="true"></span> edit
                            </a>
                        </td>
                    </tr>
                {% endfor %}
            </tbody>
        </table>
    </div>

{% endblock %}