{% extends '@SonataAdmin/CRUD/base_list.html.twig' %}

{% block list_header %}
    {% if admin.datagrid.results|length > 0 %}
        <div class="box-footer">
            <div class="form-inline clearfix">
                {% if not app.request.isXmlHttpRequest %}
                    {# NEXT_MAJOR : remove this assignment #}
                    {% set export_formats = export_formats|default(admin.exportFormats) %}

                    <div class="pull-left">
                        {% if admin.hasRoute('export') and admin.hasAccess('export') and export_formats|length %}
                            <div class="btn-group">
                                <button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown">
                                    <i class="fa fa-share-square-o" aria-hidden="true"></i>
                                    {{ "label_export_download"|trans({}, "SonataAdminBundle") }}
                                    <span class="caret"></span>
                                </button>
                                <ul class="dropdown-menu">
                                    {% for format in export_formats %}
                                    <li>
                                        {# NEXT_MAJOR: Remove completely next "<a>" element and uncomment the other one #}
                                        <a href="{{ admin.generateUrl('export', sonata_pagination_parameters(admin, 0) + {'format' : format}) }}">
                                            <i class="fa fa-arrow-circle-o-down" aria-hidden="true"></i>
                                            {{ ("export_format_" ~ format)|trans({}, 'SonataAdminBundle') }}
                                        </a>
                                        {#
                                        <a href="{{ admin.generateUrl('export', admin.datagrid.paginationparameters(0) + {'format' : format}) }}">
                                            <i class="fa fa-arrow-circle-o-down" aria-hidden="true"></i>
                                            {{ ("export_format_" ~ format)|trans({}, 'SonataAdminBundle') }}
                                        </a>
                                        #}
                                    </li>
                                    {% endfor %}
                                </ul>
                                {% if tav_env and automatisation_reconversion and admin.isReconversionAdmin is defined and admin.isReconversionAdmin %}
                                    <a href="{{ path('credit_transfer_file') }}" type="button" class="btn btn-default">
                                        <i class="fa fa-share-square-o" aria-hidden="true"></i>
                                        Générer SEPA
                                    </a>
                                {% endif %}
                            </div>
                    </div>
                    {% if admin.total is defined and admin.total > 0 %}
                        <div class="pull-left" style="margin: 5px 5px;">
                            <label for="{{ admin.uniqid }}_sum_of_orders" class="control-label">{{ admin.totalLabel is defined ? admin.totalLabel : (('Total'|trans))}} : </label>
                            <label class="control-label">{{ admin.total }}</label>
                        </div>
                    {% endif %}
{# 
                            {% if block('pager_results') is not empty %}
                                &nbsp;-&nbsp;
                            {% endif %} #}
                        {% endif %}

                    <div class="pull-right">
                        {% include get_admin_template('pager_results', admin.code) %}
                    </div>
                {% endif %}
            </div>
        </div>
    {% endif %}
{% endblock %}


{% block list_footer %}
    {% if admin.datagrid.results|length > 0 %}
        <div class="box-footer">
            <div class="form-inline clearfix">
                {% if not app.request.isXmlHttpRequest %}
                    <div class="pull-left">
                        {% if admin.hasRoute('batch') and batchactions|length > 0 %}
                            {% block batch %}
                                <script>
                                    {% block batch_javascript %}
                                        jQuery(document).ready(function ($) {
                                            // Toggle individual checkboxes when the batch checkbox is changed
                                            $('#list_batch_checkbox').on('ifChanged change', function () {
                                                var checkboxes = $(this)
                                                    .closest('table')
                                                    .find('td.sonata-ba-list-field-batch input[type="checkbox"], div.sonata-ba-list-field-batch input[type="checkbox"]')
                                                ;

                                                if (Admin.get_config('USE_ICHECK')) {
                                                    checkboxes.iCheck($(this).is(':checked') ? 'check' : 'uncheck');
                                                } else {
                                                    checkboxes.prop('checked', this.checked);
                                                }
                                            });

                                            // Add a CSS class to rows when they are selected
                                            $('td.sonata-ba-list-field-batch input[type="checkbox"], div.sonata-ba-list-field-batch input[type="checkbox"]')
                                                .on('ifChanged change', function () {
                                                    $(this)
                                                        .closest('tr, div.sonata-ba-list-field-batch')
                                                        .toggleClass('sonata-ba-list-row-selected', $(this).is(':checked'))
                                                    ;
                                                })
                                                .trigger('ifChanged')
                                            ;
                                        });
                                    {% endblock %}
                                </script>

                            {% block batch_actions %}
                                <label class="checkbox" for="{{ admin.uniqid }}_all_elements">
                                    <input type="checkbox" name="all_elements" id="{{ admin.uniqid }}_all_elements">
                                    {{ 'all_elements'|trans({}, 'SonataAdminBundle') }}
                                    {# NEXT_MAJOR: remove the attribute check and just use .countResults() #}
                                    ({{ attribute(admin.datagrid.pager, 'countResults') is defined ? admin.datagrid.pager.countResults() : admin.datagrid.pager.getNbResults() }})
                                </label>

                                <select name="action" style="width: auto; height: auto" class="form-control">
                                    {% for action, options in batchactions %}
                                        <option value="{{ action }}">{{ options.label|trans({}, options.translation_domain|default(admin.translationDomain)) }}</option>
                                    {% endfor %}
                                </select>
                            {% endblock %}

                                <input type="submit" class="btn btn-small btn-primary" value="{{ 'btn_batch'|trans({}, 'SonataAdminBundle') }}">
                            {% endblock %}
                        {% endif %}
                    </div>


                    {# NEXT_MAJOR : remove this assignment #}
                    {% set export_formats = export_formats|default(admin.exportFormats) %}

                    <div class="pull-left ml-2">
                        {% if admin.hasRoute('export') and admin.hasAccess('export') and export_formats|length %}
                            <div class="btn-group">
                                <button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown">
                                    <i class="fa fa-share-square-o" aria-hidden="true"></i>
                                    {{ "label_export_download"|trans({}, "SonataAdminBundle") }}
                                    <span class="caret"></span>
                                </button>
                                <ul class="dropdown-menu">
                                    {% for format in export_formats %}
                                    <li>
                                        {# NEXT_MAJOR: Remove completely next "<a>" element and uncomment the other one #}
                                        <a href="{{ admin.generateUrl('export', sonata_pagination_parameters(admin, 0) + {'format' : format}) }}">
                                            <i class="fa fa-arrow-circle-o-down" aria-hidden="true"></i>
                                            {{ ("export_format_" ~ format)|trans({}, 'SonataAdminBundle') }}
                                        </a>
                                        {#
                                        <a href="{{ admin.generateUrl('export', admin.datagrid.paginationparameters(0) + {'format' : format}) }}">
                                            <i class="fa fa-arrow-circle-o-down" aria-hidden="true"></i>
                                            {{ ("export_format_" ~ format)|trans({}, 'SonataAdminBundle') }}
                                        </a>
                                        #}
                                    </li>
                                    {% endfor %}
                                </ul>
                            </div>
                            {# {% if block('pager_results') is not empty %}
                                &nbsp;-&nbsp;
                            {% endif %} #}
                        {% endif %}
                    </div>
                    <div class="pull-right">
                        {% block pager_results %}
                            {% include get_admin_template('pager_results', admin.code) %}
                        {% endblock %}
                    </div>
                {% endif %}
            </div>

            {% block pager_links %}
                {% if admin.datagrid.pager.haveToPaginate() %}
                    <hr/>
                    {% include get_admin_template('pager_links', admin.code) %}
                {% endif %}
            {% endblock %}
        </div>
    {% endif %}
{% endblock %}