{#

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.

#}

{% deprecated 'The "tree.html.twig" template is deprecated since sonata-project/admin-bundle version 4.9 and will be removed in 5.0.' %}

{% extends '@SonataAdmin/CRUD/base_list.html.twig' %}

{% import _self as tree %}
{% macro navigate_child(collection, admin, root) %}
    <ul{% if root %} class="sonata-tree"{% endif %}>
        {% for element in collection|filter(element => not root) %}
            <li>
                <div class="sonata-tree__item">
                    {% if element.parent %}<i class="fas fa-caret-right" aria-hidden="true"></i>{% endif %}
                    <i class="fas fa-code" aria-hidden="true"></i>
                    <a class="sonata-tree__item__edit" href="{{ admin.generateObjectUrl('edit', element) }}">{{ element.name }}</a>
                    <i class="text-muted">{{ element.description }}</i>
                    <a class="label label-default pull-right" href="{{ admin.generateObjectUrl('edit', element) }}">edit <i class="fas fa-magic" aria-hidden="true"></i></a>
                    {% if true %}<span class="label label-warning pull-right">true</span>{% endif %}
                </div>

                {% if element.children|length %}
                    {{ _self.navigate_child(element.children, admin, false) }}
                {% endif %}
            </li>
        {% endfor %}
    </ul>
{% endmacro %}

{% block tab_menu %}
    {% include '@SonataAdmin/CRUD/list_tab_menu.html.twig' with {
        'mode':   'tree',
        'action': action,
        'admin':  admin,
    } only %}
{% endblock %}

{% block list_table %}
    <div class="col-xs-12 col-md-12">
        <div class="box box-primary">
            <div class="box-header">
                <h1 class="box-title">
                    {{ 'element.tree_site_label'|trans({}, admin.translationdomain) }}
                    <div class="btn-group">
                        <button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown">
                            <strong class="text-info">{{ currentSite.name }}</strong> <span class="caret"></span>
                        </button>
                        <ul class="dropdown-menu" role="menu">
                            {% for context in contexts %}
                                <li>
                                    <a href="{{ admin.generateUrl('tree', { 'context': context.id }) }}">
                                        {% if currentContext and context.id == currentContext.id %}
                                            <span class="pull-right">
                                                <i class="fas fa-check" aria-hidden="true"></i>
                                            </span>
                                        {% endif %}
                                        {{ site.name }}
                                    </a>
                                </li>
                            {% endfor %}
                        </ul>
                    </div>
                </h1>
            </div>
            <div class="box-content">
                {{ tree.navigate_child(collection, admin, true) }}
            </div>
        </div>
    </div>
{% endblock %}
