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

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

{% block topbar_title %}
Inventory - Categories
{% endblock %}

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

    <!-- Toast Messages -->
    <div class="swiftpos-toast-container">
        {% if messages %}
            {% for message in messages %}
                <div class="swiftpos-toast swiftpos-toast-{{ message.tags }}">
                    <div class="toast-icon">
                        {% if message.tags == 'success' %}
                            <i class="fas fa-check-circle"></i>
                        {% elif message.tags == 'error' or message.tags == 'danger' %}
                            <i class="fas fa-exclamation-circle"></i>
                        {% elif message.tags == 'warning' %}
                            <i class="fas fa-exclamation-triangle"></i>
                        {% else %}
                            <i class="fas fa-info-circle"></i>
                        {% endif %}
                    </div>
                    <div class="toast-text">
                        {{ message }}
                    </div>
                </div>
            {% endfor %}
        {% endif %}
    </div>

    <div class="sp-page-header">
        <div>
            <h1 class="sp-page-title"><i class="fas fa-layer-group"></i>Categories</h1>
            <p class="sp-page-subtitle">{{ categories|length }} category{{ categories|length|pluralize }} — organise your product catalogue.</p>
        </div>
        <div class="sp-page-actions">
            <a href="{% url 'inventory:product_list' %}"
               class="btn btn-outline-secondary btn-sm d-flex align-items-center gap-2">
                <i class="fas fa-box"></i> Products
            </a>
            <a href="{% url 'inventory:add_category' %}"
               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 align-middle mb-0 table-hover">
                    <thead>
                    <tr>
                        <th>Name</th>
                        <!-- <th>Description</th> -->
                        <th>Products</th>
                        <th>Actions</th>
                    </tr>
                    </thead>
                    <tbody>
                    {% if categories %}
                        {% for category in categories %}
                            <tr>
                                <td>
                                    <span class="fw-semibold">{{ category.name }}</span>
                                </td>
                               <!--  <td class="d-none d-md-table-cell">
                                    <span class="small text-muted">
                                        {{ category.description|default:"-" }}
                                    </span>
                                </td> -->
                                <td class="text-center">
                                    <span class="badge bg-light text-muted border">
                                        {{ category.product_count|default:category.products.count }} items
                                    </span>
                                </td>
                                <td class="text-end">
                                    <div class="btn-group btn-group-sm">
                                        <a href="{% url 'inventory:product_list' %}?category={{ category.id }}"
                                           class="btn btn-outline-secondary"
                                           title="View products">
                                            <i class="fas fa-eye"></i>
                                        </a>
                                        <a href="#"
                                           class="btn btn-outline-secondary"
                                           title="Edit category">
                                            <i class="fas fa-pen"></i>
                                        </a>
                                    </div>
                                </td>
                            </tr>
                        {% endfor %}
                    {% else %}
                        <tr>
                            <td colspan="4" class="text-center text-muted small py-4">
                                No categories created yet.
                            </td>
                        </tr>
                    {% endif %}
                    </tbody>
                </table>
            </div>
        </div>
    </div>
</div>
{% endblock %}