{% block form %}
    {{ sonata_block_render_event('sonata.admin.edit.form.top', { 'admin': admin, 'object': object }) }}

    {% set url = objectId is not null ? 'edit' : 'create' %}

    {% if not admin.hasRoute(url) %}
        <div>
            {{ "form_not_available"|trans({}, "SonataAdminBundle") }}
        </div>
    {% else %}
        <form
              {% if sonata_config.getOption('form_type') == 'horizontal' %}class="form-horizontal"{% endif %}
              role="form"
              action="{% block sonata_form_action_url %}{{ admin.generateUrl(url, {(admin.idParameter): objectId, 'uniqid': admin.uniqid, 'subclass': app.request.get('subclass')}) }}{% endblock %}"
              {% if form.vars.multipart %} enctype="multipart/form-data"{% endif %}
              method="POST"
              {% if not sonata_config.getOption('html5_validate') %}novalidate="novalidate"{% endif %}
              {% block sonata_form_attributes %}{% endblock %}
              >

            {{ include('@SonataAdmin/Helper/render_form_dismissable_errors.html.twig') }}

            {% block sonata_pre_fieldsets %}
                <div class="row">
            {% endblock %}

            {% block sonata_tab_content %}
                {% import "@SonataAdmin/CRUD/base_edit_form_macro.html.twig" as form_helper %}
                {% set formtabs = admin.getformtabs() %}
                {% set has_tab = ((formtabs|length == 1 and formtabs|keys[0] != 'default') or formtabs|length > 1 ) %}

                <div class="col-md-12">
                    {% if has_tab %}
                        {% set tab_prefix = 'tab_' ~ admin.uniqid ~ '_' ~ random() %}
                        {% set tab_query_index = app.request.query.get('_tab', 0)|split("_")|last %}
                        <div class="nav-tabs-custom">
                            <ul class="nav nav-tabs" role="tablist">
                                {% for name, form_tab in formtabs %}
                                    {% set _tab_name = tab_prefix ~ '_' ~ loop.index %}
                                    <li{% if (not app.request.query.has('_tab') and loop.index == 1) or (tab_query_index == loop.index) %} class="active"{% endif %}>
                                        <a href="#{{ _tab_name }}" class="changer-tab" aria-controls="{{ _tab_name }}" data-toggle="tab">
                                            <i class="fas fa-exclamation-circle has-errors hide" aria-hidden="true"></i>
                                            {% if form_tab.translation_domain is defined and form_tab.translation_domain is same as(false) %}
                                                {{ form_tab.label }}
                                            {% else %}
                                                {{ form_tab.label|trans({}, form_tab.translation_domain ?? admin.translationDomain) }}
                                            {% endif %}
                                        </a>
                                    </li>
                                {% endfor %}
                            </ul>
                            <div class="tab-content">
                                {% for code, form_tab in formtabs %}
                                    {% set _tab_name = tab_prefix ~ '_' ~ loop.index %}
                                    <div
                                        class="tab-pane fade{% if (not app.request.query.has('_tab') and loop.first) or (tab_query_index == loop.index) %} in active{% endif %}"
                                        id="{{ _tab_name }}"
                                    >
                                        <div class="box-body  container-fluid">
                                            <div class="sonata-ba-collapsed-fields">
                                                {% if form_tab.description != false %}
                                                    {% if form_tab.translation_domain is defined and form_tab.translation_domain is same as(false) %}
                                                        <p>{{ form_tab.description|raw }}</p>
                                                    {% else %}
                                                        <p>{{ form_tab.description|trans({}, form_tab.translation_domain ?? admin.translationDomain)|raw }}</p>
                                                    {% endif %}
                                                {% endif %}

                                                {{ form_helper.render_groups(admin, form, form_tab['groups'], has_tab) }}
                                            </div>
                                        </div>
                                    </div>
                                {% endfor %}
                            </div>
                            <input type="hidden" name="_tab" value="{{ app.request.query.get('_tab') }}">
                        </div>
                    {% elseif formtabs['default'] is defined %}
                        {{ form_helper.render_groups(admin, form, formtabs['default'].groups, has_tab) }}
                    {% endif %}
                </div>
            {% endblock %}

            {% block sonata_post_fieldsets %}
                </div>
            {% endblock %}

            {{ form_rest(form) }}

            {% block formactions %}
                <div class="sonata-ba-form-actions well well-small form-actions">
                {% block sonata_form_actions %}
                    {% if app.request.isxmlhttprequest %}
                        {% if objectId is not null %}
                            <button type="submit" class="btn btn-success" name="btn_update"><i class="fas fa-save" aria-hidden="true"></i> {{ 'btn_update'|trans({}, 'SonataAdminBundle') }}</button>
                            {% if admin.hasRoute('delete') and admin.hasAccess('delete', object) %}
                                {% block btn_delete %}
                                    {{ 'delete_or'|trans({}, 'SonataAdminBundle') }}
                                    <a class="btn btn-danger" href="{{ admin.generateObjectUrl('delete', object) }}">
                                        <i class="fas fa-minus-circle" aria-hidden="true"></i> {{ 'link_delete'|trans({}, 'SonataAdminBundle') }}
                                    </a>
                                {% endblock %}
                            {% endif %}
                        {% else %}
                            {% block btn_create %}
                                <button type="submit" class="btn btn-success" name="btn_create"><i class="fas fa-plus-circle" aria-hidden="true"></i> {{ 'btn_create'|trans({}, 'SonataAdminBundle') }}</button>
                            {% endblock %}
                        {% endif %}
                    {% else %}
                        {% if admin.supportsPreviewMode %}
                            {% block btn_preview %}
                                <button class="btn btn-info persist-preview" name="btn_preview" type="submit">
                                    <i class="fas fa-eye" aria-hidden="true"></i>
                                    {{ 'btn_preview'|trans({}, 'SonataAdminBundle') }}
                                </button>
                            {% endblock %}
                        {% endif %}
                        {% if objectId is not null %}
                            {% block btn_update_and_edit %}
                                <button type="submit" class="btn btn-success" name="btn_update_and_edit"><i class="fas fa-save" aria-hidden="true"></i> {{ 'btn_update_and_edit_again'|trans({}, 'SonataAdminBundle') }}</button>
                            {% endblock %}

                            {% if admin.hasRoute('list') and admin.hasAccess('list') %}
                                {% block btn_update_and_list %}
                                    <button type="submit" class="btn btn-success" name="btn_update_and_list"><i class="fas fa-save"></i> <i class="fas fa-list" aria-hidden="true"></i> {{ 'btn_update_and_return_to_list'|trans({}, 'SonataAdminBundle') }}</button>
                                {% endblock %}
                            {% endif %}

                            {% if admin.hasRoute('delete') and admin.hasAccess('delete', object) %}
                                {{ block('btn_delete') }}
                            {% endif %}

                            {% if admin.isAclEnabled() and admin.hasRoute('acl') and admin.hasAccess('acl', object) %}
                                {% block btn_acl %}
                                    <a class="btn btn-info" href="{{ admin.generateObjectUrl('acl', object) }}"><i class="fas fa-users" aria-hidden="true"></i> {{ 'link_edit_acl'|trans({}, 'SonataAdminBundle') }}</a>
                                {% endblock %}
                            {% endif %}
                        {% else %}
                            {% if admin.hasroute('edit') and admin.hasAccess('edit') %}
                                {% block btn_create_and_edit %}
                                    <button class="btn btn-success" type="submit" name="btn_create_and_edit"><i class="fas fa-save" aria-hidden="true"></i> {{ 'btn_create_and_edit_again'|trans({}, 'SonataAdminBundle') }}</button>
                                {% endblock %}
                            {% endif %}
                            {% if admin.hasroute('list') and admin.hasAccess('list') %}
                                {% block btn_create_and_list %}
                                    <button type="submit" class="btn btn-success" name="btn_create_and_list"><i class="fas fa-save"></i> <i class="fas fa-list" aria-hidden="true"></i> {{ 'btn_create_and_return_to_list'|trans({}, 'SonataAdminBundle') }}</button>
                                {% endblock %}
                            {% endif %}
                            {% block btn_create_and_create %}
                                <button class="btn btn-success" type="submit" name="btn_create_and_create"><i class="fas fa-plus-circle" aria-hidden="true"></i> {{ 'btn_create_and_create_a_new_one'|trans({}, 'SonataAdminBundle') }}</button>
                            {% endblock %}
                        {% endif %}
                    {% endif %}
                {% endblock %}
                </div>
            {% endblock formactions %}
        </form>
    {% endif %}

    {{ sonata_block_render_event('sonata.admin.edit.form.bottom', { 'admin': admin, 'object': object }) }}

{% endblock %}
