{% load i18n wagtailadmin_tags %}

{% if not page_perms %}
    {% page_permissions page as page_perms %}
{% endif %}

{% if page.locked and page_perms.can_unlock %}
    {% url 'wagtailadmin_pages:unlock' page.id as form_action %}
{% elif not page.locked and page_perms.can_lock %}
    {% url 'wagtailadmin_pages:lock' page.id as form_action %}
{% endif %}

<form action="{{ form_action }}" method="POST" class="lock-indicator {{ page.locked|yesno:'locked,unlocked' }}">
    <span class="lock-status">
    {% if page.locked %}
        {% trans "This page is locked" %}
    {% else %}
        {% trans "This page is unlocked" %}
    {% endif %}</span>

    {% csrf_token %}
    {% if page.locked %}
        {% if page_perms.can_unlock %}
        <input type="hidden" name="next" value="{% url 'wagtailadmin_pages:edit' page.id %}" />
        <button
            type="submit"
            class="status-tag primary lock-status"
            aria-label="{% trans 'Remove editor lock' %}">
            {% trans "Unlock" %}
        </button>
        {% else %}
            <div class="lock-status">
            ({% trans "You don't have permission to unlock" %})
                </div>
        {% endif %}
    {% else %}
        {% if page_perms.can_lock %}
            <input type="hidden" name="next" value="{% url 'wagtailadmin_pages:edit' page.id %}" />
        <button
            type="submit"
            class="status-tag primary lock-status"
            aria-label="{% trans 'Apply editor lock' %}">
            {% trans "Lock" %}
        </button>
        {% else %}
            <div class="lock-status">
            ({% trans "You don't have permission to lock" %})
                </div>
        {% endif %}
    {% endif %}


</form>
