{% extends "aa_bb/base.html" %}
{% load i18n %}

{% block details %}
<div class="card">
    <div class="card-header">
        <h3 class="card-title">{% translate "Compliance Tickets" %}</h3>
    </div>
    <div class="card-body">
        <!-- Tab Navigation -->
        <ul class="nav nav-tabs mb-3">
            <li class="nav-item">
                <a class="nav-link {% if current_tab == 'open' %}active{% endif %}" href="{% url 'aa_bb:ticket_list' %}?tab=open">
                    {% translate "Open" %}
                </a>
            </li>
            <li class="nav-item">
                <a class="nav-link {% if current_tab == 'exceptions' %}active{% endif %}" href="{% url 'aa_bb:ticket_list' %}?tab=exceptions">
                    {% translate "Exceptions" %}
                </a>
            </li>
            <li class="nav-item">
                <a class="nav-link {% if current_tab == 'resolved' %}active{% endif %}" href="{% url 'aa_bb:ticket_list' %}?tab=resolved">
                    {% translate "Resolved" %}
                </a>
            </li>
            <li class="nav-item">
                <a class="nav-link {% if current_tab == 'all' %}active{% endif %}" href="{% url 'aa_bb:ticket_list' %}?tab=all">
                    {% translate "All" %}
                </a>
            </li>
        </ul>
        <div class="table-responsive">
            <table class="table table-striped table-hover">
                <thead>
                    <tr>
                        <th>{% translate "Ticket ID" %}</th>
                        <th>{% translate "User" %}</th>
                        <th>{% translate "Reason" %}</th>
                        <th>{% translate "Status" %}</th>
                        <th>{% translate "Created At" %}</th>
                        <th>{% translate "Actions" %}</th>
                    </tr>
                </thead>
                <tbody>
                    {% for ticket in tickets %}
                    <tr>
                        <td>{{ ticket.ticket_id }}</td>
                        <td>
                            {% if ticket.user %}
                                {{ ticket.user.profile.main_character.character_name|default:ticket.user.username }}
                            {% else %}
                                {% translate "Unknown User" %}
                            {% endif %}
                        </td>
                        <td>{{ ticket.get_reason_display }}</td>
                        <td>
                            {% if ticket.is_exception %}
                                <span class="badge bg-info">{% translate "Exception" %}</span>
                            {% elif ticket.is_resolved %}
                                <span class="badge bg-success">{% translate "Resolved" %}</span>
                            {% else %}
                                <span class="badge bg-warning text-dark">{% translate "Open" %}</span>
                            {% endif %}
                        </td>
                        <td>{{ ticket.created_at|date:"Y-m-d H:i" }}</td>
                        <td>
                            <a href="{% url 'aa_bb:ticket_view' ticket.pk %}" class="btn btn-primary btn-sm">
                                {% translate "View" %}
                                <span class="badge bg-info">{{ ticket.comment_count }}</span>
                            </a>
                        </td>
                    </tr>
                    {% empty %}
                    <tr>
                        <td colspan="6" class="text-center">{% translate "No tickets found." %}</td>
                    </tr>
                    {% endfor %}
                </tbody>
            </table>
        </div>
    </div>
</div>
{% endblock %}
