{% extends '@kohinos/bundles/SonataAdminBundle/standard_layout.html.twig' %}

{% block sonata_page_content %}
    <section class="content-header">
        <div class="sticky-wrapper">
            <nav class="navbar navbar-default" role='navigation'>
                <div class="container-fluid">
                    <div class="navbar-collapse">
                        <ul class="nav navbar-nav navbar-right">
                            <li>
                                <a class="sonata-action-element" href="{{ admin.generateUrl('list') }}"><i class="fa fa-undo"></i> Retour à la liste
                                </a>
                            </li>
                            {% if test %}
                                <li>
                                    <a class="sonata-action-element" href="{{ admin.generateUrl('synchro') }}"><i class="fa fa-refresh"></i> Synchronisation
                                    </a>
                                </li>
                            {% else %}
                                <li>
                                    <a class="sonata-action-element" href="{{ admin.generateUrl('synchro') }}?test=true"><i class="fa fa-refresh"></i> Test Synchronisation</a>
                                </li>
                            {% endif %}
                        </ul>
                    </div>
                </div>
            </nav>
        </div>
    </section>
    <section class="content">
    	<div class="row">
    		<div class="col-xs-12 col-md-12">
                <div class="box box-primary" style="margin-bottom: 100px;">
                	<div class="box-body table-responsive">
                        <h4>Synchronisation avec HelloAsso {{test?'(TEST)':'effectué !'}}:</h4>
                        {% if updatedData|length > 0 or newData|length > 0 %}
                            <table class="table table-bordered table-striped table-hover sonata-ba-list">
                                <thead>
                                    <tr class="sonata-ba-list-field-header-text">
                                        <td>Id</td>
                                        <td>HelloAsso Id</td>
                                        <td>Message</td>
                                        <td>Adhérent</td>
                                        <td>Prestataire</td>
                                    </tr>
                                </thead>
                                <tbody>
                                    {% if updatedData|length > 0 %}
                                        <tr>
                                            <td colspan="5" class='text-center'>
                                                <b>MISE(S) À JOUR</b>
                                            </td>
                                        </tr>
                                        {% for key, data in updatedData %}
                                            <tr>
                                                <td>{{key}}</td>
                                                <td>{{data.data.helloassoid}}</td>
                                                <td>{{data.message}}</td>
                                                <td>{{data.data.adherent?("<a href='"~path('adherent_edit', {id: data.data.adherent.id})~"'>" ~ data.data.adherent.name~"</a>")|raw:''}}</td>
                                                <td>{{data.data.prestataire?("<a href='"~path('prestataire_edit', {id: data.data.prestataire.id})~"'>" ~ data.data.prestataire.raison~"</a>")|raw:''}}</a></td>
                                            </tr>
                                        {% endfor %}
                                    {% endif %}
                                    {% if newData|length > 0 %}
                                        <tr>
                                            <td colspan="5" class='text-center'>
                                                <b>NOUVEAUTÉ(S)</b>
                                            </td>
                                        </tr>
                                        <tr>
                                            <td colspan="5" class='text-center'>
                                                <em>Toutes ces transactions sont importées mais aucunes opérations ne sera effectuées sur les comptes des adhérents/prestataires</em>
                                            </td>
                                        </tr>
                            			{% for key, data in newData %}
                                            <tr>
                                                <td>{{key}}</td>
                                                <td>{{data.data.helloassoid}}</td>
                                                <td>{{data.message}}</td>
                                                <td>{{data.data.adherent?("<a href='"~path('adherent_edit', {id: data.data.adherent.id})~"'>" ~ data.data.adherent.name~"</a>")|raw:''}}</td>
                                                <td>{{data.data.prestataire?data.data.prestataire.raison:''}}</td>
                                            </tr>
                                        {% endfor %}
                                    {% endif %}
                                </tbody>
                            </table>
                        {% else %}
                            <br/>
                            <p>
                                {{ "Aucunes informations nouvelles venant d'HelloAsso"|trans }}
                            </p>
                        {% endif %}
        			</div>
    			</div>
    		</div>
    	</div>
    </section>
{% endblock %}