{% set _count = layerset_groups | length %}
<p>{{ 'mb.manager.sourceinstance.embedded_in_applications' | transchoice(_count) }}{{ _count ? ':' : '.' }}</p>
<ul class="list-default">
{% for lsg in layerset_groups %}
    {%- set application = lsg.application -%}
    <li>{%- set _linkToApp = is_granted('EDIT', application) -%}
        {%- if _linkToApp -%}
        <a href="{{ path('mapbender_manager_application_edit', {'slug': application.slug}) ~ '#tabLayers' }}">
        {%- endif -%}
            {{- application.title -}}
            {%- if not application.published -%}&nbsp;<span class="badge">{{ "mb.states.inactive" | trans }}</span>{%- endif -%}
        {%- if _linkToApp -%}
        </a>
        {%- endif -%}
        <ul class="list-default">
        {%- for instance_group in lsg.instance_groups -%}
        {%- set layerset = instance_group.layerset -%}
        {%- for assignment in instance_group.instance_assignments -%}
            {%- set instance = assignment.instance -%}
        <li>{%- if _linkToApp -%}
            <a href="{{ path('mapbender_manager_repository_instance', {'slug': application.slug, 'instanceId' : instance.id}) }}">
            {%- endif -%}
                {%- if instance.layerset -%}
                <span title="{{ 'mb.terms.sourceinstance.bound.singular' | trans }}"><i class="fa fas fa-anchor"></i></span>&nbsp;
                {%- else -%}
                <span title="{{ 'mb.terms.sourceinstance.reusable.singular' | trans }} #{{ instance.id }}"><i class="fa fas fa-wifi"></i></span>&nbsp;
                {%- endif -%}
                {{ assignment.instance.title | default('#' ~ assignment.instance.id) }}
                ({{ "mb.terms.layerset.singular" | trans }} {{ layerset.title | default(layerset.id) }})
                {%- if not assignment.enabled -%}&nbsp;<span class="badge">{{ "mb.states.inactive" | trans }}</span>{%- endif -%}
            {%- if _linkToApp -%}
                </a>
            {%- endif -%}
        </li>
        {%- endfor -%}
        {%- endfor -%}
        </ul>
    </li>
{% endfor %}
</ul>

