{% extends "Global/layout.html.twig" %}

{% set pagetitle = 'Manage amenities' | trans %}

{% block title %}{{pagetitle}}{% endblock %}

{% block content %}

    {% set navigation = [{ "dashboard_index": ('Dashboard' | trans), "current":(pagetitle) }] %}
    {% include "Global/navigation.html.twig" with navigation %}

    <section class="section-content padding-y bg-white">
        <div class="{{ services.getSetting("app_layout") }}">
            <div class="row">
                <aside class="col-lg-3 pt-3 pt-lg-0">
                    {% include "Dashboard/sidebar.html.twig" %}
                </aside>
                <div class="col-lg-9 mt-4 mt-lg-0">

                    <div class="box shadow-none bg-gray mb-4">
                        <div class="row">
                            <div class="col-sm-12 col-lg-2 text-center text-lg-left mb-3 mb-lg-0">
                                <span class="center-lg-y text-muted">{{ "%resultsCount% result(s) found"|trans({'%resultsCount%': amenities.getTotalItemCount}) }}</span>
                            </div>
                            <div class="col-sm-12 col-lg-4 text-center mb-3 mb-lg-0">
                                <form>
                                    <ul class="list-inline">
                                        <li class="list-inline-item dropdown"><a href="#" class="dropdown-toggle" data-toggle="dropdown">{{ "Search"|trans }}</a>
                                            <div class="dropdown-menu dropdown-menu-arrow p-3" style="min-width:300px;max-width:500px;">
                                                <label for="keyword">{{ "Keyword"|trans }}</label>
                                                <input id="keyword" name="keyword" type="text" class="form-control" value="{{ app.request.get('keyword') }}">
                                            </div>
                                        </li>
                                        <li class="list-inline-item ml-3"><button type="submit" class="btn btn-primary"><i class="fas fa-search"></i></button></li>
                                    </ul>
                                </form>
                            </div>
                            <div class="col-sm-12 col-lg-6 text-center text-lg-right">
                                <label for="sortable-select" class="display-inline">{{ "Sort by"|trans }}
                                    <select id="sortable-select" class="form-control display-inline-block bg-white select2 ml-3" data-placeholder="{{ "Select an option"|trans }}" style="width: 50%;">
                                        {{ knp_pagination_sortable(amenities, "Creation date"|trans ~ ' (' ~ "desc"|trans ~ ')', "a.createdAt", {"direction": "desc", "criteria": "a.createdAt"}) }}
                                        {{ knp_pagination_sortable(amenities, "Creation date"|trans ~ ' (' ~ "asc"|trans ~ ')', "a.createdAt", {"direction": "asc", "criteria": "a.createdAt"}) }}
                                    </select>
                                </label>
                                <a href="{{ path('dashboard_administrator_amenity_add') }}" class="btn btn-primary ml-3" data-toggle="tooltip" title="{{'Add a new amenity' | trans}}"><i class="fas fa-plus"></i></a>
                            </div>
                        </div>
                    </div>

                    {% if amenities.getTotalItemCount > 0 %}

                        <div class="row">

                            <div class="col-12">
                                <div class="card">
                                    <div class="table-responsive">
                                        <table class="table table-hover table-vcenter text-nowrap">
                                            <thead>
                                                <tr>
                                                    <th>{{'Name' | trans}}</th>
                                                    <th>{{'Venues count' | trans}}</th>
                                                    <th>{{'Icon' | trans}}</th>
                                                    <th>{{'Status' | trans}}</th>
                                                    <th class="text-center"><i class="fas fa-cog"></i></th>
                                                </tr>
                                            </thead>
                                            <tbody>

                                                {% for amenity in amenities %}

                                                    <tr>
                                                        <td>
                                                            {{ amenity.name }}
                                                        </td>
                                                        <td>
                                                            {{ amenity.venues|length }}
                                                        </td>
                                                        <td>
                                                            <i class="{{ amenity.icon }} fa-2x fa-fw"></i>
                                                        </td>
                                                        <td>
                                                            {% if amenity.hidden %}
                                                                <span class="badge badge-danger"><i class="fas fa-eye-slash fa-fw"></i> {{ "Hidden"|trans }}</span>
                                                            {% else %}
                                                                <span class="badge badge-success"><i class="fas fa-eye fa-fw"></i> {{ "Visible"|trans }}</span>
                                                            {% endif %}
                                                            {% if amenity.deletedAt %}
                                                                <br>
                                                                <br>
                                                                <span class="badge badge-danger"><i class="fas fa-times fa-fw"></i> {{ "Deleted"|trans }}</span>
                                                            {% endif %}
                                                        </td>
                                                        <td class="text-center">
                                                            <div class="item-action dropdown">
                                                                <a href="javascript:void(0)" data-toggle="dropdown" data-boundary="window" class="icon"><i class="fas fa-ellipsis-v"></i></a>
                                                                <div class="dropdown-menu dropdown-menu-right">
                                                                    <a href="{{ path('dashboard_administrator_amenity_edit', { slug : amenity.slug }) }}" class="dropdown-item"><i class="dropdown-icon fas fa-edit fa-fw text-muted"></i> {{ "Edit"|trans }}</a>
                                                                    {% if amenity.hidden %}
                                                                        <a href="{{ path('dashboard_administrator_amenity_show', { slug : amenity.slug }) }}" class="dropdown-item"><i class="dropdown-icon fas fa-eye fa-fw text-muted"></i> {{ "Show"|trans }}</a>
                                                                    {% else %}
                                                                        <a href="{{ path('dashboard_administrator_amenity_hide', { slug : amenity.slug }) }}" class="dropdown-item"><i class="dropdown-icon fas fa-eye-slash fa-fw text-muted"></i> {{ "Hide"|trans }} </a>
                                                                    {% endif %}
                                                                    {% if amenity.deletedAt %}
                                                                        <a href="{{ path('dashboard_administrator_amenity_restore', { slug : amenity.slug }) }}" class="dropdown-item"><i class="dropdown-icon fas fa-trash-restore fa-fw text-muted"></i> {{ "Restore"|trans }}</a>
                                                                        <span data-target="{{ path('dashboard_administrator_amenity_delete', { slug : amenity.slug }) }}" class="dropdown-item requires-confirmation" data-confirmation-text="{{ "You are about to delete the amenity PERMANENTLY"|trans }}"><i class="dropdown-icon fas fa-trash fa-fw text-muted"></i> {{ "Delete permanently"|trans }}</span>
                                                                    {% else %}
                                                                        <a href="{{ path('dashboard_administrator_amenity_disable', { slug : amenity.slug }) }}" class="dropdown-item"><i class="dropdown-icon fas fa-times fa-fw text-muted"></i> {{ "Delete"|trans }} </a>
                                                                    {% endif %}
                                                                </div>
                                                            </div>
                                                        </td>
                                                    </tr>

                                                {% endfor %}
                                            </tbody>
                                        </table>
                                    </div>
                                </div>
                                {{ knp_pagination_render(amenities, null, {}, {'align': 'center'}) }}
                            </div>

                        </div>

                    {% else %}

                        {% include "Global/message.html.twig" with { type: "info", message: ('No amenites found'|trans), icon: "fas fa-exclamation-circle" } %}

                    {% endif %}
                </div>
            </div>

        </div>
    </section>

{% endblock %}