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

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

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

{% block panel %}
    <div class="card overflow-hidden">
        <table class="table">
            <thead>
                <tr>
                    <th>{% trans "Name" %}</th>
                    <th>{% trans "Short name" %}</th>
                    <th>{% trans "Players" %}</th>
                    <th>{% trans "Staff" %}</th>
                    <th></th>
                </tr>
            </thead>
            <tbody>
                {% for team in teams %}
                    <tr>
                        <td><a class="link link-hover font-semibold" href="{% url 'management:team_detail' team.pk %}">{{ team.name }}</a></td>
                        <td class="font-mono text-muted">{{ team.short_name }}</td>
                        <td class="font-mono tabular-nums">{{ team.player_count }}</td>
                        <td class="font-mono tabular-nums">{{ team.staff_count }}</td>
                        <td class="text-right">
                            {% if is_club_admin %}
                                <div class="flex justify-end gap-1">
                                    <a class="btn btn-outline btn-sm" href="{% url 'management:team_detail' team.pk %}" aria-label="{% trans 'Edit' %}">{% lucide "pencil" size=14 %} {% trans "Edit" %}</a>
                                    <button class="btn btn-outline btn-error btn-sm" type="button" onclick="document.getElementById('{{ team.pk|dom_id:"team_delete_modal" }}').showModal()" aria-label="{% trans 'Delete' %}">{% lucide "trash-2" size=14 %} {% trans "Delete" %}</button>
                                </div>
                            {% endif %}
                        </td>
                    </tr>
                {% empty %}
                    <tr>
                        <td colspan="5" class="text-center text-muted">{% trans "No teams yet." %}</td>
                    </tr>
                {% endfor %}
            </tbody>
        </table>
    </div>

    {% include "management/_pagination.html" %}

    {% if is_club_admin %}
        {% trans "Delete team" as delete_team_title %}
        {% trans "Delete" as delete_label %}
        {% for team in teams %}
            {% url 'management:team_delete' team.pk as team_delete_url %}
            {% blocktrans with name=team.name asvar delete_team_body %}Delete “{{ name }}”? This also removes its roster and staff assignments. This cannot be undone.{% endblocktrans %}
            {% include "controlpanel/_confirm_modal.html" with modal_id=team.pk|dom_id:"team_delete_modal" title=delete_team_title body=delete_team_body action_url=team_delete_url submit_label=delete_label %}
        {% endfor %}
    {% endif %}
{% endblock panel %}
