{% extends "layout.html" %}
{% set active_id = "places" %}
{% from "_macros.html" import render_pagination, render_location %}
{%- block title -%}
{{ _('Places') }}
{%- endblock -%}
{% block content %}

<h1>
    {{ _('Places') }}
    <a class="btn btn-outline-secondary btn-sm m-1" href="{{ url_for('manage_admin_unit_places_create', id=admin_unit.id) }}" role="button"><i class="fa fa-plus"></i> {{ _('Create place') }}</a>
</h1>

<div class="table-responsive">
    <table class="table table-sm table-bordered table-hover table-striped">
        <thead>
            <tr>
                <th>{{ _('Name') }}</th>
                <th>{{ _('Location') }}</th>
                <th><i class="fa fa-info" data-toggle="tooltip" title="{{ _('Coordinates') }}"></i></th>
                <th>{{ _('Photo') }}</th>
                <th><i class="fa fa-info" data-toggle="tooltip" title="{{ _('Number of events') }}"></i></th>
            </tr>
        </thead>
        <tbody>
            {% for place in places %}
                <tr>
                    <td>
                        <button class="btn btn-link dropdown-toggle p-0 text-wrap text-left" type="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">{{ place.name }}</button>
                        <div class="dropdown-menu dropdown-menu-right">
                            <a class="dropdown-item" href="{{ url_for('event_place_update', id=place.id) }}">{{ _('Edit') }}</a>
                            <a class="dropdown-item" href="{{ url_for('event_place_delete', id=place.id) }}">{{ _('Delete') }}&hellip;</a>
                            <div class="dropdown-divider"></div>
                            <a class="dropdown-item" href="{{ url_for('manage_admin_unit_events', id=admin_unit.id, event_place_id=place.id) }}">{{ _('View events') }}</a>
                        </div>
                    </td>
                    <td>{{ render_location(place.location) }}</td>
                    <td>{% if place.location and place.location.coordinate %}<i class="fa fa-fw fa-check-circle text-success"></i>{% endif %}</td>
                    <td>{% if place.photo %}<i class="fa fa-fw fa-check-circle text-success"></i>{% endif %}</td>
                    <td><a class="text-body" href="{{ url_for('manage_admin_unit_events', id=admin_unit.id, event_place_id=place.id) }}">{{ place.events|length }}</a></td>
                </tr>
            {% endfor %}
        </tbody>
    </table>
</div>

<div class="my-4">{{ render_pagination(pagination) }}</div>

{% endblock %}