{% extends 'base.html' %}

{% block title %}Inventory - Products{% endblock %}

{% block content %}
<div class="d-flex justify-content-between align-items-center mb-4">
    <h1 class="h3 mb-0">
        <i class="bi bi-box-seam me-2"></i>
        Inventory - Products
    </h1>
    <a href="#" class="btn btn-primary">
        <i class="bi bi-plus-circle me-2"></i>
        New Product
    </a>
</div>

<div class="card">
    <div class="card-body">
        {% if products %}
            <div class="table-responsive">
                <table class="table table-hover">
                    <thead class="table-light">
                        <tr>
                            <th>Code</th>
                            <th>Name</th>
                            <th>Category</th>
                            <th>Current Stock</th>
                            <th>Min Stock</th>
                            <th>Cost Price</th>
                            <th>Selling Price</th>
                            <th>Status</th>
                            <th>Actions</th>
                        </tr>
                    </thead>
                    <tbody>
                        {% for product in products %}
                        <tr>
                            <td>
                                <strong>{{ product.code }}</strong>
                            </td>
                            <td>{{ product.name }}</td>
                            <td>{{ product.category.name|default:"N/A" }}</td>
                            <td>
                                <span class="badge bg-{% if product.current_stock <= product.min_stock_level %}danger{% elif product.current_stock <= product.min_stock_level|add:10 %}warning{% else %}success{% endif %}">
                                    {{ product.current_stock }} {{ product.unit }}
                                </span>
                            </td>
                            <td>{{ product.min_stock_level }} {{ product.unit }}</td>
                            <td>Rp {{ product.cost_price|floatformat:0 }}</td>
                            <td>Rp {{ product.selling_price|floatformat:0 }}</td>
                            <td>
                                <span class="badge bg-{% if product.is_active %}success{% else %}secondary{% endif %}">
                                    {{ product.is_active|yesno:"Active,Inactive" }}
                                </span>
                            </td>
                            <td>
                                <a href="{% url 'inventory:product_detail' product.pk %}" class="btn btn-sm btn-outline-primary">
                                    <i class="bi bi-eye"></i>
                                </a>
                            </td>
                        </tr>
                        {% endfor %}
                    </tbody>
                </table>
            </div>
            
            {% if is_paginated %}
            <nav aria-label="Page navigation" class="mt-4">
                <ul class="pagination justify-content-center">
                    {% if page_obj.has_previous %}
                        <li class="page-item">
                            <a class="page-link" href="?page={{ page_obj.previous_page_number }}">Previous</a>
                        </li>
                    {% endif %}
                    
                    <li class="page-item active">
                        <span class="page-link">Page {{ page_obj.number }} of {{ page_obj.paginator.num_pages }}</span>
                    </li>
                    
                    {% if page_obj.has_next %}
                        <li class="page-item">
                            <a class="page-link" href="?page={{ page_obj.next_page_number }}">Next</a>
                        </li>
                    {% endif %}
                </ul>
            </nav>
            {% endif %}
        {% else %}
            <div class="text-center py-5">
                <i class="bi bi-box-seam display-1 text-muted"></i>
                <h4 class="mt-3 text-muted">No Products Found</h4>
                <p class="text-muted">Start by adding your first product to inventory.</p>
                <a href="#" class="btn btn-primary">
                    <i class="bi bi-plus-circle me-2"></i>
                    Add Product
                </a>
            </div>
        {% endif %}
    </div>
</div>
{% endblock %}
