{% 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-fw fa-map-marker-alt" data-toggle="tooltip" data-boundary="window" title="{{ _('Coordinates') }}"></i></th>
                <th><i class="fa fa-fw fa-image" data-toggle="tooltip" data-boundary="window" title="{{ _('Photo') }}"></i></th>
                <th><i class="fa fa-fw fa-calendar" data-toggle="tooltip" data-boundary="window" 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><i class="fa fa-fw fa-map-marker-alt {% if place.location and place.location.coordinate %}text-success{% else %}text-muted{% endif %}" data-toggle="tooltip" data-boundary="window" title="{{ _('Coordinates') }}"></i></td>
                    <td><i class="fa fa-fw fa-image {% if place.photo %}text-success{% else %}text-muted{% endif %}" data-toggle="tooltip" data-boundary="window" title="{{ _('Photo') }}"></i></td>
                    <td><a class="text-body" href="{{ url_for('manage_admin_unit_events', id=admin_unit.id, event_place_id=place.id) }}" data-toggle="tooltip" data-boundary="window" title="{{ _('Number of events') }}">{{ place.events|length }}</a></td>
                </tr>
            {% endfor %}
        </tbody>
    </table>
</div>

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

{% endblock %}