{% extends '@ajax-layout/layout.twig' %}

{% block body %}
    <div id="genetableau">
        <center>
            <div>
                <form method="POST" id='formulaireListeTiers'>
                    <input type="hidden" name="divCode" value="{{ post.divCode }}" />
                    <input type="hidden" name="divLibelle" value="{{ post.divLibelle }}" />
                    <input type="hidden" name="exclude_empty_code" value="{{ post.exclude_empty_code }}" />
                    <table class="table" id="tableau">
                        <thead class="thead-dark">
                        <tr>
                            <th>
                                {{ triTable(
                                    'CODE',
                                    infoPagination.filter.tri_CODE,
                                    'Code' | trad,
                                    'genetableau',
                                    path('Ajax.liste.tiers'),
                                    'formulaireListeTiers'
                                ) }}
                            </th>
                            <th>
                                {{ triTable(
                                    'RS',
                                    infoPagination.filter.tri_RS,
                                    'Libellé' | trad,
                                    'genetableau',
                                    path('Ajax.liste.tiers'),
                                    'formulaireListeTiers'
                                ) }}
                            </th>
                        </tr>
                        </thead>
                        <tbody>
                        <tr>
                            <th>
                                {{ filterTable(
                                    'CODE',
                                    infoPagination.filter.filter_CODE,
                                    '', 'genetableau',
                                    path('Ajax.liste.tiers'),
                                    'formulaireListeTiers'
                                ) }}
                            </th>
                            <th>
                                {{ filterTable(
                                    'RS',
                                    infoPagination.filter.filter_RS, '', 'genetableau',
                                    path('Ajax.liste.tiers'),
                                    'formulaireListeTiers'
                                ) }}
                            </th>
                        </tr>
                        {% for tier in tiers %}
                            {% set onClick=attrJs('changeCodeLibelleTiers', [
                                post.divCode,
                                tier.CODE,
                                post.divLibelle,
                                tier.CODE~' ('~tier.RS~')',
                            ])  %}

                            <tr onclick="{{ onClick | raw }}">
                                <td id ="{{ tier.CODE }}">{{ tier.CODE   | convert_encoding('UTF-8', 'ISO-8859-1') }}</td>
                                <td>{{ tier.RS  | convert_encoding('UTF-8', 'ISO-8859-1') }}</td>
                            </tr>
                        {% endfor %}
                        </tbody>
                    </table>

                </form>
                {{ paginations(
                    path('Ajax.liste.tiers'),
                    infoPagination.nombreDePage,
                    infoPagination.page,
                    infoPagination.post,
                    'genetableau'
                ) }}
            </div>
        </center>
    </div>

    <script>
        function changeCodeLibelleTiers(inputId, codeValue, divLibelle, libelleValue)
        {
            changeCodeLibelle(inputId, codeValue, divLibelle, libelleValue);
            desactivePopup();

            if (codeValue === '') {
                changeCodeLibelle('input_empty_code_tiers', '{{ emptyValue }}');
            } else {
                $('#input_empty_code_tiers').val('');
            }
        }
    </script>
{% endblock %}