<input type="hidden" name="{{ name }}" value="">

<div id="{{ id }}" class="categoriesfield">
    <ul class="elements structure">
        {% nav category in elements %}
            <li id="{{ id }}-category-{{ category.id }}">
                {% set indent = (category.level - 1) * 35 %}
                <div class="row" style="margin-left: -{{ indent }}px; padding-left: {{ indent }}px;">
                    {%- include "_elements/element" with { element: category, context: 'field' } -%}
                </div>

                {% ifchildren %}
                    <ul>
                        {% children %}
                    </ul>
                {% endifchildren %}
            </li>
        {% endnav %}
    </ul>

    <div class="btn add icon dashed">{{ selectionLabel }}</div>
</div>

{% if jsClass is defined %}
    {% js %}
        new {{ jsClass }}({
            id: "{{ id   | namespaceInputId   | e('js') }}",
            name: "{{ name | namespaceInputName | e('js') }}",
            elementType: "{{ elementType|e('js') }}",
            sources: {{ sources|json_encode|raw }},
            criteria: {{ criteria|json_encode|raw }},
            sourceElementId: {{ sourceElementId ?: 'null' }},
            branchLimit: {{ branchLimit ?: 'null' }},
            modalStorageKey: "{{ storageKey|e('js') }}",
            selectionLabel: "{{ selectionLabel|e('js') }}"
        });
    {% endjs %}
{% endif %}
