{#

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.

#}

{% extends base_template %}

{% block title %}
    {{ 'title_show'|trans({'%name%': admin.toString(object)|u.truncate(15, '...') }, 'SonataAdminBundle') }}
{% endblock %}

{% block navbar_title %}
    {{ 'title_show'|trans({'%name%': admin.toString(object)|u.truncate(100, '...') }, 'SonataAdminBundle') }}
{% endblock %}

{%- block actions -%}
    {% include '@SonataAdmin/CRUD/action_buttons.html.twig' %}
{%- endblock -%}

{% block tab_menu %}
    {{ knp_menu_render(admin.sidemenu(action), {
        'currentClass' : 'active',
        'template': get_global_template('tab_menu_template')
    }, 'twig') }}
{% endblock %}

{% block show %}
    <div class="sonata-ba-view">

        {{ sonata_block_render_event('sonata.admin.show.top', { 'admin': admin, 'object': object }) }}

        {% set showtabs = admin.getshowtabs() %}
        {% set has_tab = (showtabs|length == 1 and showtabs|keys[0] != 'default') or showtabs|length > 1 %}

        {% 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, show_tab in showtabs %}
                        {% 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">
                                {% if show_tab.translation_domain is defined and show_tab.translation_domain is same as(false) %}
                                    {{ show_tab.label }}
                                {% else %}
                                    {{ show_tab.label|trans({}, show_tab.translation_domain ?? admin.translationDomain) }}
                                {% endif %}
                            </a>
                        </li>
                    {% endfor %}
                </ul>

                <div class="tab-content">
                    {% for code, show_tab in showtabs %}
                        {% 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 show_tab.description != false %}
                                        <p>{{ show_tab.description|raw }}</p>
                                    {% endif %}

                                    {% set groups = show_tab.groups %}
                                    {{ block('show_groups') }}
                                </div>
                            </div>
                        </div>
                    {% endfor %}
                </div>
            </div>
        {% elseif showtabs['default'] is defined %}
            {% set groups = showtabs['default'].groups %}
            {{ block('show_groups') }}
        {% endif %}

    </div>

    {{ sonata_block_render_event('sonata.admin.show.bottom', { 'admin': admin, 'object': object }) }}
{% endblock %}

{% block show_groups %}
    <div class="row">
        {% block field_row %}
            {% for code in groups %}
                {% set show_group = admin.showgroups[code] %}

                <div class="{{ show_group.class|default('col-md-12') }} {{ no_padding|default(false) ? 'nopadding' }}">
                    <div class="{{ show_group.box_class }}">
                        <div class="box-header">
                            <h4 class="box-title">
                                {% block show_title %}
                                    {% if show_group.translation_domain is defined and show_group.translation_domain is same as(false) %}
                                        {{ show_group.label }}
                                    {% else %}
                                        {{ show_group.label|trans({}, show_group.translation_domain ?? admin.translationDomain) }}
                                    {% endif %}
                                {% endblock %}
                            </h4>
                        </div>
                        <div class="box-body table-responsive no-padding">
                            <table class="table">
                                <tbody>
                                {% for show_field_name in show_group.fields %}
                                    {% block show_field %}
                                        <tr class="sonata-ba-view-container">
                                            {% if elements[show_field_name] is defined %}
                                                {{ elements[show_field_name]|render_view_element(object) }}
                                            {% endif %}
                                        </tr>
                                    {% endblock %}
                                {% endfor %}
                                </tbody>
                            </table>
                        </div>
                    </div>
                </div>
            {% endfor %}
        {% endblock %}

    </div>
{% endblock %}
