{% extends "_layouts/cp" %}

{% set elementInstance = craft.app.elements.createElement(elementType) %}
{% set context = 'index' %}

{% if not elementInstance %}
    {% exit 404 %}
{% endif %}

{% set sources = craft.app.elementIndexes.getSources(elementType, 'index') %}
{% set customizableSources = (sources is not empty and context == 'index' and currentUser.admin) %}

{% set showSiteMenu = (craft.app.getIsMultiSite() ? (showSiteMenu ?? 'auto') : false) %}
{% if showSiteMenu == 'auto' %}
    {% set showSiteMenu = elementInstance.isLocalized() %}
{% endif %}


{% block contextMenu %}
    {% if showSiteMenu %}
        {% include "_elements/sitemenu" %}
    {% endif %}
{% endblock %}


{% block sidebar %}
    {% if sources is not empty %}
        <nav>
            {% include "_elements/sources" %}
        </nav>

        {% if customizableSources %}
            <div class="heading"><span></span></div>
            <a class="customize-sources settings icon" title="{{ 'Customize sources'|t }}"></a>
        {% endif %}
    {% endif %}
{% endblock %}


{% block content %}
    <div class="elementindex">
        {% include "_elements/indexcontainer" with {
            showSiteMenu: false
        } %}
    </div>
{% endblock %}


{% block initJs %}
    Craft.elementIndex = Craft.createElementIndex('{{ elementType|e("js") }}', $('#main'), {
        context:        '{{ context }}',
        storageKey:     'elementindex.{{ elementType|e("js") }}',
        criteria:       Craft.defaultIndexCriteria
    });
{% endblock %}

{% js block('initJs') %}
