{% if name is defined and name %}
    <input type="hidden" name="{{ name }}" value="">
{% endif -%}

{% set elements = (elements is defined ? elements : []) -%}
{% set jsClass = (jsClass is defined and jsClass ? jsClass : 'Craft.BaseElementSelectInput') -%}
{% set sources = (sources is defined and sources ? sources : null) -%}
{% set criteria = (criteria is defined and criteria ? criteria : null) -%}
{% set storageKey = (storageKey is defined and storageKey ? storageKey : null) -%}

<div id="{{ id }}" class="elementselect">
    <div class="elements">
        {% for element in elements %}
            {% include "_elements/element" with {
                context: 'field',
                size: (viewMode == 'large' ? 'large' : 'small')
            } %}
        {% endfor %}
    </div>

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

{% do view.registerAssetBundle("craft\\web\\assets\\prismjs\\PrismJsAsset") %}

{% set jsSettings = {
    id: id|namespaceInputId,
    name: name|namespaceInputName,
    elementType: elementType,
    sources: sources,
    criteria: criteria,
    sourceElementId: sourceElementId,
    viewMode: viewMode,
    limit: limit,
    modalStorageKey: storageKey,
    fieldId: fieldId,
    defaultFieldLayoutId: defaultFieldLayoutId,
    modalSettings: {hideSidebar: hideSidebar}
} %}

{% js %}
    new {{ jsClass }}({{ jsSettings|json_encode|raw }});
{% endjs %}
