{% extends 'admin/admin_page.twig' %}

{% block header %}
    <script src="{{ "/js/app/admin/polls.js" }}" type="text/javascript"></script>
{% endblock %}

{% block admin_main %}
    <div class="panel panel-default" id="poll_search">
        <div class="panel-heading">{{__('Generic', 'Search')}}</div>
        <div class="panel-body" style="display: none;">
            <form action="" method="GET">
                <div class="row">
                    <div class="col-md-6">
                        <div class="form-group">
                            <label for="poll" class="control-label">{{__('Admin', 'Poll ID')}}</label>
                            <input type="text" name="poll" id="poll" class="form-control"
                                   value="{{ search.poll | raw }}"/>
                        </div>
                    </div>
                    <div class="col-md-6">
                        <div class="form-group">
                            <label for="title" class="control-label">{{__('Admin', 'Title')}}</label>
                            <input type="text" name="title" id="title" class="form-control"
                                   value="{{ search.title | raw }}"/>
                        </div>
                    </div>
                    <div class="col-md-6">
                        <div class="form-group">
                            <label for="name" class="control-label">{{__('Admin', 'Author')}}</label>
                            <input type="text" name="name" id="name" class="form-control"
                                   value="{{ search.name | raw }}"/>
                        </div>
                    </div>
                    <div class="col-md-6">
                        <div class="form-group">
                            <label for="mail" class="control-label">{{__('Admin', 'Email')}}</label>
                            <input type="text" name="mail" id="mail" class="form-control"
                                   value="{{ search.mail | raw }}"/>
                        </div>
                    </div>
                </div>
                <input type="submit" value="{{__('Generic', 'Search')}}" class="btn btn-default"/>
            </form>
        </div>
    </div>

    <form action="" method="POST">
        <input type="hidden" name="csrf" value="{{ crsf }}"/>
        {% if poll_to_delete %}
            <div class="alert alert-warning text-center">
                <h3>{{__('adminstuds', 'Confirm removal of the poll')}} "{{ poll_to_delete.id | raw }}"</h3>

                <p>
                    <button class="btn btn-default" type="submit" value="1"
                            name="annullesuppression">
                        {{__('adminstuds', 'Keep the poll')}}
                    </button>
                    <button type="submit" name="delete_confirm" value="{{ poll_to_delete.id | raw }}"
                            class="btn btn-danger">
                        {{ __('adminstuds', 'Delete the poll') }}
                    </button>
                </p>
            </div>
        {% endif %}
        <input type="hidden" name="csrf" value="{{ crsf }}"/>

        <div class="panel panel-default">
            <div class="panel-heading">
                {% if count == total %}
                    {{ count }}
                {% else %}
                    {{ count }} / {{ total}}
                {% endif %}
                {{ __('Admin', 'polls in the database at this time')}}
            </div>
            <div class="table-of-polls panel">
                <table class="table table-bordered table-polls">
                    <tr align="center">
                        <th scope="col"></th>
                        <th scope="col">{{ __('Admin', 'Title') }}</th>
                        <th scope="col">{{ __('Admin', 'Author') }}</th>
                        <th scope="col">{{ __('Admin', 'Email') }}</th>
                        <th scope="col">{{__('Admin', 'Expiration date')}}</th>
                        <th scope="col">{{__('Admin', 'Votes')}}</th>
                        <th scope="col">{{__('Admin', 'Poll ID')}}</th>
                        <th scope="col" colspan="3">{{__('Admin', 'Actions')}}</th>
                    </tr>
                    {% for poll in polls %}
                        <tr align="center">
                            <td class="cell-format">
                                {% if poll.format == 'D' %}
                                    <span class="glyphicon glyphicon-calendar" aria-hidden="true"
                                          title="{{__('Generic', 'Date')}}"></span>
                                    <span class="sr-only">{{__('Generic', 'Date')}}</span>
                                {% else %}
                                    <span class="glyphicon glyphicon-list-alt" aria-hidden="true"
                                          title="{{__('Generic', 'Classic')}}"></span>
                                    <span class="sr-only">{{__('Generic', 'Classic')}}</span>
                                {% endif %}
                            </td>
                            <td>{{ poll.title | raw }}</td>
                            <td>{{ poll.admin_name | raw }}</td>
                            <td>{{ poll.admin_mail | raw }}</td>

                            {% if date(poll.end_date) > date() %}
                                <td>{{ poll.end_date | date('d/m/y') }}</td>
                            {% else %}
                                <td>
                                    <span class="text-danger">{{ poll.end_date | date('d/m/y') }}</span>
                                </td>
                            {% endif %}
                            <td>{{ poll.votes | raw }}</td>
                            <td>{{ poll.id | raw }}</td>
                            <td>
                                <a href="{{ path('view_poll', {'poll_id': poll.id}) }}" class="btn btn-link"
                                   title="{{__('Admin', 'See the poll')}}">
                                    <span class="glyphicon glyphicon-eye-open"></span>
                                    <span class="sr-only">{{__('Admin', 'See the poll')}}</span>
                                </a>
                            </td>
                            <td>
                                <a href="{{ path('view_admin_poll', {'admin_poll_id': poll.adminId}) }}" class="btn btn-link"
                                   title="{{__('Admin', 'Change the poll')}}">
                                    <span class="glyphicon glyphicon-pencil"></span>
                                    <span class="sr-only">{{ __('Admin', 'Change the poll')}}</span>
                                </a>
                            </td>
                            <td>
                                <button type="submit" name="delete_poll" value="{{ poll.id | raw }}" class="btn btn-link"
                                        title="{{__('Admin', 'Deleted the poll')}}">
                                    <span class="glyphicon glyphicon-trash text-danger"></span>
                                    <span class="sr-only">{{__('Admin', 'Deleted the poll')}}</span>
                                </button>
                            </td>
                        </tr>
                    {% endfor %}
                </table>
            </div>

            <div class="panel-heading">
                {{__('Admin', 'Pages:')}}
                {% for p in 1..pages %}
                    {% if p == page %}
                        <a href="{{ SERVER_URL }}admin/polls.php?page={{ p }}&{{ search_query}}" class="btn btn-danger"
                           disabled="disabled">{{ p }}</a>
                    {% else %}
                        <a href="{{ SERVER_URL }}admin/polls.php?page={{ p }}&{{ search_query }}" class="btn btn-info">{{ p }}</a>
                    {% endif %}
                {% endfor %}
            </div>
        </div>
    </form>
{% endblock %}
