{% macro loop(page, depth, twig_vars) %}
    {% import _self as self %}

    {% set separator = twig_vars['config'].system.param_sep %}
    {% set base_url = twig_vars['base_url_relative'] %}
    {% set base_url_simple = twig_vars['base_url_simple'] %}
    {% set admin_route = twig_vars['admin_route'] %}
    {% set admin_lang = twig_vars['admin_lang'] %}
    {% set warn = twig_vars['warn'] %}

    {% for p in page.children() %}
        {% set page_route =  p.rawRoute|trim('/') %}
        {% if p.language and p.language != admin_lang %}
            {% set page_url = base_url_simple ~ '/' ~ p.language ~ '/' ~ admin_route ~ '/pages/' ~ page_route %}
        {% else %}
            {% set page_url = base_url ~ '/pages/' ~ page_route  %}
        {% endif %}

        <li class="page-item" data-nav-id="{{ p.route }}">
            <div class="row">
                <span {{ p.children(0).count > 0 ? 'data-toggle="children"' : ''}} class="hint--bottom">
                <i class="page-icon fa fa-fw fa-circle-o {{ p.children(0).count > 0 ? 'children-closed' : ''}} {{ p.modular ? 'modular' : (not p.routable ? 'not-routable' : (not p.visible ? 'not-visible' : (not p.page ? 'folder' :  ''))) }}"></i>
                </span>

                <span data-hint="{{ p.header.routes.default ?: p.route }}" class="hint--bottom">
                    <a data-page="{{ p.route }}" class="js__page-link page-link" href="#">{{ p.title }}</a>
                </span>

                <span class="page-home">{{ p.home ? '<i class="fa fa-home"></i>' }}</span>
            </div>
            {% if p.children().count > 0 %}

                <ul class="depth-{{ depth + 1 }}" style="display:none;">
                    {{ self.loop(p, depth + 1, twig_vars) }}
                </ul>
            {% endif %}
        </li>
    {% endfor %}
{% endmacro %}

{% import _self as macro %}

<div class="pages-list-container clear block size-1-4">
    <h5>{{ "PLUGIN_ADMIN.PAGES"|tu|e }}</h5>
    <div class="mediapicker-scroll">
        <ul class="pages-list depth-0">
            {{ macro.loop(pages, 0, _context) }}
        </ul>
    </div>
</div>
