{#

This file is part of the Sonata package.

(c) Thomas Rabaix <thomas.rabaix@sonata-project.org>

For the full copyright and license information, please view the LICENSE
file that was distributed with this source code.

#}
<table class="table table-bordered">
    <thead>
        <tr>
            {% for field_name, nested_field in form.children|first.children %}
                {% if field_name == '_delete' %}
                    <th>{{ 'action_delete'|trans({}, 'SonataAdminBundle') }}</th>
                {% else %}
                    <th
                        {% if nested_field.vars['required']|default(false) %}
                            class="required"
                        {% endif %}
                        {% if nested_field.vars['attr']['hidden']|default(false) %}
                            style="display:none;"
                        {% endif %}
                    >
                        {{ nested_field.vars.label|trans({}, nested_field.vars['sonata_admin'].admin.translationDomain
                            |default(nested_field.vars.translation_domain)
                        ) }}
                    </th>
                {% endif %}
            {% endfor %}
        </tr>
    </thead>
    <tbody class="sonata-ba-tbody">
        {% for nested_group_field_name, nested_group_field in form.children %}
            <tr>
                {% for field_name, nested_field in nested_group_field.children %}
                    <td class="
                        sonata-ba-td-{{ id }}-{{ field_name }}
                        control-group
                        {% if nested_field.vars.errors|default(false) %} error sonata-ba-field-error{% endif %}
                        "
                        {% if nested_field.vars['attr']['hidden']|default(false) %}
                            style="display:none;"
                        {% endif %}
                    >
                        {% if sonata_admin.field_description.associationadmin.formfielddescriptions[field_name] is defined %}
                            {{ form_widget(nested_field) }}

                            {% if sonata_admin.field_description.associationadmin.formfielddescriptions[field_name].help %}
                                <span class="help-block">
                                    {%- block help %}
                                        {{- sonata_admin.field_description.associationadmin.formfielddescriptions[field_name].help|raw -}}
                                    {% endblock -%}
                                </span>
                            {% endif %}

                            {% set dummy = nested_group_field.setrendered %}
                        {% else %}
                            {% if field_name == '_delete' %}
                                {{ form_widget(nested_field, { label: false }) }}
                            {% else %}
                                {{ form_widget(nested_field) }}
                            {% endif %}
                        {% endif %}
                        {% if nested_field.vars.errors|default(false) %}
                            <div class="help-inline sonata-ba-field-error-messages">
                                {{ form_errors(nested_field) }}
                            </div>
                        {% endif %}
                    </td>
                {% endfor %}
            </tr>
        {% endfor %}
    </tbody>
</table>
