{#

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.

#}

{% if not sonata_admin.field_description.hasassociationadmin %}
    {{ value|render_relation_element(sonata_admin.field_description) }}
{% elseif sonata_admin.edit == 'inline' %}
    {% for field_description in sonata_admin.field_description.associationadmin.formfielddescriptions %}
        {{ form_row(form[field_description.name]) }}
    {% endfor %}
{% else %}
    <div id="field_container_{{ id }}" class="field-container">
        {% if sonata_admin.edit == 'list' %}
            <span id="field_widget_{{ id }}" class="field-short-description">
                {% if sonata_admin.value and sonata_admin.field_description.associationadmin.id(sonata_admin.value) is not null %}
                    {{ render(path('sonata_admin_short_object_information', {
                        '_sonata_admin': sonata_admin.field_description.associationadmin.baseCodeRoute,
                        'objectId': sonata_admin.field_description.associationadmin.id(sonata_admin.value),
                        'uniqid': sonata_admin.field_description.associationadmin.uniqid,
                        'linkParameters': sonata_admin.field_description.option('link_parameters', {})
                    } + (
                        sonata_admin.field_description.associationadmin.hasRequest()
                        ? sonata_admin.field_description.associationadmin.request.attributes.get('_route_params', {})
                        : {}
                    ) + app.request.query.all|default({})
                    )) }}
                {% elseif sonata_admin.field_description.option('placeholder', 'short_object_description_placeholder') %}
                    <span class="inner-field-short-description">
                        {{ sonata_admin.field_description.option('placeholder', 'short_object_description_placeholder')|trans({}, 'SonataAdminBundle') }}
                    </span>
                {% endif %}
            </span>
            <span style="display: none" >
                {{ form_widget(form) }}
            </span>
        {% else %}
            <span id="field_widget_{{ id }}" >
                {{ form_widget(form) }}
            </span>
        {% endif %}

        <div id="field_actions_{{ id }}" class="field-actions">
            {% set display_btn_list = sonata_admin.edit == 'list'
                and sonata_admin.field_description.associationadmin.hasRoute('list')
                and sonata_admin.field_description.associationadmin.hasAccess('list')
                and btn_list %}
            {% set display_btn_add = sonata_admin.edit != 'admin'
                and sonata_admin.field_description.associationadmin.hasRoute('create')
                and sonata_admin.field_description.associationadmin.hasAccess('create')
                and btn_add %}
            {% if display_btn_list or display_btn_add %}
            <div class="btn-group">
                {% if display_btn_list %}
                    <a  href="{{ sonata_admin.field_description.associationadmin.generateUrl('list', {select: true}|merge(sonata_admin.field_description.getOption('link_parameters', {}))) }}"
                        onclick="return start_field_dialog_form_list_{{ id }}(this);"
                        class="btn btn-info btn-sm sonata-ba-action"
                        {# NEXT_MAJOR: Remove the fallback on null and on btn_catalogue #}
                        title="{{
                            btn_translation_domain|default(null) is same as(false)
                            ? btn_list
                            : btn_list|trans({}, btn_translation_domain|default(btn_catalogue))
                        }}"
                        >
                        <i class="fas fa-list"></i>
                        {# NEXT_MAJOR: Remove the fallback on null and on btn_catalogue #}
                        {{
                            btn_translation_domain|default(null) is same as(false)
                            ? btn_list
                            : btn_list|trans({}, btn_translation_domain|default(btn_catalogue))
                        }}
                    </a>
                {% endif %}

                {% if display_btn_add %}
                    <a  href="{{ sonata_admin.field_description.associationadmin.generateUrl('create', sonata_admin.field_description.getOption('link_parameters', {})) }}"
                        onclick="return start_field_dialog_form_add_{{ id }}(this);"
                        class="btn btn-success btn-sm sonata-ba-action"
                        {# NEXT_MAJOR: Remove the fallback on null and on btn_catalogue #}
                        title="{{
                            btn_translation_domain|default(null) is same as(false)
                            ? btn_add
                            : btn_add|trans({}, btn_translation_domain|default(btn_catalogue))
                        }}"
                        >
                        <i class="fas fa-plus-circle"></i>
                        {# NEXT_MAJOR: Remove the fallback on null and on btn_catalogue #}
                        {{
                            btn_translation_domain|default(null) is same as(false)
                            ? btn_add
                            : btn_add|trans({}, btn_translation_domain|default(btn_catalogue))
                        }}
                    </a>
                {% endif %}
            </div>
            {% endif %}

            {% set display_btn_delete = sonata_admin.edit == 'list'
                and sonata_admin.field_description.associationadmin.hasRoute('delete')
                and sonata_admin.field_description.associationadmin.hasAccess('delete')
                and btn_delete %}
            {% if display_btn_delete %}
                <a  href=""
                    onclick="return remove_selected_element_{{ id }}(this);"
                    class="btn btn-danger btn-sm sonata-ba-action"
                    {# NEXT_MAJOR: Remove the fallback on null and on btn_catalogue #}
                    title="{{
                        btn_translation_domain|default(null) is same as(false)
                        ? btn_delete
                        : btn_delete|trans({}, btn_translation_domain|default(btn_catalogue))
                    }}"
                    >
                    <i class="fas fa-minus-circle"></i>
                    {# NEXT_MAJOR: Remove the fallback on null and on btn_catalogue #}
                    {{
                        btn_translation_domain|default(null) is same as(false)
                        ? btn_delete
                        : btn_delete|trans({}, btn_translation_domain|default(btn_catalogue))
                    }}
                </a>
            {% endif %}

            {% if display_btn_list or display_btn_add or display_btn_delete %}
                {% include '@SonataAdmin/CRUD/Association/edit_modal.html.twig' %}
                {% include '@SonataAdmin/CRUD/Association/edit_many_script.html.twig' %}
            {% endif %}
        </div>
    </div>
{% endif %}
