{% extends "@ChillMain/layout.html.twig" %}

{% block title 'List of third parties'|trans %}

{% set third_parties = entities %}

{% block content %}
    {% embed '@ChillMain/CRUD/_index.html.twig' %}

        {% macro rowCustomButtons(tp) %}
            {% if is_granted('CHILL_3PARTY_3PARTY_UPDATE', tp) %}
                <li>
                    <a href="{{ chill_path_add_return_path('chill_crud_3party_3party_edit',
                        { 'id': (tp.isParent ? tp.id : tp.parent.id) }) }}"
                       title="{{ 'Edit'|trans }}"
                       class="btn btn-sm btn-update"></a>
                </li>
            {% endif %}
            {% if is_granted('CHILL_3PARTY_3PARTY_SHOW', tp) %}
                <li>
                    <a href="{{ chill_path_add_return_path('chill_crud_3party_3party_view',
                        { 'id': (tp.isParent ? tp.id : tp.parent.id) }) }}"
                       title="{{ 'Show'|trans }}"
                       class="btn btn-sm btn-show"></a>
                </li>
            {% endif %}
        {% endmacro %}

        {% block index_header %}
            <h1>{{ 'List of third parties'|trans  }}</h1>
        {% endblock %}

        {% block table_entities %}
            <div class="thirdparty-list my-5">
                <div class="row justify-content-center">

                    <label class="counter text-end">
                        <span>{{ paginator.totalItems }}</span> {{ 'third parties'|trans }}
                    </label>

                    <div class="flex-table">
                        {% for tp in third_parties %}
                            <div class="item-bloc">
                                {{ tp|chill_entity_render_box({
                                    'render': 'bloc',
                                    'showContacts': true,
                                    'addLink': true,
                                    'customButtons': { 'replace': _self.rowCustomButtons(tp) },
                                    'isConfidential': (tp.contactDataAnonymous ? true : false)
                                }) }}
                            </div>
                        {% endfor %}
                    </div>

                </div>
            </div>
        {% endblock %}
        {% block actions_before %}
            <li class="cancel">
                {{ chill_items_per_page(paginator) }}
            </li>
        {% endblock %}
    {% endembed %}
{% endblock %}
