{% extends "_layouts/cp" %}

{% set entryTypes = section.getEntryTypes() %}
{% set multiple  = (entryTypes|length > 1) %}

{% block actionButton %}
    {% if section.type != 'single' %}
        <a href="{{ url('settings/sections/' ~ section.id ~ '/entrytypes/new') }}" class="btn submit add icon">{{ "New entry type"|t('app') }}</a>
    {% endif %}
{% endblock %}

{% block content %}
    <table id="entrytypes" class="data fullwidth collapsible">
        <thead>
            <th scope="col">{{ "Name"|t('app') }}</th>
            <th scope="col">{{ "Handle"|t('app') }}</th>
            {% if multiple %}
                <td class="thin"></td>
                <td class="thin"></td>
            {% endif %}
        </thead>
        <tbody>
            {% for entryType in entryTypes %}
                <tr data-id="{{ entryType.id }}" data-uid="{{ entryType.uid }}" data-name="{{ entryType.name|t('site') }}">
                    <th scope="row" data-title="{{ 'Name'|t('app') }}"><a href="{{ url('settings/sections/' ~ section.id ~ '/entrytypes/' ~ entryType.id) }}">{{ entryType.name|t('site') }}</a></th>
                    <td data-title="{{ 'Handle'|t('app') }}"><code>{{ entryType.handle }}</code></td>
                    {% if multiple %}
                        <td class="thin"><a class="move icon" title="{{ 'Reorder'|t('app') }}" role="button"></a></td>
                        <td class="thin"><a class="delete icon" title="{{ 'Delete'|t('app') }}" role="button"></a></td>
                    {% endif %}
                </tr>
            {% endfor %}
        </tbody>
    </table>
{% endblock %}


{% if section.type != 'single' %}
    {% js %}
        new Craft.AdminTable({
            tableSelector: '#entrytypes',
            deleteAction: 'sections/delete-entry-type',
            minItems: 1,
            sortable: true,
            reorderAction: 'sections/reorder-entry-types',
            confirmDeleteMessage: '{{ "Are you sure you want to delete “{name}” and all entries that use it?"|t('app') }}',
        });
    {% endjs %}
{% endif %}
