{# templates/inventory/add_category.html #}
{% extends 'core/base.html' %}
{% load static %}

{% block title %}Add Category - SwiftPOS{% endblock %}

{% block topbar_title %}
Add Category
{% 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>

    {# Non-field form errors #}
    {% if form.non_field_errors %}
        <div class="alert alert-danger mb-3">
            {{ form.non_field_errors }}
        </div>
    {% endif %}

    <div class="d-flex flex-wrap justify-content-between align-items-center mb-3 gap-2">
        <div>
            <h5 class="mb-0">Add New Category</h5>
            <div class="text-muted small">
                Organise products into groups like "Snacks", "Drinks", or "Clothes".
            </div>
        </div>
        <a href="{% url 'inventory:category_list' %}"
           class="btn btn-outline-secondary btn-sm d-flex align-items-center gap-2">
            <i class="fas fa-list"></i> Categories
        </a>
    </div>

    <div class="card">
        <div class="card-body">
            <form method="post"
    
      novalidate>
    {% csrf_token %}
    

                <div class="row g-3">
                    {# Render every field from ProductCategoryForm #}
                    {% for field in form %}
                        <div class="col-md-6">
                            <label for="{{ field.id_for_label }}"
                                   class="form-label small fw-semibold">
                                {{ field.label }}
                                {% if field.field.required %}
                                    <span class="text-danger">*</span>
                                {% endif %}
                            </label>
                            {{ field }}
                            {% if field.help_text %}
                                <div class="form-text small text-muted">
                                    {{ field.help_text }}
                                </div>
                            {% endif %}
                            {% for error in field.errors %}
                                <div class="text-danger small">
                                    {{ error }}
                                </div>
                            {% endfor %}
                        </div>
                    {% endfor %}
                </div>

                <div class="mt-4 d-flex justify-content-end gap-2">
                    <a href="{% url 'inventory:category_list' %}"
                       class="btn btn-outline-secondary btn-sm">
                        Cancel
                    </a>
                    <button type="submit"
                            class="btn btn-primary btn-sm d-flex align-items-center gap-2">
                        <i class="fas fa-save"></i> Save category
                    </button>
                </div>
            </form>
        </div>
    </div>
</div>
{% endblock %}