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

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

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

{% block panel %}
    <div class="card bg-base-100 shadow">
        <div class="card-body">
            <div class="overflow-x-auto">
                <table class="table">
                    <thead>
                        <tr>
                            <th></th>
                            <th>{% trans "Name" %}</th>
                            <th>{% trans "URL" %}</th>
                            <th>{% trans "Start date" %}</th>
                            <th>{% trans "End date" %}</th>
                            <th></th>
                        </tr>
                    </thead>
                    <tbody>
                        {% for sponsor in sponsors %}
                            <tr>
                                <td>
                                    {% if sponsor.logo %}
                                        <img src="{{ sponsor.logo.url }}" alt="" class="size-8 rounded object-contain">
                                    {% endif %}
                                </td>
                                <td>{{ sponsor.name }}</td>
                                <td>
                                    {% if sponsor.url %}
                                        <a class="link link-hover" href="{{ sponsor.url }}" target="_blank" rel="noopener noreferrer">{{ sponsor.url }}</a>
                                    {% else %}
                                        <span class="opacity-50">&mdash;</span>
                                    {% endif %}
                                </td>
                                <td>{{ sponsor.start_date|date:"Y-m-d" }}</td>
                                <td>{{ sponsor.end_date|date:"Y-m-d"|default:"—" }}</td>
                                <td class="text-right">
                                    <div class="flex justify-end gap-1">
                                        <a class="btn btn-outline btn-sm" href="{% url 'management:sponsor_update' sponsor.pk %}" aria-label="{% trans 'Edit' %}">{% lucide "pencil" size=14 %} {% trans "Edit" %}</a>
                                        <button class="btn btn-sm btn-outline btn-error" type="button" onclick="document.getElementById('{{ sponsor.pk|dom_id:"sponsor_delete_modal" }}').showModal()" aria-label="{% trans 'Delete' %}">{% lucide "trash-2" size=14 %} {% trans "Delete" %}</button>
                                    </div>
                                </td>
                            </tr>
                        {% empty %}
                            <tr>
                                <td colspan="6" class="text-center opacity-60">{% trans "No sponsors yet." %}</td>
                            </tr>
                        {% endfor %}
                    </tbody>
                </table>
            </div>
        </div>
    </div>

    {% trans "Delete sponsor" as delete_sponsor_title %}
    {% trans "Delete" as delete_label %}
    {% for sponsor in sponsors %}
        {% url 'management:sponsor_delete' sponsor.pk as sponsor_delete_url %}
        {% blocktrans with name=sponsor.name asvar delete_sponsor_body %}Delete “{{ name }}”? This cannot be undone.{% endblocktrans %}
        {% include "controlpanel/_confirm_modal.html" with modal_id=sponsor.pk|dom_id:"sponsor_delete_modal" title=delete_sponsor_title body=delete_sponsor_body action_url=sponsor_delete_url submit_label=delete_label %}
    {% endfor %}
{% endblock panel %}
