{% set operations = operations|default(getLastOperations(app.request, app.user)) %}
{% set title = title|default('Dernières opérations'|trans) %}
{% extends '@kohinos/block/block_collapse.html.twig' %}

{% block blocktitle %}
	<i class="fa fa-list-alt mr-4"></i> {{ title }}
{% endblock blocktitle %}
{% block blocksubtitle %}
{% endblock blocksubtitle %}
{% block blockcontent %}
    <div class="table-responsive">
  		<table class="table">
            <thead>
              <tr>
                <th scope="col">Date</th>
                <th scope="col">Type</th>
                <th scope="col">Operation</th>
                <th scope="col">Montant</th>
              </tr>
            </thead>
            <tbody>
  			{% for operation in operations %}
                <tr>
                    <td><span data-toggle="tooltip" data-placement="bottom" title="{{ operation.createdAt|date('d/m/Y H:i') }}">{{ operation.createdAt|date('d/m/Y') }}</span></td>
                    <td>{{ ((isCurrentAccountable(app.user, operation.flux.expediteur) ? 'exp' : 'dest')~'_'~operation.flux.parenttype)|trans({}, 'flux') }}</td>
                    <td>
                        <span style='cursor:pointer;' data-toggle="collapse" data-target="#operationInfo{{loop.index}}">
                            {% if not isCurrentAccountable(app.user, operation.flux.expediteur)  %}
                                {{ operation.flux.expediteur }}
                            {% elseif not isCurrentAccountable(app.user, operation.flux.destinataire)  %}
                                {{ operation.flux.destinataire }}
                            {% endif %}
                            <i class="fa fa-caret-down ml-2" aria-hidden="true"></i>
                        </span>
                        <div id='operationInfo{{loop.index}}' class='collapse'>
                            Référence : {{ operation.flux.reference }}<br/>
                            Moyen : {{ operation.flux.moyen|trans }}
                        </div>
                    </td>
                    <td><span class='font-weight-bold {{ (operation.montant < 0)? '':'text-primary' }}'>{{ (operation.montant < 0)? '- ':'+ ' }} {{ operation.montant|abs }}</span></td>
                </tr>
  			{% endfor %}
  		  </tbody>
  		</table>
    </div>
    {% if operations|length > 0 %}
        <a href='{{ path('show_operations', {'currency' : operations[0].currency}) }}' type="button" class="btn btn-primary">
            <i class="fa fa-share-square-o" aria-hidden="true"></i>
            {{ 'Voir toutes les opérations'|trans }}
        </a>
		<br/>
		{# <div class="btn-group">
            <button type="button" class="btn btn-primary dropdown-toggle" data-toggle="dropdown" id="dropdownMenuLink">
                <i class="fa fa-share-square-o" aria-hidden="true"></i>
                Exporter
                <span class="caret"></span>
            </button>
            <div class="dropdown-menu" aria-labelledby="dropdownMenuLink">
                <a class="dropdown-item" href="{{ path('exportUserOperation', {'format' : 'json'}) }}">
                    <i class="fa fa-arrow-circle-o-down" aria-hidden="true"></i>
                    JSON
                </a>
                <a class="dropdown-item" href="{{ path('exportUserOperation', {'format' : 'xml'}) }}">
                    <i class="fa fa-arrow-circle-o-down" aria-hidden="true"></i>
                    XML
                </a>
                <a class="dropdown-item" href="{{ path('exportUserOperation', {'format' : 'csv'}) }}">
                    <i class="fa fa-arrow-circle-o-down" aria-hidden="true"></i>
                    CSV
                </a>
                <a class="dropdown-item" href="{{ path('exportUserOperation', {'format' : 'xls'}) }}">
                    <i class="fa fa-arrow-circle-o-down" aria-hidden="true"></i>
                    XLS
                </a>
			</div>
        </div> #}
	{% endif %}
{% endblock blockcontent %}
