{% extends "core/base.html" %}
{% load static %}

{% block title %}Expense Categories - SwiftPOS{% endblock %}
{% block topbar_title %}Expense Categories{% endblock %}

{% block content %}
<div class="container-fluid px-0">

    <div class="sp-page-header">
        <div>
            <h1 class="sp-page-title"><i class="fas fa-tags"></i>Expense Categories</h1>
            <p class="sp-page-subtitle">Manage classification categories for operating expenses.</p>
        </div>
        <div class="sp-page-actions">
            <a href="{% url 'analytics:expense_list' %}" class="btn btn-outline-secondary btn-sm d-flex align-items-center gap-2">
                <i class="fas fa-arrow-left"></i> Back to Expenses
            </a>
            <a href="{% url 'analytics:expense_category_create' %}" class="btn btn-primary btn-sm d-flex align-items-center gap-2">
                <i class="fas fa-plus"></i> Add Category
            </a>
        </div>
    </div>

    <div class="card">
        <div class="card-body p-0">
            <div class="sp-table-container">
                <table class="table table-hover align-middle mb-0">
                    <thead class="table-light text-muted small">
                        <tr>
                            <th class="ps-4">Category Name</th>
                            <th>Description</th>
                            <th>Expenses Logged</th>
                            <th class="text-end pe-4">Created On</th>
                        </tr>
                    </thead>
                    <tbody>
                    {% for cat in categories %}
                        <tr>
                            <td class="ps-4 fw-bold text-dark">{{ cat.name }}</td>
                            <td class="text-muted small">{{ cat.description|default:"-" }}</td>
                            <td>
                                <span class="badge bg-light text-dark rounded-pill px-3 border">
                                    {{ cat.expense_count }} expenses
                                </span>
                            </td>
                            <td class="text-end pe-4 text-muted small">{{ cat.created_at|date:"M j, Y" }}</td>
                        </tr>
                    {% empty %}
                        <tr>
                            <td colspan="4" class="text-center py-5">
                                <div class="bg-light rounded-circle d-inline-flex align-items-center justify-content-center mb-3" style="width: 64px; height: 64px;">
                                    <i class="fas fa-tags fa-2x text-muted opacity-50"></i>
                                </div>
                                <h6 class="fw-bold text-dark mb-1">No Categories Found</h6>
                                <p class="small text-muted mb-3">Create business expense categories (e.g., Rent, Salaries) to start classification.</p>
                                <a href="{% url 'analytics:expense_category_create' %}" class="btn btn-primary btn-sm rounded-pill px-4 shadow-sm">Add Category</a>
                            </td>
                        </tr>
                    {% endfor %}
                    </tbody>
                </table>
            </div>
        </div>
    </div>

</div>
{% endblock %}
