{% 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="d-flex flex-column flex-md-row justify-content-between align-items-start align-items-md-center mb-4 gap-3">
        <div>
            <h4 class="mb-1 fw-bold text-dark"><i class="fas fa-tags me-2 text-primary"></i>Expense Categories</h4>
            <div class="text-muted small">Manage classification categories for operating expenses</div>
        </div>
        <div class="d-flex gap-2">
            <a href="{% url 'analytics:expense_list' %}" class="btn btn-outline-secondary rounded-pill px-3 fw-medium bg-white shadow-sm">
                <i class="fas fa-arrow-left me-1"></i> Back to Expenses
            </a>
            <a href="{% url 'analytics:expense_category_create' %}" class="btn btn-primary rounded-pill px-4 shadow-sm fw-medium d-flex align-items-center gap-2">
                <i class="fas fa-plus"></i> Add Category
            </a>
        </div>
    </div>

    <div class="card border-0 shadow-sm" style="border-radius: 16px;">
        <div class="card-body p-0">
            <div class="table-responsive">
                <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 %}
