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

{% block title %}Article index{% endblock %}

{% block body %}
    <div class="container mt-3">

        <h1>Article index</h1>

        {% for message in app.flashes('success') %}
            <div class="alert alert-success">
                {{ message }}
            </div>
        {% endfor %}

        <table class="table table-striped">
            <thead>
                <tr>
                    <th>Titre</th>
                    <th>Auteur</th>
                    <th>Date de création</th>
                    <th>Actions</th>
                </tr>
            </thead>
            <tbody>
            {% for article in articles %}
                <tr>
                    <td>{{ article.title }}</td>
                    <td>{{ article.author }}</td>
                    <td>{{ article.creationDate ? article.creationDate|date('Y-m-d H:i:s') : '' }}</td>
                    <td>

                        <a href="{{ path('article_show', {'id': article.id}) }}" class="btn btn-secondary mb-1">Voir</a>
                        <a href="{{ path('article_edit', {'id': article.id}) }}" class="btn btn-secondary mb-1">Éditer</a>
                        {{ include('article/_delete_form.html.twig') }}

                    </td>
                </tr>
            {% else %}
                <tr>
                    <td colspan="6">Pas d'articles trouvés</td>
                </tr>
            {% endfor %}
            </tbody>
        </table>
        <a href="{{ path('article_new') }}" class="btn btn-primary">Créer un nouveau article</a>
    </div>
{% endblock %}
