{% extends "freeform/_layouts/settings" %}
{% hook "freeform.prepareCpTemplate" %}

{% set selectedSubnavItem = "statuses" %}

{% block actionButton %}

    {% if currentUser.can("freeform-settingsAccess") %}
        <div class="buttons">
            <a class="btn submit add icon" href="{{ url('freeform/settings/statuses/new/') }}">
                {{ "New Status"|t('freeform') }}
            </a>
        </div>
    {% endif %}

{% endblock %}

{% set title = "Statuses"|t('freeform') %}

{% set content %}

    {% if statuses|length %}
        <table id="statuses" class="data fullwidth collapsible">
            <thead>
            <th scope="col">{{ "Name"|t('freeform') }}</th>
            <th scope="col">{{ "Handle"|t('freeform') }}</th>
            <th scope="col">{{ "Is Default"|t('freeform') }}</th>
            <th class="thin"></th>
            <th class="thin"></th>
            </thead>
            <tbody>
            {% for status in statuses %}
                <tr data-id="{{ status.id }}" data-name="{{ status.name|t('freeform') }}">
                    <th scope="row" data-title="{{ 'Name'|t('freeform') }}">
                        <span class="color-indicator" style="background: {{ status.colorHex }};"></span>
                        {% if currentUser.can("freeform-settingsAccess") %}
                            <a href="{{ url('freeform/settings/statuses/' ~ status.id) }}">
                                {{ status.name }}
                            </a>
                        {% else %}
                            {{ status.name }}
                        {% endif %}
                    </th>
                    <td data-title="{{ 'Handle'|t('freeform') }}">
                        <code>
                            {{ status.handle }}
                        </code>
                    </td>
                    <td>{% if status.isDefault %}<span data-icon="check"></span>{% endif %}</td>
                    <td class="thin"><a class="move icon" title="{{ 'Reorder'|t('freeform') }}" role="button"></a></td>
                    <td class="thin">
                        {% if currentUser.can("freeform-settingsAccess") and not status.isDefault %}
                            <a class="delete icon" title="{{ 'Delete'|t('freeform') }}" role="button"></a>
                        {% endif %}
                    </td>
                </tr>
            {% endfor %}
            </tbody>
        </table>
    {% else %}
        <div class="zilch">
            {{ "No statuses exist yet."|t('freeform') }}
        </div>
    {% endif %}
{% endset %}

{% css %}
    #content { padding: 0; }
{% endcss %}

{% js %}
    var adminTable = new Craft.AdminTable({
        tableSelector: '#statuses',
        noObjectsSelector: '#nostatuses',
        newObjectBtnSelector: '#newstatuscontainer',
        deleteAction: 'freeform/statuses/delete',
        confirmDeleteMessage: '{{ "Are you sure you want to delete this status?"|t('freeform') }}',
        sortable: true,
        reorderAction: 'freeform/statuses/reorder',
        reorderSuccessMessage: '{{ "Success"|t('freeform') }}',
        reorderFailMessage:    '{{ "Failed"|t('freeform') }}',
    });
{% endjs %}
