{% extends "base.html" %}
{% block title %}Dashboard - Support Center{% endblock %}

{% block content %}
<div class="row mb-5">
    <div class="col-md-8">
        <h2 class="mb-1">Support Dashboard</h2>
        <p class="text-muted">Manage and track your support requests</p>
    </div>
</div>

<div class="row g-4 mb-5">
    <div class="col-md-4">
        <div class="card p-4 text-center">
            <h3 class="h1 mb-0">{{ open_count }}</h3>
            <span class="text-muted text-uppercase small fw-bold">Open Tickets</span>
        </div>
    </div>
    <div class="col-md-4">
        <div class="card p-4 text-center">
            <h3 class="h1 mb-0">{{ pending_count }}</h3>
            <span class="text-muted text-uppercase small fw-bold">Pending</span>
        </div>
    </div>
    <div class="col-md-4">
        <div class="card p-4 text-center">
            <h3 class="h1 mb-0">{{ resolved_count }}</h3>
            <span class="text-muted text-uppercase small fw-bold">Resolved</span>
        </div>
    </div>
</div>

<div class="card shadow-sm border-0">
    <div class="card-body p-0">
        <div class="table-responsive">
            <table class="table table-hover align-middle mb-0">
                <thead class="bg-light">
                    <tr>
                        <th class="ps-4 py-3 text-muted fw-normal">Ticket</th>
                        <th class="py-3 text-muted fw-normal text-center">Status</th>
                        <th class="py-3 text-muted fw-normal">Priority</th>
                        <th class="py-3 text-muted fw-normal">Updated</th>
                        <th class="pe-4 py-3 text-end fw-normal">Action</th>
                    </tr>
                </thead>
                <tbody>
                    {% for ticket in tickets %}
                    <tr class="card-ticket">
                        <td class="ps-4 py-4">
                            <div class="fw-semibold text-dark">{{ ticket.title }}</div>
                            <div class="text-muted small">#{{ ticket.id }} &bull; {{ ticket.get_category_display }}</div>
                        </td>
                        <td class="text-center">
                            <span class="status-badge status-{{ ticket.status }}">
                                {{ ticket.get_status_display }}
                            </span>
                        </td>
                        <td>
                            <span class="priority-{{ ticket.priority }}">
                                {{ ticket.get_priority_display }}
                            </span>
                        </td>
                        <td class="text-muted small">
                            {{ ticket.updated_at|timesince }} ago
                        </td>
                        <td class="pe-4 text-end">
                            <a href="{% url 'ticket_detail' ticket.id %}" class="btn btn-light btn-sm px-3">View</a>
                        </td>
                    </tr>
                    {% empty %}
                    <tr>
                        <td colspan="5" class="text-center py-5 text-muted">
                            <div class="mb-3"><i class="bi bi-ticket-detailed h1"></i></div>
                            <p>No tickets found. Need help? Create a new ticket!</p>
                            <a href="{% url 'ticket_create' %}" class="btn btn-primary btn-sm">Create First Ticket</a>
                        </td>
                    </tr>
                    {% endfor %}
                </tbody>
            </table>
        </div>
    </div>
</div>
{% endblock %}
