{% if layer.parent == null %}
    {% set type = "root" %}
{% elseif layer.sublayer|length > 0 %}
    {% set type = "node" %}
{% else %}
    {% set type = "item" %}
{% endif %}

{% for form_layer in form_layers %}
    {% if form_layer.vars.value.id == layer.id %}
        <tr id="{{ type }}{{ layer.id }}" class="{{ type }} level{{ level }}" data-id="{{ form_layer.vars.value.id }}"{% if layer.parent != null %} data-parent="{{layer.parent.id}}"{% endif %} data-type="{{ type }}">
            {% set _icon = (layer.sublayer | length) ? 'fa fas fa-folder-open' : 'fa fas fa-caret-right' %}
            <td class="level{{ level }} itemType"><span class="itemType {{ _icon }}"></span></td>
            <td class="titleColumn" title="{{ form_layer.title.vars.label | trans }}">{{ form_widget(form_layer.title) }}</td>
            <td title="{{ form_layer.minScale.vars.label | trans }}">{{ form_widget(form_layer.minScale) }}</td>
            <td title="{{ form_layer.maxScale.vars.label | trans }}">{{ form_widget(form_layer.maxScale) }}</td>
            {{ form_row(form_layer.active) }}
            {{ form_row(form_layer.allowselected) }}
            {{ form_row(form_layer.selected) }}
            {{ form_row(form_layer.allowinfo) }}
            {{ form_row(form_layer.info) }}
            {{ form_row(form_layer.allowtoggle) }}
            {{ form_row(form_layer.toggle) }}
            <td class="text-end">
            {%- set _popover_id = 'popover_' ~ form_layer.vars.id -%}
            <div class="static-popover-wrap">
              <span class="-fn-toggle-layer-detail clickable" data-toggle-target="#{{ _popover_id }}"
                    title="{{'mb.manager.source.instancelayer.moreinfo'|trans}}">
                <i class="fas fa-ellipsis"></i>
              </span>
              <div class="popover-inner-wrap">
                <div id="{{ _popover_id }}" class="popover infoMsgBox bs-popover-auto fade">
                  <div class="popover-arrow"></div>
                  <div class="popover-body">
                    <span class="hidden layer-priority">{{ form_widget(form_layer.priority) }}</span>
                      <div class="row mb-3">
                        <div class="col-sm-2">{{ form_label(form_layer.displayId) }}</div>
                        <div class="col-sm-10">
                          {% set inputVal = layer.sourceInstance.source.id ~ '-' ~ layer.sourceItem.id ~ '/' ~ layer.sourceInstance.id ~ '-' ~ layer.id %}
                          {{ form_widget(form_layer.displayId, {'value': inputVal}) }}
                        </div>
                      </div>
                      <div class="row mb-3">
                        <div class="col-sm-2">{{ form_label(form_layer.displayName) }}</div>
                        <div class="col-sm-10">{{ form_widget(form_layer.displayName) }}</div>
                      </div>
                      <div class="row mb-3">
                        <div class="col-sm-2">{{ form_label(form_layer.style) }}</div>
                        <div class="col-sm-10">{{ form_widget(form_layer.style) }}</div>
                      </div>
                      {% if form_layer.legend is defined %}
                          <div class="mb-3 form-check--inline">
                            {{ form_widget(form_layer.legend) }}
                            {{ form_help(form_layer.legend) }}
                          </div>
                      {% endif %}
                  </div>
                </div>
              </div>
            </div>
            </td>
        </tr>
        {% if layer.sublayer|length > 0 %}
            {% for sublayer in layer.sublayer %}
                {% include "@MapbenderWms/Repository/instance-layer-form.html.twig"  with {'form_layers': form_layers, 'layer': sublayer, 'level': level + 1 }%}
            {% endfor %}
        {% endif %}
    {% endif %}
{% endfor %}
