{% spaceless %}

{% set structure = structure is defined ? structure : null -%}
{% set structureEditable = structureEditable is defined ? structureEditable : false -%}

{% if structure -%}
    {% set basePadding = (context == 'index' ? 20 + (showCheckboxes ? 7 : 0) + (structureEditable ? 14 : 0) : 7) %}
    {% set padding = craft.app.locale.getOrientation() == 'ltr' ? 'left' : 'right' -%}
{% endif -%}

{% for element in elements %}
    <tr data-id="{{ element.id }}"{% if structure %} data-level="{{ element.level }}" data-descendants="{{ element.getTotalDescendants() }}"{% endif %}{% if element.id in disabledElementIds %} class="disabled"{% endif %}>
        {% if showCheckboxes %}
            <td class="checkbox-cell"><div class="checkbox" title="{{ 'Select'|t('app') }}"></div></td>
        {% endif %}
        {% for attribute in attributes %}
            {% if loop.first %}
                <td data-title="{{ attribute[1].label }}"{% if structure %} style="padding-{{ padding }}: {{ basePadding + (element.level - 1) * 44 }}px;"{% endif %} data-titlecell="">
                    {%- if structureEditable %}<a class="move icon" title="{{ 'Reorder'|t('app') }}" role="button">&nbsp;</a>{% endif %}
                    {%- if structure and element.getHasDescendants() %}<span class="toggle{% if element.id not in collapsedElementIds %} expanded{% endif %}" title="{{ 'Show/hide children'|t('app') }}"></span>{% endif %}
                    {%- include "_elements/element" -%}
                </td>
            {% else %}
                <td data-title="{{ attribute[1].label }}" data-attr="{{ attribute[0] }}">
                    {{- element.getTableAttributeHtml(attribute[0])|raw -}}
                </td>
            {% endif %}
        {% endfor %}
    </tr>
{% endfor %}

{% endspaceless -%}
