{% extends "management/base.html" %}
{% load i18n lucide ui %}

{% block heading %}{% trans "Positions" %}{% endblock heading %}

{% block actions %}
    {% if is_club_admin %}
        <a class="btn btn-primary gap-2" href="{% url 'management:position_create' %}">{% lucide "plus" size=16 %} {% trans "New position" %}</a>
    {% endif %}
{% endblock actions %}

{% block panel %}
    <div class="card overflow-hidden">
        <table class="table">
            <thead>
                <tr>
                    <th>{% trans "Ordering" %}</th>
                    <th>{% trans "Name" %}</th>
                    <th>{% trans "Short name" %}</th>
                    <th>{% trans "Staff position" %}</th>
                    <th>{% trans "Management position" %}</th>
                    <th></th>
                </tr>
            </thead>
            <tbody>
                {% for position in positions %}
                    <tr>
                        <td class="font-mono text-muted">{{ position.ordering }}</td>
                        <td class="font-semibold text-ink">{{ position.name }}</td>
                        <td class="font-mono text-muted">{{ position.short_name }}</td>
                        <td>
                            <span class="badge badge-sm {% if position.staff_position %}badge-success{% else %}badge-ghost{% endif %}">
                                {% if position.staff_position %}{% trans "Yes" %}{% else %}{% trans "No" %}{% endif %}
                            </span>
                        </td>
                        <td>
                            <span class="badge badge-sm {% if position.management_position %}badge-success{% else %}badge-ghost{% endif %}">
                                {% if position.management_position %}{% trans "Yes" %}{% else %}{% trans "No" %}{% endif %}
                            </span>
                        </td>
                        <td class="text-right">
                            {% if is_club_admin %}
                                <div class="flex justify-end gap-1">
                                    <a class="btn btn-outline btn-sm gap-2" href="{% url 'management:position_update' position.pk %}">{% lucide "pencil" size=14 %} {% trans "Edit" %}</a>
                                    <button class="btn btn-sm btn-outline btn-error" type="button" onclick="document.getElementById('{{ position.pk|dom_id:"position_delete_modal" }}').showModal()" aria-label="{% trans 'Delete' %}">{% lucide "trash-2" size=14 %}</button>
                                </div>
                            {% endif %}
                        </td>
                    </tr>
                {% empty %}
                    <tr>
                        <td colspan="6" class="text-center text-muted">{% trans "No positions yet." %}</td>
                    </tr>
                {% endfor %}
            </tbody>
        </table>
    </div>

    {% if is_club_admin %}
        {% trans "Delete position" as delete_position_title %}
        {% trans "Delete" as delete_label %}
        {% for position in positions %}
            {% url 'management:position_delete' position.pk as position_delete_url %}
            {% blocktrans with name=position.name asvar delete_position_body %}Delete “{{ name }}”? Positions still assigned on a team roster can't be deleted. This cannot be undone.{% endblocktrans %}
            {% include "controlpanel/_confirm_modal.html" with modal_id=position.pk|dom_id:"position_delete_modal" title=delete_position_title body=delete_position_body action_url=position_delete_url submit_label=delete_label %}
        {% endfor %}
    {% endif %}
{% endblock panel %}
