{% load i18n %}
{% load staticfiles %}

<div class="row">
    <div class="col-xs-12">
        <h2>
            {% trans "Facilities" %}
            <small>
                <span class="help-tooltip glyphicon glyphicon-question-sign" data-toggle="tooltip" data-placement="right" title='{% trans "A facility is a physical location where learners learn." %}'></span>
            </small>
            {% if missing_meta %}
            <small>
                <span class="help-tooltip glyphicon glyphicon-exclamation-sign
                notice" data-toggle="tooltip" data-placement="right" title='{%trans "The facilities highlighted below are missing metadata (e.g. location, contact information). Click the pencil icon to edit or update this information." %}'></span>
            </small>
            {% endif %}
        </h2>
        {% if not facilities %}
            <p id="no-facilities-message">
                {% trans "You currently have no facilities that sync data with the central server." %}
            </p>
        {% else %}
            <div class="table-responsive" id="facilities-table">
                <table class="table table-hover table-bordered">
                    <thead>
                        <tr class="header-footer-bg">
                            <th>{% trans "Facility Name" %}</th>
                            <th>{% trans "# Users" %}</th>
                            <th>{% trans "# Groups" %}</th>
                            <th>{% trans "Last Usage" %}</th>
                            <th>{% trans "Delete" %}</th>
                        </tr>
                    </thead>
                    <tbody>
                        {% for id,facility in facilities.items %}
                            <tr {% if facility.meta_data_in_need %} class="warning" {% endif %}>
                                <td>
                                     <a class="facility-name" href="{% url 'facility_management' zone_id=zone_id facility_id=facility.id %}">{{ facility.name }}</a>
 					{% if facility.meta_data_in_need %} 
						<a href="{% url 'facility_form' facility_id=facility.id %}" class="help-tooltip glyphicon glyphicon-pencil notice" data-toggle="tooltip" data-placement="right" title="{% trans "Edit/update information for this facility." %}"></a>
 					{% endif %}
                                </td>
                                <td>
                                    {{ facility.num_users }}
                                </td>
                                <td>
                                    {{ facility.num_groups }}
                                </td>
                                </td>
                                <td>
                                    {% if not facility.last_time_used %}
                                        {% trans "Never" %}
                                    {% elif facility.last_time_used.last_activity_datetime %}
                                        {{ facility.last_time_used.last_activity_datetime }}
                                    {% else %}
                                        {{ facility.last_time_used.start_datetime|date }} - {{ facility.last_time_used.end_datetime|date }}
                                    {% endif %}
                                </td>
                                <td>
                                    {% if request.is_django_user %}
                                    <a class="facility-delete-link" href="#">
                                        <span class="glyphicon glyphicon-trash" title="{% trans 'Delete facility' %}" value="{% url 'facility_delete' facility_id=facility.id %}"></span>
                                    </a>
                                    {% endif %}
                                </td>
                            </tr>
                        {% endfor %}
                        {# Add a new facility #}
                    </tbody>
                </table>
            </div>
        {% endif %}
    </div>
</div>
<div class="row table-bottom-options">
    <div class="col-sm-4 col-xs-12">
        <p class="add-new-table-item">
            <a class="create-facility" href="{% url 'add_facility' zone_id=zone_id %}">
                <span class="glyphicon glyphicon-plus-sign"></span>
                {% trans 'Add a new facility' %}...
            </a>
        </p>
    </div>
</div>
