{% extends 'admin/base.html.twig' %}

{% block content %}
    <div class="content">
        <div class="container-fluid">
            <div class="row">
                <div class="col-md-12">
                    <div class="card">
                        <div class="card-header">
                            <div class="float-left">
                                <h4 class="card-title">Список новостей</h4>
                            </div>
                            <div class="float-right">
                                <a class="btn btn-primary btn-fill btn-icon" href="{{ path('admin.news_add') }}" role="button" title="Добавить">
                                    <i class="fa fa-plus"></i>
                                </a>
                            </div>
                        </div>
                        <div class="card-body">
                            {% for label, messages in app.flashes(['success', 'warning', 'danger', 'info', 'primary']) %}
                                {% for message in messages %}
                                    <div class="alert alert-{{ label }}">
                                        <span>{{ message }}</span>
                                    </div>
                                {% endfor %}
                            {% endfor %}

                            <table class="table table-hover table-bordered">
                                <thead>
                                <th>ID</th>
                                <th>Название</th>
                                <th>Дата публикации</th>
                                <th>Активная</th>
                                <th></th>
                                </thead>
                                <tbody>
                                {% for record in news %}
                                    <tr>
                                        <td>{{ record.id }}</td>
                                        <td>{{ record.title }}</td>
                                        <td>{{ record.publishDate }}</td>
                                        {% if record.isActive %}
                                            <td class="text-success">Да</td>
                                        {% else %}
                                            <td class="text-danger">Нет</td>
                                        {% endif %}
                                        <td style="width: 110px">
                                            <a class="btn btn-primary btn-fill btn-icon" href="{{ path('admin.news_edit', {id: record.id}) }}" role="button" title="Редактировать">
                                                <i class="fa fa-pencil"></i>
                                            </a>
                                            <a class="btn btn-danger btn-fill btn-icon" href="{{ path('admin.news_delete', {id: record.id}) }}" role="button" title="Удалить">
                                                <i class="fa fa-trash-o"></i>
                                            </a>
                                        </td>
                                    </tr>
                                {% endfor %}
                                </tbody>
                            </table>

                            <br>
                            <ul class="pagination justify-content-center">
                                {% if prev_page %}
                                    <li class="page-item">
                                        <a class="page-link" href="{{ path('admin.news_list', {
                                            page: prev_page
                                        }) }}">Предыдущая страница</a>
                                    </li>
                                {% endif %}
                                {% if next_page %}
                                    <li class="page-item">
                                        <a class="page-link" href="{{ path('admin.news_list', {
                                            page: next_page
                                        }) }}">Следующая страница</a>
                                    </li>
                                {% endif %}
                            </ul>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>`
{% endblock %}
